
opensecurity/njsscannjsscan是一款静态应用安全测试(SAST)工具,专为Node.js应用设计。它结合了libsast的简单模式匹配器和semgrep的语法感知语义代码模式搜索能力,能够有效识别Node.js源代码中的不安全代码模式。
.njsscan配置文件自定义扫描规则、忽略路径和文件pip install njsscanbash$ njsscan usage: njsscan [-h] [--json] [--sarif] [--sonarqube] [--html] [-o OUTPUT] [-c CONFIG] [--missing-controls] [-w] [-v] [path ...] 位置参数: path 源代码文件或目录路径 可选参数: -h, --help 显示帮助信息并退出 --json 设置输出格式为JSON --sarif 设置输出格式为SARIF 2.1.0 --sonarqube 设置为SonarQube兼容格式 --html 设置输出格式为HTML -o OUTPUT, --output OUTPUT 保存结果的输出文件名 -c CONFIG, --config CONFIG .njsscan配置文件位置 --missing-controls 启用缺失安全控制检查 -w, --exit-warning 警告时返回非零退出码 -v, --version 显示njsscan版本
基本扫描命令:
bash$ 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>") │ │ │ │ ╘════════════════╧═══════════════════════════════════════════════╛ │ ╘═════════════╧═══════════════════════════════════════════════════════════════════════════════════════════════╛
通过项目根目录的.njsscan文件或--config参数指定的配置文件自定义扫描行为:
yaml--- - nodejs-extensions: - .js template-extensions: - .new - .hbs - '' ignore-filenames: - skip.js ignore-paths: - __MACOSX - skip_dir - node_modules ignore-extensions: - .jsx ignore-rules: - regex_injection_dos - pug_jade_template severity-filter: - WARNING - ERROR
在触发问题的代码行添加注释 // njsscan-ignore: rule_id1, rule_id2 可忽略指定规则:
javascriptapp.get('/some/redirect', function (req, res) { var target = req.param("target"); res.redirect(target); // njsscan-ignore: express_open_redirect });
bashdocker pull opensecurity/njsscan docker run -v /本地源代码路径:/src opensecurity/njsscan /src
bashdocker build -t njsscan . docker run -v /本地源代码路径:/src njsscan /src
创建文件 .github/workflows/njsscan.yml:
yamlname: njsscan on: push: branches: [ master, main ] pull_request: branches: [ master, main ] jobs: njsscan: runs-on: ubuntu-latest name: njsscan check steps: - name: Checkout the code uses: actions/checkout@v2 - name: nodejsscan scan id: njsscan uses: ajinabraham/njsscan-action@master with: args: '.'
在 .gitlab-ci.yml 中添加:
yamlstages: - test njsscan: image: python before_script: - pip3 install --upgrade njsscan script: - njsscan .
在 .travis.yml 中添加:
yamllanguage: python install: - pip3 install --upgrade njsscan script: - njsscan .
python>>> 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': [] }
nodejsscan基于njsscan构建,提供完整的漏洞管理用户界面及其他集成功能。详情参见nodejsscan。



manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务