You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ebc1d35
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: capabilities/web-security/skills/dom-vulnerability-static-analysis/SKILL.md
+39-2Lines changed: 39 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -63,8 +63,45 @@ For DOMPurify: check version and config -- see `dompurify-mxss-bypass` skill.
63
63
64
64
## 4. AST-based analysis (large codebases)
65
65
66
-
-**Semgrep**: `semgrep --config p/javascript` for DOM XSS rules
67
-
-**CodeQL**: `javascript/ql/src/Security/CWE-079` for taint tracking
66
+
`rg` patterns are fragile for code constructs — they miss variations in whitespace, nesting, and comments. Use AST-based tools for structural matching.
67
+
68
+
### ast-grep (installed in runtime)
69
+
70
+
ast-grep uses tree-sitter for structural code matching. Patterns use real code syntax with `$VAR` wildcards — far more accurate than regex for function calls, assignments, and nested expressions.
71
+
72
+
```bash
73
+
# innerHTML / outerHTML sinks — catches any receiver expression
Add `--json` to any command for structured output with file paths, line/column positions, and captured metavariable values. This is useful for programmatic triage or feeding results into jxscout custom analyzers.
100
+
101
+
### Additional AST tools (if operator-installed)
102
+
103
+
-**Semgrep**: `semgrep --config p/javascript` for DOM XSS rules (includes taint tracking in Pro)
104
+
-**CodeQL**: `javascript/ql/src/Security/CWE-079` for data-flow taint analysis
Copy file name to clipboardExpand all lines: capabilities/web-security/skills/jxscout-custom-analyzers/SKILL.md
+84-5Lines changed: 84 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,12 +20,13 @@ The `JXSCOUT_PROJECT_NAME` environment variable must be set. The project setting
20
20
21
21
## Choosing the right analyzer type
22
22
23
-
For JS/TS code pattern matching (function calls, assignments, data flow, control structures), **prefer AST-based analysis via script analyzers**(e.g. semgrep) over regex. Regex works for simple literal patterns -- hardcoded URLs, API keys, specific strings -- but is fragile for code constructs because it misses variations in whitespace, formatting, nesting, and comments.
23
+
For JS/TS code pattern matching (function calls, assignments, data flow, control structures), **prefer AST-based analysis via script analyzers** over regex. Regex works for simple literal patterns -- hardcoded URLs, API keys, specific strings -- but is fragile for code constructs because it misses variations in whitespace, formatting, nesting, and comments.
24
24
25
25
Rule of thumb:
26
26
-**Regex**: simple string patterns that don't depend on code structure
27
27
-**Derived**: narrowing down an existing match kind by value
28
-
-**Script (semgrep)**: anything involving code semantics -- function calls, assignments, data flow, missing checks
28
+
-**Script (ast-grep)**: anything involving code semantics -- function calls, assignments, data flow, missing checks. Installed in the runtime, use this by default.
29
+
-**Script (semgrep)**: same use case as ast-grep, with additional taint tracking in semgrep Pro. Only available if operator-installed.
29
30
30
31
## Analyzer types
31
32
@@ -113,9 +114,87 @@ The script receives file paths on stdin (one per line) and must output a JSON ar
113
114
114
115
`$JXSCOUT_PROJECT_DIR` and `$JXSCOUT_PROJECT_NAME` are available as environment variables in all scripts.
115
116
116
-
## Using semgrep for JS analysis
117
+
## Using ast-grep for JS analysis (installed in runtime)
117
118
118
-
When semgrep is available and you need to find JS/TS code patterns, prefer it over regex. Semgrep uses AST-based matching which is far more accurate for code patterns (function calls, assignments, data flow) than regular expressions.
119
+
ast-grep uses tree-sitter for AST-based structural code matching. Patterns use real code syntax with `$VAR` wildcards -- far more accurate than regex for function calls, assignments, and nested expressions. Prefer ast-grep over regex for script analyzers.
120
+
121
+
### 1. Create the wrapper script
122
+
123
+
Create `scripts/ast_grep_to_jxscout.sh` in your project directory. This script converts ast-grep JSON output to the jxscout match format:
For analyzers that need several patterns (e.g. all eval-family sinks), create one analyzer per pattern with a shared match kind, or write a wrapper that runs ast-grep multiple times and merges the output.
194
+
195
+
## Using semgrep for JS analysis (if operator-installed)
196
+
197
+
When semgrep is available and you need taint tracking or data-flow analysis beyond structural matching, use it as a script analyzer. Semgrep is not installed in the runtime by default.
119
198
120
199
### 1. Create a semgrep rule
121
200
@@ -304,7 +383,7 @@ jxscout auto-reloads when `settings.jsonc` changes, so the view updates immediat
304
383
305
384
## Workflow for adding a custom analyzer
306
385
307
-
1. Decide the analyzer type: regex for simple literal patterns, derived for filtering existing match kinds, script for code-semantic analysis (prefer semgrep for JS/TS when available)
386
+
1. Decide the analyzer type: regex for simple literal patterns, derived for filtering existing match kinds, script for code-semantic analysis (prefer ast-grep for JS/TS structural matching; use semgrep if operator-installed and taint tracking is needed)
308
387
2. Add the configuration to `settings.jsonc` under `analyzer > custom_analyzers`
309
388
3. Test with `analyze` on a file that should match (create a temp test file if needed, then delete it)
310
389
4. **Always** add the new match kind to the VS Code matches view -- **first ensure the full `vscode_extension` block is in `settings.jsonc`** (get it from `print-full-project-settings` if missing), then append your entry
0 commit comments