Skip to content

Commit 3d52392

Browse files
authored
Merge pull request #340 from Titas-Ghosh/fix/server-action-url-encoding
Encode server action URLs safely and fix GraphArea lint return path
2 parents 722e87b + 6dbec72 commit 3d52392

2 files changed

Lines changed: 32 additions & 24 deletions

File tree

src/GraphArea.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ function Graph({
5656
}, [active, instance, graphID, dispatcher]);
5757

5858
useEffect(() => {
59-
if (!ref.current) return;
60-
setContainerDim(ref.current);
6159
const handleResize = () => setContainerDim(ref.current);
62-
window.addEventListener('resize', handleResize);
63-
setInstance(initialiseNewGraph());
60+
if (ref.current) {
61+
setContainerDim(ref.current);
62+
window.addEventListener('resize', handleResize);
63+
setInstance(initialiseNewGraph());
64+
}
6465
return () => window.removeEventListener('resize', handleResize);
6566
}, [ref]);
6667

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

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class GraphServer extends GraphLoadSave {
5151
// this.setGraphML(graphXML);
5252
// });
5353
// } else {
54-
// // eslint-disable-next-line no-toast.success
5554
// toast.success('Not on server');
5655
// }
5756
// }
@@ -65,7 +64,6 @@ class GraphServer extends GraphLoadSave {
6564

6665
// });
6766
// } else {
68-
// // eslint-disable-next-line no-toast.success
6967
// toast.success('Not on server');
7068
// }
7169
// }
@@ -119,7 +117,6 @@ class GraphServer extends GraphLoadSave {
119117
toast.error(err.response?.data?.message || err.message);
120118
});
121119
} else {
122-
// eslint-disable-next-line no-toast.success
123120
toast.success('Not on server');
124121
}
125122
}
@@ -133,7 +130,6 @@ class GraphServer extends GraphLoadSave {
133130

134131
});
135132
} else {
136-
// eslint-disable-next-line no-toast.success
137133
toast.success('Not on server');
138134
}
139135
}
@@ -170,12 +166,16 @@ class GraphServer extends GraphLoadSave {
170166
build() {
171167
const graphName = this.getCurrentGraphName();
172168
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}`;
169+
const query = new URLSearchParams({
170+
fetch: graphName,
171+
unlock: this.superState.unlockCheck,
172+
docker: this.superState.dockerCheck,
173+
maxtime: this.superState.maxTime,
174+
params: this.superState.params,
175+
octave: this.superState.octave,
176+
});
177+
const url = `${EXECUTION_ENGINE_URL}/build/${encodeURIComponent(this.superState.uploadedDirName)}`
178+
+ `?${query.toString()}`;
179179
this.serverAction('post', url, {
180180
built: false, ran: true, debugged: true, cleared: false, stopped: false, destroyed: true,
181181
}, (res) => {
@@ -186,7 +186,7 @@ class GraphServer extends GraphLoadSave {
186186
debug() {
187187
const graphName = this.getCurrentGraphName();
188188
if (!graphName) return;
189-
const url = `${EXECUTION_ENGINE_URL}/debug/${graphName}`;
189+
const url = `${EXECUTION_ENGINE_URL}/debug/${encodeURIComponent(graphName)}`;
190190
this.serverAction('post', url, {
191191
built: false, ran: false, debugged: false, cleared: true, stopped: true, destroyed: true,
192192
});
@@ -195,7 +195,7 @@ class GraphServer extends GraphLoadSave {
195195
run() {
196196
const graphName = this.getCurrentGraphName();
197197
if (!graphName) return;
198-
const url = `${EXECUTION_ENGINE_URL}/run/${graphName}`;
198+
const url = `${EXECUTION_ENGINE_URL}/run/${encodeURIComponent(graphName)}`;
199199
this.serverAction('post', url, {
200200
built: false, ran: false, debugged: false, cleared: true, stopped: true, destroyed: true,
201201
});
@@ -204,10 +204,13 @@ class GraphServer extends GraphLoadSave {
204204
clear() {
205205
const graphName = this.getCurrentGraphName();
206206
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}`;
207+
const query = new URLSearchParams({
208+
unlock: this.superState.unlockCheck,
209+
maxtime: this.superState.maxTime,
210+
params: this.superState.params,
211+
});
212+
const url = `${EXECUTION_ENGINE_URL}/clear/${encodeURIComponent(graphName)}`
213+
+ `?${query.toString()}`;
211214
this.serverAction('post', url, {
212215
built: false, ran: true, debugged: true, cleared: false, stopped: true, destroyed: true,
213216
});
@@ -216,7 +219,7 @@ class GraphServer extends GraphLoadSave {
216219
stop() {
217220
const graphName = this.getCurrentGraphName();
218221
if (!graphName) return;
219-
const url = `${EXECUTION_ENGINE_URL}/stop/${graphName}`;
222+
const url = `${EXECUTION_ENGINE_URL}/stop/${encodeURIComponent(graphName)}`;
220223
this.serverAction('post', url, {
221224
built: false, ran: false, debugged: false, cleared: true, stopped: false, destroyed: true,
222225
});
@@ -225,15 +228,19 @@ class GraphServer extends GraphLoadSave {
225228
destroy() {
226229
const graphName = this.getCurrentGraphName();
227230
if (!graphName) return;
228-
const url = `${EXECUTION_ENGINE_URL}/destroy/${graphName}`;
231+
const url = `${EXECUTION_ENGINE_URL}/destroy/${encodeURIComponent(graphName)}`;
229232
this.serverAction('delete', url, {
230233
built: true, ran: false, debugged: false, cleared: false, stopped: false, destroyed: false,
231234
});
232235
}
233236

234237
library(fileName) {
235-
const url = `${EXECUTION_ENGINE_URL}/library/${this.superState.uploadedDirName}`
236-
+ `?filename=${fileName}&path=${this.superState.library}`;
238+
const query = new URLSearchParams({
239+
filename: fileName,
240+
path: this.superState.library,
241+
});
242+
const url = `${EXECUTION_ENGINE_URL}/library/${encodeURIComponent(this.superState.uploadedDirName)}`
243+
+ `?${query.toString()}`;
237244
this.serverAction('post', url, null);
238245
}
239246

0 commit comments

Comments
 (0)