Skip to content

Commit ec154d5

Browse files
committed
Encode server action URLs and query parameters safely
1 parent 8c67e34 commit ec154d5

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

src/graph-builder/graph-core/6-server.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,16 @@ class GraphServer extends GraphLoadSave {
170170
build() {
171171
const graphName = this.getCurrentGraphName();
172172
if (!graphName) return;
173-
const url = `${EXECUTION_ENGINE_URL}/build/${this.superState.uploadedDirName}`
174-
+ `?fetch=${graphName}&unlock=${this.superState.unlockCheck}`
175-
+ `&docker=${this.superState.dockerCheck}`
176-
+ `&maxtime=${this.superState.maxTime}`
177-
+ `&params=${this.superState.params}`
178-
+ `&octave=${this.superState.octave}`;
173+
const query = new URLSearchParams({
174+
fetch: graphName,
175+
unlock: this.superState.unlockCheck,
176+
docker: this.superState.dockerCheck,
177+
maxtime: this.superState.maxTime,
178+
params: this.superState.params,
179+
octave: this.superState.octave,
180+
});
181+
const url = `${EXECUTION_ENGINE_URL}/build/${encodeURIComponent(this.superState.uploadedDirName)}`
182+
+ `?${query.toString()}`;
179183
this.serverAction('post', url, {
180184
built: false, ran: true, debugged: true, cleared: false, stopped: false, destroyed: true,
181185
}, (res) => {
@@ -186,7 +190,7 @@ class GraphServer extends GraphLoadSave {
186190
debug() {
187191
const graphName = this.getCurrentGraphName();
188192
if (!graphName) return;
189-
const url = `${EXECUTION_ENGINE_URL}/debug/${graphName}`;
193+
const url = `${EXECUTION_ENGINE_URL}/debug/${encodeURIComponent(graphName)}`;
190194
this.serverAction('post', url, {
191195
built: false, ran: false, debugged: false, cleared: true, stopped: true, destroyed: true,
192196
});
@@ -195,7 +199,7 @@ class GraphServer extends GraphLoadSave {
195199
run() {
196200
const graphName = this.getCurrentGraphName();
197201
if (!graphName) return;
198-
const url = `${EXECUTION_ENGINE_URL}/run/${graphName}`;
202+
const url = `${EXECUTION_ENGINE_URL}/run/${encodeURIComponent(graphName)}`;
199203
this.serverAction('post', url, {
200204
built: false, ran: false, debugged: false, cleared: true, stopped: true, destroyed: true,
201205
});
@@ -204,10 +208,13 @@ class GraphServer extends GraphLoadSave {
204208
clear() {
205209
const graphName = this.getCurrentGraphName();
206210
if (!graphName) return;
207-
const url = `${EXECUTION_ENGINE_URL}/clear/${graphName}`
208-
+ `?unlock=${this.superState.unlockCheck}`
209-
+ `&maxtime=${this.superState.maxTime}`
210-
+ `&params=${this.superState.params}`;
211+
const query = new URLSearchParams({
212+
unlock: this.superState.unlockCheck,
213+
maxtime: this.superState.maxTime,
214+
params: this.superState.params,
215+
});
216+
const url = `${EXECUTION_ENGINE_URL}/clear/${encodeURIComponent(graphName)}`
217+
+ `?${query.toString()}`;
211218
this.serverAction('post', url, {
212219
built: false, ran: true, debugged: true, cleared: false, stopped: true, destroyed: true,
213220
});
@@ -216,7 +223,7 @@ class GraphServer extends GraphLoadSave {
216223
stop() {
217224
const graphName = this.getCurrentGraphName();
218225
if (!graphName) return;
219-
const url = `${EXECUTION_ENGINE_URL}/stop/${graphName}`;
226+
const url = `${EXECUTION_ENGINE_URL}/stop/${encodeURIComponent(graphName)}`;
220227
this.serverAction('post', url, {
221228
built: false, ran: false, debugged: false, cleared: true, stopped: false, destroyed: true,
222229
});
@@ -225,15 +232,19 @@ class GraphServer extends GraphLoadSave {
225232
destroy() {
226233
const graphName = this.getCurrentGraphName();
227234
if (!graphName) return;
228-
const url = `${EXECUTION_ENGINE_URL}/destroy/${graphName}`;
235+
const url = `${EXECUTION_ENGINE_URL}/destroy/${encodeURIComponent(graphName)}`;
229236
this.serverAction('delete', url, {
230237
built: true, ran: false, debugged: false, cleared: false, stopped: false, destroyed: false,
231238
});
232239
}
233240

234241
library(fileName) {
235-
const url = `${EXECUTION_ENGINE_URL}/library/${this.superState.uploadedDirName}`
236-
+ `?filename=${fileName}&path=${this.superState.library}`;
242+
const query = new URLSearchParams({
243+
filename: fileName,
244+
path: this.superState.library,
245+
});
246+
const url = `${EXECUTION_ENGINE_URL}/library/${encodeURIComponent(this.superState.uploadedDirName)}`
247+
+ `?${query.toString()}`;
237248
this.serverAction('post', url, null);
238249
}
239250

0 commit comments

Comments
 (0)