-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support njsscan-ignore for templates (#64)
* support njsscan-ignore for templates (#64) * depricate `ignore:`
- Loading branch information
1 parent
fac7443
commit c6ea106
Showing
6 changed files
with
116 additions
and
31 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
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
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,31 @@ | ||
"""Libsast Patcher for supporting rules with metadata.""" | ||
from copy import deepcopy | ||
|
||
from libsast.core_matcher.pattern_matcher import PatternMatcher | ||
|
||
|
||
def add_finding(self, file_path, rule, matches): | ||
"""Add Code Analysis Findings.""" | ||
for match in matches: | ||
crule = deepcopy(rule) | ||
file_details = { | ||
'file_path': file_path.as_posix(), | ||
'match_string': match[0], | ||
'match_position': match[1], | ||
'match_lines': match[2], | ||
} | ||
if rule['id'] in self.findings: | ||
self.findings[rule['id']]['files'].append(file_details) | ||
else: | ||
metadata = crule['metadata'] | ||
metadata['description'] = crule['message'] | ||
metadata['severity'] = crule['severity'] | ||
self.findings[rule['id']] = { | ||
'files': [file_details], | ||
'metadata': metadata, | ||
} | ||
|
||
|
||
def patch_libsast(): | ||
"""Patch Libsast.""" | ||
PatternMatcher.add_finding = add_finding |
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 |
---|---|---|
@@ -1,91 +1,100 @@ | ||
--- | ||
- id: handlebar_mustache_template | ||
description: The Handlebar.js/Mustache.js template has an unescaped variable. Untrusted | ||
message: The Handlebar.js/Mustache.js template has an unescaped variable. Untrusted | ||
user input passed to this variable results in Cross Site Scripting (XSS). | ||
type: Regex | ||
pattern: '{{{(?!.*body).+}}}|{{[ ]*&[\w]+.*}}' | ||
severity: ERROR | ||
input_case: exact | ||
cwe: "CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')" | ||
owasp: "A1: Injection" | ||
metadata: | ||
cwe: cwe-79 | ||
owasp: "A1: Injection" | ||
|
||
- id: dust_template | ||
description: The Dust.js template has an unescaped variable. Untrusted user input | ||
message: The Dust.js template has an unescaped variable. Untrusted user input | ||
passed to this variable results in Cross Site Scripting (XSS) | ||
type: Regex | ||
pattern: '{.+\|[ ]*s[ ]*}[^}]' | ||
severity: ERROR | ||
input_case: exact | ||
cwe: "CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')" | ||
owasp: "A1: Injection" | ||
metadata: | ||
cwe: cwe-79 | ||
owasp: "A1: Injection" | ||
|
||
- id: pug_jade_template | ||
description: The Pug.js/Jade.js template has an unescaped variable. Untrusted user | ||
message: The Pug.js/Jade.js template has an unescaped variable. Untrusted user | ||
input passed to this variable results in Cross Site Scripting (XSS). | ||
type: Regex | ||
pattern: '!{.+}' | ||
severity: ERROR | ||
input_case: exact | ||
cwe: "CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')" | ||
owasp: "A1: Injection" | ||
metadata: | ||
cwe: cwe-79 | ||
owasp: "A1: Injection" | ||
|
||
- id: ejs_ect_template | ||
description: The EJS/ECT template has an unescaped variable. Untrusted user input | ||
message: The EJS/ECT template has an unescaped variable. Untrusted user input | ||
passed to this variable results in Cross Site Scripting (XSS). | ||
type: Regex | ||
pattern: <%-(?![ ]*include\().*%> | ||
severity: ERROR | ||
input_case: exact | ||
cwe: "CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')" | ||
owasp: "A1: Injection" | ||
metadata: | ||
cwe: cwe-79 | ||
owasp: "A1: Injection" | ||
|
||
- id: vue_template | ||
description: The Vue.js template has an unescaped variable. Untrusted user input | ||
message: The Vue.js template has an unescaped variable. Untrusted user input | ||
passed to this variable results in Cross Site Scripting (XSS). | ||
type: Regex | ||
pattern: v-html=[\'|"].+[\'|"] | ||
severity: ERROR | ||
input_case: exact | ||
cwe: "CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')" | ||
owasp: "A1: Injection" | ||
metadata: | ||
cwe: cwe-79 | ||
owasp: "A1: Injection" | ||
|
||
- id: underscore_template | ||
description: The Underscore unescape function with untrusted user input results | ||
message: The Underscore unescape function with untrusted user input results | ||
in Cross Site Scripting (XSS). | ||
type: Regex | ||
pattern: '_.unescape\(.+\)' | ||
severity: ERROR | ||
input_case: exact | ||
cwe: "CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')" | ||
owasp: "A1: Injection" | ||
metadata: | ||
cwe: cwe-79 | ||
owasp: "A1: Injection" | ||
|
||
- id: squirrelly_template | ||
description: The Squirrelly.js template has an unescaped variable. Untrusted user input | ||
message: The Squirrelly.js template has an unescaped variable. Untrusted user input | ||
passed to this variable results in Cross Site Scripting (XSS) | ||
type: Regex | ||
pattern: '{{.+\|.*safe.*}}' | ||
severity: ERROR | ||
input_case: exact | ||
cwe: "CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')" | ||
owasp: "A1: Injection" | ||
metadata: | ||
cwe: cwe-79 | ||
owasp: "A1: Injection" | ||
|
||
- id: electronjs_node_integration | ||
description: Node integration exposes node.js APIs to the electron app and this | ||
message: Node integration exposes node.js APIs to the electron app and this | ||
can introduce remote code execution vulnerabilities to the application if the | ||
app is vulnerable to Cross Site Scripting (XSS). | ||
type: Regex | ||
pattern: <webview.+nodeIntegration(?!.*=.*['|"]false['|"]) | ||
severity: WARNING | ||
input_case: exact | ||
cwe: "CWE-272: Least Privilege Violation" | ||
owasp: "A6: Security Misconfiguration" | ||
metadata: | ||
cwe: cwe-272 | ||
owasp: "A6: Security Misconfiguration" | ||
|
||
- id: electronjs_disable_websecurity | ||
description: Disabling webSecurity will disable the same-origin policy and | ||
message: Disabling webSecurity will disable the same-origin policy and | ||
allows the execution of insecure code from any domain. | ||
type: Regex | ||
pattern: <webview.+disablewebsecurity(?!.*=.*['|"]false['|"]) | ||
severity: ERROR | ||
input_case: exact | ||
cwe: "CWE-346: Origin Validation Error" | ||
owasp: "A6: Security Misconfiguration" | ||
metadata: | ||
cwe: cwe-79 | ||
owasp: "A6: Security Misconfiguration" |
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 @@ | ||
<script> | ||
window.MY_VAR = "{{{val}}}"; // njsscan-ignore: handlebar_mustache_template | ||
</script> |
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