Skip to content

Commit 77b64b0

Browse files
sh-shamsanMohammed Alhazmi
authored andcommitted
Added data sanitization to queryId and nodeId, along with encodeURIComponent to queryId & nodeId.
Co-authored-by: Mohammed Alhazmi <alhazmi@ibm.com>
1 parent bc90e93 commit 77b64b0

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

presto-ui/src/components/QueryDetail.jsx

+12-2
Original file line numberDiff line numberDiff line change
@@ -912,10 +912,20 @@ export class QueryDetail extends React.Component {
912912
}
913913
}
914914

915+
static getQueryURL(id) {
916+
if (!id || typeof id !== 'string' || id.length === 0) {
917+
return "/v1/query/undefined";
918+
}
919+
const sanitizedId = id.replace(/[^a-z0-9_]/gi, '');
920+
return sanitizedId.length > 0 ? `/v1/query/${encodeURIComponent(sanitizedId)}` : "/v1/query/undefined";
921+
}
922+
923+
915924
refreshLoop() {
916925
clearTimeout(this.timeoutId); // to stop multiple series of refreshLoop from going on simultaneously
917-
const queryId = getFirstParameter(window.location.search);
918-
$.get('/v1/query/' + queryId, function (query) {
926+
const queryId = getFirstParameter(window.location.search);
927+
928+
$.get(QueryDetail.getQueryURL(queryId), function (query) {
919929
let lastSnapshotStages = this.state.lastSnapshotStage;
920930
if (this.state.stageRefresh) {
921931
lastSnapshotStages = query.outputStage;

presto-ui/src/components/StageDetail.jsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -506,12 +506,18 @@ export class StageDetail extends React.Component {
506506
this.timeoutId = setTimeout(this.refreshLoop, 1000);
507507
}
508508
}
509+
static getQueryURL(id) {
510+
if (!id || typeof id !== 'string' || id.length === 0) {
511+
return "/v1/query/undefined";
512+
}
513+
const sanitizedId = id.replace(/[^a-z0-9_]/gi, '');
514+
return sanitizedId.length > 0 ? `/v1/query/${encodeURIComponent(sanitizedId)}` : "/v1/query/undefined";
515+
}
509516

510517
refreshLoop() {
511518
clearTimeout(this.timeoutId); // to stop multiple series of refreshLoop from going on simultaneously
512519
const queryString = getFirstParameter(window.location.search).split('.');
513-
const queryId = queryString.length > 0 ? queryString[0] : "undefined";
514-
520+
const rawQueryId = queryString.length > 0 ? queryString[0] : "";
515521
let selectedStageId = this.state.selectedStageId;
516522
if (selectedStageId === null) {
517523
selectedStageId = 0;
@@ -520,7 +526,8 @@ export class StageDetail extends React.Component {
520526
}
521527
}
522528

523-
$.get('/v1/query/' + queryId, query => {
529+
530+
$.get(StageDetail.getQueryURL(rawQueryId), query => {
524531
this.setState({
525532
initialized: true,
526533
ended: query.finalQueryInfo,

presto-ui/src/components/WorkerStatus.jsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,18 @@ export class WorkerStatus extends React.Component {
5050
this.timeoutId = setTimeout(this.refreshLoop, 1000);
5151
}
5252
}
53+
static getStatusQuery(id){
54+
// Node ID does not have a common pattern
55+
if (id.length === 0) {
56+
return "/v1/worker/undefined/status";
57+
}
58+
return `/v1/worker/${encodeURIComponent(id)}/status`;
59+
}
5360

5461
refreshLoop() {
5562
clearTimeout(this.timeoutId); // to stop multiple series of refreshLoop from going on simultaneously
56-
const nodeId = getFirstParameter(window.location.search);
57-
$.get('/v1/worker/' + nodeId + '/status', function (serverInfo) {
63+
64+
$.get(WorkerStatus.getStatusQuery(getFirstParameter(window.location.search)), function (serverInfo) {
5865
this.setState({
5966
serverInfo: serverInfo,
6067
initialized: true,

presto-ui/src/components/WorkerThreadList.jsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ export class WorkerThreadList extends React.Component {
4040
selectedThreadState: ALL_THREAD_STATE,
4141
};
4242
}
43-
43+
static getRequestQuery(id){
44+
// Node ID does not have a common pattern
45+
if (id.length === 0) {
46+
return "/v1/worker/undefined/thread";
47+
}
48+
return `/v1/worker/${encodeURIComponent(id)}/thread`;
49+
}
4450
captureSnapshot() {
45-
const nodeId = getFirstParameter(window.location.search);
46-
$.get('/v1/worker/' + nodeId + '/thread', function (threads) {
51+
$.get(WorkerThreadList.getRequestQuery(getFirstParameter(window.location.search)), function (threads) {
4752
this.setState({
4853
threads: WorkerThreadList.processThreads(threads),
4954
snapshotTime: new Date(),

0 commit comments

Comments
 (0)