Skip to content

Commit 5249a3f

Browse files
Potential fix for code scanning alert no. 350: Server-side request forgery (#32879)
Signed-off-by: Alex Lavrov <36633600+alexslavr@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 272bcb3 commit 5249a3f

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

packages/devextreme/testing/runner/lib/vectormap.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,33 @@ function wait(timeout: number): Promise<void> {
8484
});
8585
}
8686

87+
function sanitizeVectorMapArg(arg: string): string {
88+
const trimmed = arg.trim();
89+
90+
// Reject empty values
91+
if (!trimmed) {
92+
throw new Error('Vector map argument must not be empty.');
93+
}
94+
95+
// Disallow characters and sequences that can alter the path structure
96+
if (trimmed.includes('/') || trimmed.includes('\\') || trimmed.includes('?') || trimmed.includes('#')) {
97+
throw new Error('Vector map argument contains invalid characters.');
98+
}
99+
100+
// Prevent simple path traversal attempts
101+
if (trimmed.includes('..')) {
102+
throw new Error('Vector map argument must not contain path traversal sequences.');
103+
}
104+
105+
// Optionally enforce a reasonable maximum length to avoid resource abuse
106+
if (trimmed.length > 256) {
107+
throw new Error('Vector map argument is too long.');
108+
}
109+
110+
// Encode as a single safe URL path segment
111+
return encodeURIComponent(trimmed);
112+
}
113+
87114
function httpGetText(targetUrl: string): Promise<string> {
88115
return new Promise((resolve, reject) => {
89116
const request = http.get(targetUrl, (response) => {
@@ -205,8 +232,10 @@ export function createVectorMapService({
205232
arg: string,
206233
startTime: number,
207234
): Promise<string> {
235+
const safeArg = sanitizeVectorMapArg(arg);
236+
208237
try {
209-
return await httpGetText(`http://127.0.0.1:${vectorMapTesterPort}/${action}/${arg}`);
238+
return await httpGetText(`http://127.0.0.1:${vectorMapTesterPort}/${action}/${safeArg}`);
210239
} catch (error) {
211240
if (Date.now() - startTime > VECTOR_SERVER_RETRY_TIMEOUT_MS) {
212241
throw error;

0 commit comments

Comments
 (0)