
Node.js 애플리케이션을 위한 의미 인식 SAST 스캐너로, libsast 패턴 매칭과 semgrep 구문 인식 분석을 사용하여 안전하지 않은 코드 패턴을 탐지합니다.
njsscan은 libsast의 간단한 패턴 매처와 구문 인식 의미적 코드 패턴 검색 도구인 semgrep을 사용하여 node.js 애플리케이션에서 안전하지 않은 코드 패턴을 찾을 수 있는 정적 애플리케이션 테스트(SAST) 도구입니다.
OpSecX Node.js 보안: 침투 테스트 및 익스플로잇 - NJS
pip install njsscan
Python 3.10+가 필요하며 Mac과 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>") │ │
│ │ ╘════════════════╧═══════════════════════════════════════════════╛ │
╘═════════════╧═══════════════════════════════════════════════════════════════════════════════════════════════╛
njsscan을 기반으로 구축된 nodejsscan은 다양한 유용한 통합 기능과 함께 완전한 기능을 갖춘 취약점 관리 사용자 인터페이스를 제공합니다.

자세한 내용은 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': []
}
소스 코드 디렉터리의 루트에 있는 .njsscan 파일로 njsscan을 구성할 수 있습니다. --config 인수를 사용하여 사용자 지정 .njsscan 파일을 사용할 수도 있습니다.
---
- 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
severity-overrides:
express_xss: WARNING
node_secret: ERROR
JavaScript 소스 파일에서 검출 결과를 트리거하는 줄에 // njsscan-ignore: rule_id1, rule_id2 주석을 추가하여 해당 결과를 억제할 수 있습니다.
예시:
app.get('/some/redirect', function (req, res) {
var target = req.param("target");
res.redirect(target); // njsscan-ignore: express_open_redirect
});
CI/CD 또는 DevSecOps 파이프라인에서 njsscan을 활성화할 수 있습니다.
.github/workflows/njsscan.yml 파일에 다음을 추가하세요.
name: 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@v7
- uses: actions/setup-python@v7
with:
python-version: '3.12'
- name: nodejsscan scan
id: njsscan
uses: ajinabraham/njsscan-action@master
with:
args: '.'
예시: njsscan GitHub Action을 사용하는 dvna
.github/workflows/njsscan_sarif.yml 파일에 다음을 추가하세요.
name: njsscan sarif
on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]
jobs:
njsscan:
runs-on: ubuntu-latest
name: njsscan code scanning
steps:
- name: Checkout the code
uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.12'
- name: nodejsscan scan
id: njsscan
uses: ajinabraham/njsscan-action@master
with:
args: '. --sarif --output results.sarif || true'
- name: Upload njsscan report
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif

.gitlab-ci.yml 파일에 다음을 추가하세요.
stages:
- test
njsscan:
image: python:3.12
stage: test
before_script:
- pip3 install --upgrade njsscan
script:
- njsscan . --gitlab-sast -o gl-sast-report.json
artifacts:
reports:
sast: gl-sast-report.json
명령 예시(로컬):
njsscan . --gitlab-sast -o gl-sast-report.json
이렇게 하면 SARIF 변환기 없이도 기본 GitLab SAST 보고서가 작성되어 발견 항목이 취약점 보고서 / MR 보안 위젯에 표시됩니다.
.travis.yml 파일에 다음을 추가하세요.
language: python
install:
- pip3 install --upgrade njsscan
script:
- njsscan .
.circleci/config.yaml 파일에 다음을 추가하세요.
version: 2.1
jobs:
njsscan:
docker:
- image: cimg/python:3.9.6
steps:
- checkout
- run:
name: Install njsscan
command: pip install --upgrade njsscan
- run:
name: njsscan check
command: njsscan .
docker pull opensecurity/njsscan
docker run -v /path-to-source-dir:/src opensecurity/njsscan /src
docker build -t njsscan .
docker run -v /path-to-source-dir:/src njsscan /src