Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ app.post('/test5', function (req,res) {
}
})

app.get('/test-replace', function (req,res) {
const sanitized = req.query.path.replace(/\.\.\//g, '');
// ruleid:express-path-join-resolve-traversal
return path.join(opts.path, sanitized);
})

app.post('/ok-test1', function okTest1(req,res) {
let data = ['one', 'two', 'three'];
for (let x of data) {
Expand All @@ -71,10 +77,10 @@ app.post('/ok-test2', function okTest2() {
someFunc()
})

app.post('/ok-test3', function (req,res) {
app.post('/test-replace-prefix', function testReplacePrefix(req,res) {
let somePath = req.body.path;
somePath = somePath.replace(/^(\.\.(\/|\\|$))+/, '');
// ok:express-path-join-resolve-traversal
// ruleid:express-path-join-resolve-traversal
return path.join(opts.path, somePath);
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ rules:
- pattern: path.join(...,$SINK,...)
- pattern: path.resolve(...,$SINK,...)
pattern-sanitizers:
- pattern: $Y.replace(...)
- pattern: $Y.indexOf(...)
- pattern: |
function ... (...) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ function test4(req,res) {
})
}

function testReplace(userInput) {
const sanitized = userInput.replace(/\.\.\//g, '');
// ruleid:path-join-resolve-traversal
return path.join('/tmp/semgrep-root', sanitized);
}

function okTest1(req,res) {
let data = ['one', 'two', 'three'];
for (let x of data) {
Expand All @@ -56,10 +62,10 @@ function okTest2() {
someFunc()
}

function okTest3(req,res) {
function testReplacePrefix(req,res) {
let somePath = req.body.path;
somePath = somePath.replace(/^(\.\.(\/|\\|$))+/, '');
// ok:path-join-resolve-traversal
// ruleid:path-join-resolve-traversal
return path.join(opts.path, somePath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ function test5(req,res) {
}
}

function testReplace(userInput: string) {
const sanitized = userInput.replace(/\.\.\//g, '');
// ruleid:path-join-resolve-traversal
return join('/tmp/semgrep-root', sanitized);
}

function okTest1(req,res) {
let data = ['one', 'two', 'three'];
for (let x of data) {
Expand All @@ -66,10 +72,10 @@ function okTest2() {
someFunc()
}

function okTest3(req,res) {
function testReplacePrefix(req,res) {
let somePath = req.body.path;
somePath = somePath.replace(/^(\.\.(\/|\\|$))+/, '');
// ok:path-join-resolve-traversal
// ruleid:path-join-resolve-traversal
return join(opts.path, somePath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ rules:
- pattern-inside: path.join(...,$SINK,...)
- pattern-inside: path.resolve(...,$SINK,...)
pattern-sanitizers:
- pattern: $Y.replace(...)
- pattern: $Y.indexOf(...)
- pattern: |
function ... (...) {
Expand Down