-
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(javascript rule): dangerous javvascript html inserts (#693)
* feat: add rule for dangerous insert html * feat: dangerous insert html * docs: update docs
- Loading branch information
Showing
8 changed files
with
105 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
62 changes: 62 additions & 0 deletions
62
pkg/commands/process/settings/rules/javascript/lang/dangerous_insert_html.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,62 @@ | ||
patterns: | ||
- pattern: | | ||
document.$<METHOD>($<...>$<DATA>$<...>) | ||
filters: | ||
- variable: METHOD | ||
values: | ||
- write | ||
- writeLn | ||
- not: | ||
variable: DATA | ||
detection: javascript_dangerous_insert_html_sanitzed_input | ||
- pattern: | | ||
$<_>.$<METHOD>($<...>$<DATA>$<...>) | ||
filters: | ||
- variable: METHOD | ||
values: | ||
- setHTML | ||
- insertAdjacentHTML | ||
- createElement | ||
- replaceWith | ||
- replaceChildren | ||
- not: | ||
variable: DATA | ||
detection: javascript_dangerous_insert_html_sanitzed_input | ||
auxiliary: | ||
- id: javascript_dangerous_insert_html_sanitzed_input | ||
patterns: | ||
- pattern: | | ||
$<ANYTHING:string|template_string> | ||
filters: | ||
- not: | ||
variable: ANYTHING | ||
detection: javascript_dangerous_insert_html_unsanitzed_input | ||
- sanitize($<_>) | ||
- sanitizeHTML($<_>) | ||
- id: javascript_dangerous_insert_html_unsanitzed_input | ||
patterns: | ||
- | | ||
`$<...>${$<...>$<_>$<...>}$<...>` | ||
languages: | ||
- javascript | ||
trigger: presence | ||
severity: | ||
default: medium | ||
metadata: | ||
description: "Dangerous dynamic HTML insert detected." | ||
remediation_message: | | ||
## Description | ||
TODO | ||
## Remediations | ||
TODO | ||
<!-- | ||
## Resources | ||
Coming soon. | ||
--> | ||
cwe_id: | ||
- 79 | ||
id: "javascript_dangerous_insert_html" |
3 changes: 3 additions & 0 deletions
3
...cript/lang/dangerous_insert_html/.snapshots/TestJavascriptDangeoursInsertHTML--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 @@ | ||
{} | ||
|
||
|
13 changes: 13 additions & 0 deletions
13
...ous_insert_html/.snapshots/TestJavascriptDangeoursInsertHTML--unsecure-document_write.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,13 @@ | ||
medium: | ||
- rule: | ||
cwe_ids: | ||
- "79" | ||
id: javascript_dangerous_insert_html | ||
description: Dangerous dynamic HTML insert detected. | ||
documentation_url: https://docs.bearer.com/reference/rules/javascript_dangerous_insert_html | ||
line_number: 2 | ||
filename: unsecure-document_write.js | ||
parent_line_number: 2 | ||
parent_content: document.write(`<li>${input}</li>`) | ||
|
||
|
13 changes: 13 additions & 0 deletions
13
...gerous_insert_html/.snapshots/TestJavascriptDangeoursInsertHTML--unsecure-element_ref.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,13 @@ | ||
medium: | ||
- rule: | ||
cwe_ids: | ||
- "79" | ||
id: javascript_dangerous_insert_html | ||
description: Dangerous dynamic HTML insert detected. | ||
documentation_url: https://docs.bearer.com/reference/rules/javascript_dangerous_insert_html | ||
line_number: 2 | ||
filename: unsecure-element_ref.js | ||
parent_line_number: 2 | ||
parent_content: this.ref.replaceChildren(`<li>${input}</li>`) | ||
|
||
|
3 changes: 3 additions & 0 deletions
3
pkg/commands/process/settings/rules/javascript/lang/dangerous_insert_html/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,3 @@ | ||
function renderListItem(input) { | ||
this.ref.insertAdjacentHTML("beforebegin", `<li>fixed list item</li>`); | ||
} |
3 changes: 3 additions & 0 deletions
3
.../settings/rules/javascript/lang/dangerous_insert_html/testdata/unsecure-document_write.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 @@ | ||
function renderListItem(input) { | ||
document.write(`<li>${input}</li>`); | ||
} |
3 changes: 3 additions & 0 deletions
3
...ess/settings/rules/javascript/lang/dangerous_insert_html/testdata/unsecure-element_ref.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 @@ | ||
function renderListItem(input) { | ||
this.ref.replaceChildren(`<li>${input}</li>`); | ||
} |