-
Notifications
You must be signed in to change notification settings - Fork 94
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 open redirect rule (#713)
feat: add open redirect rule for JS
- Loading branch information
Showing
6 changed files
with
83 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
46 changes: 46 additions & 0 deletions
46
pkg/commands/process/settings/rules/javascript/lang/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,46 @@ | ||
patterns: | ||
- pattern: | | ||
location.href = $<USER_INPUT> | ||
filters: | ||
- variable: USER_INPUT | ||
detection: javascript_lang_open_redirect_url | ||
- pattern: | | ||
window.location.href = $<USER_INPUT> | ||
filters: | ||
- variable: USER_INPUT | ||
detection: javascript_lang_open_redirect_url | ||
languages: | ||
- javascript | ||
auxiliary: | ||
- id: javascript_lang_open_redirect_url | ||
patterns: | ||
- pattern: new $<METHOD>($<USER_INPUT>) | ||
filters: | ||
- variable: METHOD | ||
values: | ||
- URL | ||
- URLSearchParams | ||
- variable: USER_INPUT | ||
detection: javascript_lang_open_redirect_user_input | ||
- id: javascript_lang_open_redirect_user_input | ||
patterns: | ||
- window.location | ||
- location | ||
trigger: presence | ||
severity: | ||
default: "low" | ||
metadata: | ||
description: "Open redirect detected." | ||
remediation_message: | | ||
## Description | ||
A redirect using unsanitized user input is bad practice and puts your application at greater risk of phishing attacks. | ||
<!-- | ||
## Remediations | ||
Coming soon. | ||
## Resources | ||
Coming soon. | ||
--> | ||
cwe_id: | ||
- 601 | ||
id: "javascript_lang_open_redirect" |
23 changes: 23 additions & 0 deletions
23
...s/rules/javascript/lang/open_redirect/.snapshots/TestJavascriptOpenRedirect--insecure.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 @@ | ||
low: | ||
- rule: | ||
cwe_ids: | ||
- "601" | ||
id: javascript_lang_open_redirect | ||
description: Open redirect detected. | ||
documentation_url: https://docs.bearer.com/reference/rules/javascript_lang_open_redirect | ||
line_number: 4 | ||
filename: insecure.js | ||
parent_line_number: 4 | ||
parent_content: window.location.href = myPath | ||
- rule: | ||
cwe_ids: | ||
- "601" | ||
id: javascript_lang_open_redirect | ||
description: Open redirect detected. | ||
documentation_url: https://docs.bearer.com/reference/rules/javascript_lang_open_redirect | ||
line_number: 5 | ||
filename: insecure.js | ||
parent_line_number: 5 | ||
parent_content: location.href = myPath2 | ||
|
||
|
3 changes: 3 additions & 0 deletions
3
...ngs/rules/javascript/lang/open_redirect/.snapshots/TestJavascriptOpenRedirect--secure.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 @@ | ||
{} | ||
|
||
|
5 changes: 5 additions & 0 deletions
5
pkg/commands/process/settings/rules/javascript/lang/open_redirect/testdata/insecure.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,5 @@ | ||
var myPath = new URLSearchParams(window.location) | ||
var myPath2 = new URL(location.href) | ||
|
||
window.location.href = myPath | ||
location.href = myPath2 |
1 change: 1 addition & 0 deletions
1
pkg/commands/process/settings/rules/javascript/lang/open_redirect/testdata/secure.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 @@ | ||
window.location.href = "https://mish.bearer.com/?" + params["userId"] |