-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(JS rules): add CWE 601 for express (Open Redirect) (#641)
feat: add cwe 601 open redirect for JS express
- Loading branch information
Showing
6 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
pkg/commands/process/settings/rules/javascript/express/open_redirect.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
patterns: | ||
- pattern: | | ||
res.redirect($<EXPRESS_REQ>$<...>) | ||
filters: | ||
- variable: EXPRESS_REQ | ||
detection: javascript_express_open_redirect_request_obj | ||
auxiliary: | ||
- id: javascript_express_open_redirect_request_obj | ||
patterns: | ||
- req.$<_> | ||
languages: | ||
- javascript | ||
trigger: presence | ||
severity: | ||
default: "low" | ||
metadata: | ||
description: "Open redirect detected." | ||
remediation_message: | | ||
## Description | ||
TODO. | ||
cwe_id: | ||
- 601 | ||
id: "javascript_express_open_redirect" |
3 changes: 3 additions & 0 deletions
3
...press/open_redirect/.snapshots/TestJavascriptExpressOpenRedirect--ok_no_open_redirect.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{} | ||
|
||
|
35 changes: 35 additions & 0 deletions
35
...ipt/express/open_redirect/.snapshots/TestJavascriptExpressOpenRedirect--open_redirect.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
low: | ||
- rule_dsrid: "" | ||
rule_display_id: javascript_express_open_redirect | ||
rule_description: Open redirect detected. | ||
rule_documentation_url: https://docs.bearer.com/reference/rules/javascript_express_open_redirect | ||
line_number: 2 | ||
filename: open_redirect.js | ||
parent_line_number: 2 | ||
parent_content: res.redirect(req.params.url) | ||
- rule_dsrid: "" | ||
rule_display_id: javascript_express_open_redirect | ||
rule_description: Open redirect detected. | ||
rule_documentation_url: https://docs.bearer.com/reference/rules/javascript_express_open_redirect | ||
line_number: 3 | ||
filename: open_redirect.js | ||
parent_line_number: 3 | ||
parent_content: res.redirect(req.query.url + "/bar") | ||
- rule_dsrid: "" | ||
rule_display_id: javascript_express_open_redirect | ||
rule_description: Open redirect detected. | ||
rule_documentation_url: https://docs.bearer.com/reference/rules/javascript_express_open_redirect | ||
line_number: 4 | ||
filename: open_redirect.js | ||
parent_line_number: 4 | ||
parent_content: res.redirect("https://" + req.params.url + "/bar") | ||
- rule_dsrid: "" | ||
rule_display_id: javascript_express_open_redirect | ||
rule_description: Open redirect detected. | ||
rule_documentation_url: https://docs.bearer.com/reference/rules/javascript_express_open_redirect | ||
line_number: 5 | ||
filename: open_redirect.js | ||
parent_line_number: 5 | ||
parent_content: res.redirect("http://" + req.params.path + "/bar") | ||
|
||
|
3 changes: 3 additions & 0 deletions
3
...s/process/settings/rules/javascript/express/open_redirect/testdata/ok_no_open_redirect.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports.foo = function(_req, res){ | ||
res.redirect("https://google.com") | ||
} |
6 changes: 6 additions & 0 deletions
6
...ommands/process/settings/rules/javascript/express/open_redirect/testdata/open_redirect.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports.foo = function(req, res){ | ||
res.redirect(req.params.url) | ||
res.redirect(req.query.url + "/bar") | ||
res.redirect("https://" + req.params.url + "/bar") | ||
res.redirect("http://" + req.params.path + "/bar") | ||
} |