Skip to content

Commit

Permalink
fix(core): make sanitizePath cross-platform (#6308)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel authored and FrozenPandaz committed Jul 12, 2021
1 parent 3a2d74c commit 9b3f23a
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/workspace/src/command-line/dep-graph.ts
Expand Up @@ -6,7 +6,7 @@ import { copySync, ensureDirSync } from 'fs-extra';
import * as http from 'http';
import ignore from 'ignore';
import * as open from 'open';
import { dirname, join, normalize, parse } from 'path';
import { dirname, join, parse, basename } from 'path';
import { performance } from 'perf_hooks';
import { URL } from 'url';
import { workspaceLayout } from '../core/file-utils';
Expand Down Expand Up @@ -369,18 +369,16 @@ function startServer(
// Avoid https://en.wikipedia.org/wiki/Directory_traversal_attack
// e.g curl --path-as-is http://localhost:9000/../fileInDanger.txt
// by limiting the path to current directory only
const sanitizePath = normalize(parsedUrl.pathname).replace(
/^(\.\.[\/\\])+/,
''
);

if (sanitizePath === '/projectGraph.json') {
const sanitizePath = basename(parsedUrl.pathname);

if (sanitizePath === 'projectGraph.json') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(currentDepGraphClientResponse));
return;
}

if (sanitizePath === '/currentHash') {
if (sanitizePath === 'currentHash') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ hash: currentDepGraphClientResponse.hash }));
return;
Expand Down

0 comments on commit 9b3f23a

Please sign in to comment.