feat: add security scanner for .rules.ts files#145
Merged
Conversation
Implement a pre-execution AST scanner that blocks dangerous patterns in rule files before they are dynamically imported. Uses Bun.Transpiler to strip TypeScript + meriyah to parse the JS AST + a custom walker to detect banned patterns (~170us per file, 5ms for 26 rules). Blocked patterns: - Dangerous imports: node:fs, child_process, net, http, vm, etc. - Bun APIs: Bun.spawn, Bun.write, Bun.file, Bun.$ - Network: fetch() - Code generation: eval(), new Function() - Obfuscation: Bun[variable], globalThis[variable], import(variable) - Global mutation: globalThis.x = ..., process.env = ... Safe modules allowed: node:path, node:url, node:util, node:crypto. Integration: scanner runs in loader.ts before import(), blocks with logError() per violation and throws on any match. archgate check exits with error if any rule file fails scanning. Includes 45 unit tests for the scanner and 6 integration tests for loader security. Updates security docs (EN + pt-BR) with the new trust model.
Deploying archgate-cli with
|
| Latest commit: |
e960004
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://13e89c16.archgate-cli.pages.dev |
| Branch Preview URL: | https://feat-rule-sandbox-scanner.archgate-cli.pages.dev |
Fix all missing Portuguese diacritical marks in the pt-BR security documentation (segurança, não, código, você, funções, etc.). Update GEN-002 (Documentation Internationalization) ADR to enforce correct diacritical marks in Portuguese translations as a Do/Don't rule, preventing this from recurring.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a pre-execution AST scanner that blocks dangerous patterns in
.rules.tsfiles before they are dynamically imported. This is the static analysis security gate described in the rule sandbox plan.src/engine/rule-scanner.ts) — UsesBun.Transpiler+meriyah(1.5MB, zero deps, pure JS) to parse rule files into an ESTree AST and walk every node checking for banned patternssrc/engine/loader.ts) — Scans each.rules.tsfile beforeimport(). If any violation is found, the file is not imported or executed andarchgate checkexits with an errorBlocked patterns
node:fs,child_process,net,http,vm, etc.)ImportDeclarationsource matchingBun.spawn,Bun.write,Bun.file,Bun.$)MemberExpressionproperty checkfetch()CallExpressioncallee checkeval(),new Function()CallExpression/NewExpressioncheckBun[x],globalThis[x])MemberExpressioncomputed flagimport(variable)ImportExpressionnon-literal sourceglobalThis.x = ...,process.env = ...)AssignmentExpressionleft-hand checkSafe modules allowed:
node:path,node:url,node:util,node:cryptoNew dependency justification
meriyah (7.1.0) — ESTree-compliant JavaScript parser. Added as
devDependency(bundled into compiled binary viabun build --compile). Zero transitive dependencies, 1.5MB. Required because: Bun has no built-in JavaScript AST parser API; oxlint has no embeddable library API; oxc-parser's NAPI bridge is slower for small files (268us vs 167us).Test plan
scanRuleSource()covering all banned patterns, safe modules, TypeScript syntax, multiple violations, and location reportingbun run validatepasses (lint + typecheck + format + 544 tests + 22 ADR checks + build)