Multi-language static application security testing (SAST) scanner for MoonBit, C/C++, JavaScript/TypeScript, Python, Java, Go, Rust, PHP and more: 84 built-in data-driven rules with CWE/OWASP mapping, taint analysis, console/JSON/JUnit/SARIF/HTML reporting, and a Markdown report with Mermaid diagrams
flowchart LR
T["target<br/>coordinate / directory / inline source"] --> D["file discovery<br/>language routing"]
D --> P["tree-sitter parse<br/>13 languages"]
P --> Q["query match<br/>84 rules"]
P --> C["C IR / CFG<br/>MCIL"]
Q --> T2["taint analysis<br/>taint.json"]
C --> T2
T2 --> S["scoring and suppression<br/>sast-ignore"]
S --> A["aggregation and dedup<br/>fingerprint"]
A --> R["report<br/>console / json / junit / sarif / html / markdown"]| Language | Rules | Language | Rules |
|---|---|---|---|
| C | 10 | Python | 10 |
| C++ | 10 | Java | 10 |
| JavaScript | 10 | JSON | 10 |
| TypeScript | 5 | MoonBit | 10 |
| TSX | 5 | C# | 1 |
| Go | 1 | Rust | 1 |
| PHP | 1 | — | — |
| Backend | moon check | moon test | What it can do |
|---|---|---|---|
| native | 331 warnings / 0 errors | 255 / 255 | everything: directory scans, moon fetch, report files |
| wasm | 331 warnings / 0 errors | 255 / 255 | everything, and this is the artifact the registry serves |
| js | 11 warnings / 0 errors | 201 / 201 | inline sources only (--source) |
| wasm-gc | 10 warnings / 0 errors | 200 / 200 | inline sources only (--source) |
flowchart TB
subgraph PURE["pure analysis core · every backend"]
SC["scan.mbt<br/>parse / query / taint / aggregate"]
CO["coord.mbt<br/>coordinate or path"]
EM["embedded rule pack<br/>rules_json / taint_json"]
end
subgraph FS["filesystem layer · native + wasm only"]
TR["tree.mbt<br/>discover / read / cache"]
LB["langc_bridge.mbt<br/>C preprocessor process"]
CM["src/command/backend.mbt<br/>read and write files / moon fetch"]
end
SC --> TR
SC --> LB
SC --> CM
CO --> CM
EM --> SCwasm-gc has one more upstream limit: moonbitlang/core/async provides
run_async_main on native, js and wasm, and not on wasm-gc. So
wasm-gc gets the synchronous entry point run_sync.mbt — it still scans
the sources it is given and prints the report, it just cannot await
asynchronous I/O.| Format | Artifact | What it is for |
|---|---|---|
| console | stdout | human reading, with file:line:col |
| json | findings.json | machines, with fingerprints |
| junit | junit.xml | CI test reports |
| sarif | findings.sarif | SARIF 2.1.0, with partialFingerprints |
| html | findings.html | a single-file page |
| markdown | findings.md | one Markdown report with Mermaid diagrams: numbered sections, tables, diagrams |
$ scan riantr/moonbit_markdown@0.1.4
LunaShield 0.3.0
files: 56 scanned, 17 skipped, 8 raw hits
findings: 2 (critical 0, high 2, medium 0, low 0, info 0)
...
report: ./findings.mdTen sections: acquisition and version pinning / ingestion statistics / the
funnel / severity distribution / where the findings are / the findings /
the rules that fired / the skipped files / method summary / reproduction
command. Three diagrams inside:flowchart LR
classDef stage fill:#fff9c4,stroke:#f9a825
classDef result fill:#c8e6c9,stroke:#1b5e20,stroke-width:2px
f0["discovered 73"]:::stage --> f1["scanned 56"]:::stage --> f2["raw hits 8"]:::stage --> f3["findings 2"]:::resultpie title Findings by severity
"high" : 2flowchart LR
classDef rule fill:#e1bee7,stroke:#4a148c
classDef high fill:#ffcdd2,stroke:#b71c1c
r0["MB001"]:::rule --> n0["src/mdcli/io_native.mbt:134:13"]:::highFinding text is untrusted input. A | in a snippet breaks a table row
and a <script> in a snippet becomes live HTML in a Markdown viewer, so the
table cells and the Mermaid labels are escaped separately — which is why
raw source snippets never appear unescaped in the report.Paths are relative. The paths the scanner resolves itself (a coordinate
is fetched into an absolute path under the working directory) are written
relative to the working directory: the same tree scanned on two machines has
to produce the same bytes, and an absolute path pins the report to one
machine. A path that is not under the working directory is left alone — it
has no relative form that would mean anything.| You call | You get back | Shape |
|---|---|---|
| scan <coord> | the console report and the Markdown report | stdout + findings.md |
| scan --format json | machine-readable findings with fingerprints | findings.json |
| scan --format sarif | SARIF 2.1.0 with partialFingerprints | findings.sarif |
| scan --format junit | a CI test report | junit.xml |
| scan --format html | a single-file page | findings.html |
| scan --format markdown | one Markdown report with Mermaid diagrams | findings.md |
| scan --source <path>=<text> | the same analysis, with no filesystem at all | stdout |
| scan --shard i/n | the shard's findings; the merged report is byte-identical to a single run | findings.json |
| scan --incremental | per-file results reused from the cache | cache directory |
| scan --baseline <report.json> | only the findings that are new | baselineState in SARIF |
| moonx riantr/LunaShield@latest <coord> | the same, from the published wasm artifact | stdout + findings.md |
moonx riantr/LunaShield@latest <author>/<module>@<version>sequenceDiagram
participant U as user
participant X as moonx
participant S as LunaShield(wasm)
participant M as moon
U->>X: moonx riantr/LunaShield@latest riantr/target@0.1.0
X->>S: fetch and instantiate the wasm artifact
S->>M: moon fetch riantr/target@0.1.0
M-->>S: .repos/riantr/target/0.1.0/
S->>S: discover → parse → query → taint → aggregate
S-->>U: report + exit codemoon add riantr/LunaShield@0.3.0import {
"riantr/LunaShield@0.3.0",
}moon run apps/scan -- <target> [options]flowchart TD
A["target string"] --> B{"does this path<br/>exist under cwd?"}
B -- yes --> P["scan as a directory<br/>used as given"]
B -- no --> C{"does it look like a coordinate<br/>author/module@version?"}
C -- no --> P2["error<br/>neither a directory nor a coordinate"]
C -- yes --> D["moon fetch<br/>into .repos/…"]
D --> E{"did it arrive?"}
E -- yes --> P
E -- no --> F["error<br/>cannot fetch …"]usage: scan [<root>] [options]
--lang <csv> languages to scan (default: all)
--rules <path> rule pack directory or rules.json
(default: the rule pack embedded in the artifact)
--source <path>=<txt> scan an inline source; repeatable. A source given
this way needs no filesystem, so it works on every
backend
--format <csv> console,json,junit,sarif,html,markdown
(default: console,markdown; the markdown report is
always written as a FILE, never to stdout)
--out <dir> write reports into dir instead of stdout
--fail-on <severity> critical|high|medium|low|info|never (default: high)
--shard <i>/<n> scan only shard i of n
--ignore <pattern> extra ignore pattern (repeatable)
--max-concurrency <n> per-file concurrency (default: 4)
--incremental reuse per-file results from --cache-dir
--cache-dir <dir> cache location (default: .lunashield-cache)
--fast-cache trust (size, mtime) and skip reading unchanged files
(implies --incremental; opt-in, mtime is not a content proof)
--taint <mode> off|report|strict taint analysis (default: off)
--baseline <path> JSON report from an earlier scan; report only new findingsscan --source 'app.py=eval(user_input)' --format consoleLunaShield 0.3.0
files: 1 scanned, 0 skipped, 1 raw hits
findings: 1 (critical 0, high 1, medium 0, low 0, info 0)
app.py:1:1 PY001 [high] Dynamic code execution via eval()
warnings: 0$ scan riantr/moonbit_markdown@0.1.4 --format console --fail-on never
LunaShield 0.3.0
files: 56 scanned, 17 skipped, 8 raw hits
findings: 2 (critical 0, high 2, medium 0, low 0, info 0)
build_pdf.js:392:36 JS003 [high] DOM XSS via innerHTML assignment
src/mdcli/io_native.mbt:134:13 MB001 [high] Command injection: process.run with untrusted command
warnings: 0$ scan tests/fixtures --format console --fail-on never
LunaShield 0.3.0
files: 252 scanned, 0 skipped, 85 raw hits
findings: 85 (critical 0, high 61, medium 21, low 3, info 0)
C001/positive.c:1:1 C001 [high] Command injection via system()
C002/positive.c:1:1 C002 [high] Format string from external input
... (85 findings, covering 13 languages)
warnings: 9# LunaShield security report - riantr/moonbit_markdown@0.1.4
> Multi-language static application security testing: tree-sitter parsing,
> data-driven rules with CWE and OWASP mapping, and optional taint analysis.
## 1. Acquisition and version pinning
| Item | Value |
| --- | --- |
| Requested target | `riantr/moonbit_markdown@0.1.4` |
| Source root | `.repos/riantr/moonbit_markdown/0.1.4` |
| Rule pack | embedded in the artifact |
| Taint mode | off |
| Analyzer | LunaShield 0.3.0 |{"version":"2.1.0","$schema":"https://json.schemastore.org/sarif-2.1.0.json",
"runs":[{"tool":{"driver":{"name":"LunaShield","version":"0.3.0",
"informationUri":"https://github.com/riantr/LunaShield",
"rules":[{"id":"JS003","shortDescription":{"text":"DOM XSS via innerHTML assignment"}}]}},
"results":[{"ruleId":"JS003","level":"error",
"message":{"text":"DOM XSS via innerHTML assignment"},
"locations":[{"physicalLocation":{"artifactLocation":{"uri":"build_pdf.js"},
"region":{"startLine":392,"startColumn":36,"byteOffset":18052}}}],
"partialFingerprints":{"primaryLocationLineHash":"1907bee0b..."}}]}]}main.mbt root executable package (the one moonx resolves)
moon.mod / moon.pkg module manifest and root package
src/command/ CLI implementation: scan.mbt (argument parsing) / coord.mbt
(coordinate vs path) / args.mbt (argv) / run.mbt (async entry) /
run_sync.mbt (sync entry) / backend.mbt and backend_stub.mbt
(the filesystem layer)
libs/core-model/ shared types: Finding / RawHit / Severity
libs/rule/ the rule model and its parser
libs/config/ configuration and command-line defaults
libs/source-file/ file discovery and reading (text.mbt is pure, read/discover need fs)
libs/lang-registry/ the registry of 13 languages
libs/lang-c/ the C IR / CFG backend
libs/parser/ the tree-sitter wrapper
libs/query-engine/ query compilation and matching
libs/scoring/ severity and scoring
libs/cache/ the incremental cache
libs/taint/ taint analysis
libs/dataflow/ the CFG + worklist engine (not wired into the scan yet)
libs/report/ Console/JSON/JUnit/SARIF/HTML/Markdown
libs/orchestrator/ pipeline orchestration (scan.mbt is the pure core, tree.mbt the
filesystem layer)
libs/daemon/ the resident daemon protocol
apps/scan/ the CLI executable entry
apps/scan-daemon/ the resident daemon executable entry
apps/rules-validate/ the rule pack acceptance tool
grammars/mcil/ the vendored MCIL (C IR) grammar
grammars/moonbit/ the vendored MoonBit tree-sitter binding
grammars/ts/ 11 vendored community tree-sitter grammars (trimmed, patched, with
their upstream licences)
rulepacks/official/ the 84 rules (generated) + the embedded constants + the self-check
tests/fixtures/ 84 rule fixture directories (positive / negative / expected.json)
tests/integration/ integration tests
tests/cram/ CLI end-to-end tests (26 cases)
scripts/ the acceptance gates and the tooling| Step | What it does |
|---|---|
| 1 | resolve dependencies (a best-effort check populates .mooncakes) |
| 2 | apply the grammar compatibility patch (idempotent; the grammars are vendored, this is the backstop) |
| 3 | grammar compatibility gate (fails if any vendored binding is unpatched) |
| 4 | moon check — all four backends |
| 5 | moon test — all four backends |
| 6 | moon fmt --check + the Mermaid syntax of this README's diagrams |
| 7 | rules-validate acceptance (exit codes 0 / 2, with line and column diagnostics) |
| 8 | cram end-to-end (26 cases) |
| 9 | the golden rule pack check (84 rules, detection ≥ 90 %, false positives ≤ 10 %) |
| 10 | the line coverage gate (libs/** aggregate ≥ 90 %, every file ≥ 75 %) |
| 11 | shard equivalence (the merged report is byte-identical to a single run) |
| 12 | the WASM target build (produces scan.wasm) |
| 13 | the C IR regression (MCIL CFG baseline and the IR-only rules) |
| 14 | the resident daemon (cache reuse, determinism, the gate, the baseline, shutdown) |
| Import module | Symbols | Provided by |
|---|---|---|
| moonbitlang/async | 94 | the user's own toolchain, its core |
| __moonbit_fs_unstable | 13 | the user's own toolchain, its core |
| wasi_snapshot_preview1 | 2 | the host runtime's WASI |
moonx riantr/LunaShield@latest riantr/moonbit_markdown@latest# scan a published module; @latest is resolved once and pinned
moon run apps/scan --target native -- riantr/moonbit_markdown@latest
# a local tree, with the Markdown report written next to it
moon run apps/scan --target native -- tests/fixtures --format markdown --out out
# an inline source: no filesystem, so it works on every backend
moon run apps/scan --target wasm-gc -- --source 'app.py=eval(user_input)' --format consolemoonx riantr/LunaShield@latest riantr/LunaShield@latestInstall
Download zipMulti-language static application security testing (SAST) scanner for MoonBit, C/C++, JavaScript/TypeScript, Python, Java, Go, Rust, PHP and more: 84 built-in data-driven rules with CWE/OWASP mapping, taint analysis, console/JSON/JUnit/SARIF/HTML reporting, and a Markdown report with Mermaid diagrams