AI App Production Auditor
Offline AST-powered TypeScript CLI inspecting web apps for configuration drift, leaked secrets, insecure CORS/TLS, and AI scaffolding traps before deployment.
01. Problem & Context
Web applications scaffolded rapidly with AI coding assistants frequently look complete locally while hiding hardcoded localhost URLs, undeclared environment variables, committed `.env` secrets, `dangerouslyAllowBrowser: true` SDK calls, or raw SQL string interpolation that fail or leak credentials in production.
02. Engineering Solution
Engineered a zero-execution, 100% offline TypeScript static-analysis CLI (`ai-app-production-auditor`) backed by `ts.createSourceFile` AST parsing and structured regex fallbacks for `.env`, JSON, YAML, TOML, and Dockerfiles. Evaluates 22 rule IDs across 5 severity levels, emits Terminal, Markdown, JSON, and OASIS SARIF v2.1.0 reports, supports inline suppressions and custom `defineRule` plugins, and provides safe mechanical `--fix` remediation.
03. System Architecture
A bounded, non-executing filesystem crawler (5,000-file and 1 MB per-file defaults, zero symlink traversal, binary null-byte skip) feeds memoized `ts.createSourceFile` ASTs and config parsers across 22 modular rules, emitting redacted findings through Terminal, GFM Markdown, JSON (`schemaVersion: 1.0.0`), and SARIF v2.1.0 serializers.
Core Architectural Components
TypeScript Compiler AST Engine (`ts.createSourceFile`)
Parses `.ts`/`.tsx`/`.mts`/`.cts`/`.js`/`.jsx`/`.mjs`/`.cjs` into memoized ASTs so comments/JSDoc never trigger false positives, catching destructured `process.env`, `import.meta.env`, localhost templates, and `NEXT_PUBLIC_*`/`VITE_*` secret prefixes.
22-Rule Security, Config, Quality & AI Guardrail Catalog
Covers `PRJ001`, `URL001`, `ENV001`–`002`, `TST001`–`002`, `BLD001`–`003`, `SEC001`–`003` (embedded secrets, `.env` files, `eval`/`vm`), `CFG001`–`007` (TLS bypass, Docker root, raw SQL interpolation, insecure CORS), and `AI001`–`003` (`dangerouslyAllowBrowser`, unsanitized stream HTML, unimplemented stubs).
Safe Mechanical `--fix` & Custom `defineRule` SDK
Supports opt-in mechanical remediation for `.env.example`, `.gitignore`, and lockfile-pinned wildcards alongside `.auditorrc.json`, inline `auditor-disable-next-line` comments, and typed `defineRule` custom rules.
Redacted Multi-Format & SARIF v2.1.0 Reporting
Outputs ANSI terminal reports, PR-ready Markdown, JSON, and OASIS SARIF v2.1.0 for GitHub Code Scanning while masking all detected credentials (`AKIA****...****PLE`) and enforcing deterministic exit codes `0`–`3`.
04. Notable Engineering Decisions
Compiler AST Analysis Over Naive Regex Scanning
Naive regexes flag comments (`// http://localhost:3000`) and domain object keys (`rejectUnauthorized`). Using `ts.createSourceFile` AST inspection eliminates comment noise and validates network/client context.
100% Offline, Non-Executing Architecture with Secret Redaction
Auditing untrusted or AI-generated repos must never `eval` or `import` target files, make outbound network calls, follow symlinks outside the root, or print raw secrets in CI logs.
OASIS SARIF v2.1.0 & Exit-Code Contract for CI Gates
Integrating directly with `github/codeql-action/upload-sarif@v3` and predictable exit codes (`0`–`3`) makes production-readiness checks enforceable in any PR workflow.
05. Engineering Challenges & Solutions
Challenge: Eliminating false positives from documentation snippets and unrelated configuration objects without missing real leaks.
Engineering Solution: Memoized TypeScript AST nodes per file so executable expressions are inspected precisely, falling back to structured pattern matching only on non-script formats.
Challenge: Providing automated fixes without risking broken application logic or corrupted source files.
Engineering Solution: Restricted `--fix` strictly to safe mechanical repairs (`.env.example` keys, `.gitignore` entries, and `package-lock.json`-pinned wildcards) while leaving code unmodified by default.
06. Implementation Highlights
- AST-powered static analysis via `ts.createSourceFile` with zero code execution and zero network telemetry
- 22 diagnostic rules spanning secrets (`SEC001`–`003`), config/CORS/SQLi/Docker (`CFG001`–`007`), env parity (`ENV001`–`002`), and AI pitfalls (`AI001`–`003`)
- Terminal, GFM Markdown, JSON, and OASIS SARIF v2.1.0 reporters with automatic secret redaction
- Safe mechanical `--fix`, inline comment suppressions, `.auditorrc.json`, and typed `defineRule` extension API
- Symlink/path-traversal defense, binary skipping, 5,000-file/1 MB limits, and predictable CI exit codes (`0`–`3`)
- Verified across 20 Vitest files (111 passing tests) and Node 20.x/22.x GitHub Actions CI