Semantic-aware SAST scanner for Node.js applications that detects insecure code patterns using libsast pattern matching and semgrep syntax-aware analysis.
njsscan is a static application testing (SAST) tool that can find insecure code patterns in your node.js applications using simple pattern matcher from libsast and syntax-aware semantic code pattern search tool semgrep.
OpSecX Node.js Security: Pentesting and Exploitation - NJS
pip install njsscan
Requires Python 3.10+ and supports only Mac and Linux
$ njsscan
usage: njsscan [-h] [--json] [--sarif] [--sonarqube] [--defectdojo] [--gitlab-sast] [--html] [-o OUTPUT] [-c CONFIG] [--missing-controls] [-w] [-v] [path ...]
positional arguments:
path Path can be file(s) or directories with source code
optional arguments:
-h, --help show this help message and exit
--json set output format as JSON
--sarif set output format as SARIF 2.1.0
--sonarqube set output format compatible with SonarQube
--defectdojo set output format compatible with DefectDojo Generic Findings Import
--gitlab-sast set output format as GitLab SAST report
--html set output format as HTML
-o OUTPUT, --output OUTPUT
output filename to save the result
-c CONFIG, --config CONFIG
Location to .njsscan config file
--missing-controls enable missing security controls check
-w, --exit-warning non zero exit code on warning
-v, --version show njsscan version
$ njsscan test.js
- Pattern Match ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ 1
- Semantic Grep βββββββββββββββββββββββββββ 160
njsscan: v0.1.9 | Ajin Abraham | opensecurity.in
βββββββββββββββ€ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β RULE ID β express_xss β
βββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β OWASP β A1: Injection β
βββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β CWE β CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') β
βββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β DESCRIPTION β Untrusted User Input in Response will result in Reflected Cross Site Scripting Vulnerability. β
βββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β SEVERITY β ERROR β
βββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β FILES β ββββββββββββββββββ€ββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β File β test.js β β
β β ββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββ€ β
β β β Match Position β 5 - 46 β β
β β ββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββ€ β
β β β Line Number(s) β 7: 8 β β
β β ββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββ€ β
β β β Match String β const { name } = req.query; β β
β β β β res.send('<h1> Hello :' + name + "</h1>") β β
β β ββββββββββββββββββ§ββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββ§ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
nodejsscan, built on top of njsscan provides a full fledged vulnerability management user interface along with other nifty integrations.

See nodejsscan
>>> from njsscan.njsscan import NJSScan
>>> node_source = '/node_source/true_positives/sqli_node.js'
>>> scanner = NJSScan([node_source], json=True, check_controls=False)
>>> scanner.scan()
{
'templates': {},
'nodejs': {
'node_sqli_injection': {
'files': [{
'file_path': '/node_source/true_positives/sqli_node.js',
'match_position': (1, 24),
'match_lines': (4, 11),
'match_string': 'var employeeId = req.foo;\n\nvar sql = "SELECT * FROM trn_employee WHERE employee_id = " + employeeId;\n\n\n\nconnection.query(sql, function (error, results, fields) {\n\n if (error) {\n\n throw error;\n\n }\n\n console.log(results);'
}],
'metadata': {
'owasp': 'A1: Injection',
'cwe': "CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')",
'description': 'Untrusted input concatinated with raw SQL query can result in SQL Injection.',
'severity': 'ERROR'
}
}
},
'errors': []
}
A .njsscan file in the root of the source code directory allows you to configure njsscan. You can also use a custom .njsscan file using --config argument.
---
- nodejs-extensions:
- .js
template-extensions:
- .new
- .hbs
- ''