@xenos1996/usat 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +335 -0
  3. package/USAT.md +596 -0
  4. package/dist/cli.d.ts +3 -0
  5. package/dist/cli.d.ts.map +1 -0
  6. package/dist/cli.js +438 -0
  7. package/dist/cli.js.map +1 -0
  8. package/dist/config.d.ts +7 -0
  9. package/dist/config.d.ts.map +1 -0
  10. package/dist/config.js +72 -0
  11. package/dist/config.js.map +1 -0
  12. package/dist/detect/index.d.ts +58 -0
  13. package/dist/detect/index.d.ts.map +1 -0
  14. package/dist/detect/index.js +329 -0
  15. package/dist/detect/index.js.map +1 -0
  16. package/dist/engine/audit.d.ts +21 -0
  17. package/dist/engine/audit.d.ts.map +1 -0
  18. package/dist/engine/audit.js +295 -0
  19. package/dist/engine/audit.js.map +1 -0
  20. package/dist/engine/diff.d.ts +24 -0
  21. package/dist/engine/diff.d.ts.map +1 -0
  22. package/dist/engine/diff.js +136 -0
  23. package/dist/engine/diff.js.map +1 -0
  24. package/dist/engine/evaluate.d.ts +19 -0
  25. package/dist/engine/evaluate.d.ts.map +1 -0
  26. package/dist/engine/evaluate.js +377 -0
  27. package/dist/engine/evaluate.js.map +1 -0
  28. package/dist/engine/gate.d.ts +19 -0
  29. package/dist/engine/gate.d.ts.map +1 -0
  30. package/dist/engine/gate.js +47 -0
  31. package/dist/engine/gate.js.map +1 -0
  32. package/dist/engine/loader.d.ts +22 -0
  33. package/dist/engine/loader.d.ts.map +1 -0
  34. package/dist/engine/loader.js +360 -0
  35. package/dist/engine/loader.js.map +1 -0
  36. package/dist/engine/maturity.d.ts +20 -0
  37. package/dist/engine/maturity.d.ts.map +1 -0
  38. package/dist/engine/maturity.js +157 -0
  39. package/dist/engine/maturity.js.map +1 -0
  40. package/dist/engine/score.d.ts +19 -0
  41. package/dist/engine/score.d.ts.map +1 -0
  42. package/dist/engine/score.js +141 -0
  43. package/dist/engine/score.js.map +1 -0
  44. package/dist/engine/sections.d.ts +14 -0
  45. package/dist/engine/sections.d.ts.map +1 -0
  46. package/dist/engine/sections.js +50 -0
  47. package/dist/engine/sections.js.map +1 -0
  48. package/dist/index.d.ts +23 -0
  49. package/dist/index.d.ts.map +1 -0
  50. package/dist/index.js +17 -0
  51. package/dist/index.js.map +1 -0
  52. package/dist/report/markdown.d.ts +16 -0
  53. package/dist/report/markdown.d.ts.map +1 -0
  54. package/dist/report/markdown.js +488 -0
  55. package/dist/report/markdown.js.map +1 -0
  56. package/dist/types.d.ts +282 -0
  57. package/dist/types.d.ts.map +1 -0
  58. package/dist/types.js +16 -0
  59. package/dist/types.js.map +1 -0
  60. package/dist/util/glob.d.ts +11 -0
  61. package/dist/util/glob.d.ts.map +1 -0
  62. package/dist/util/glob.js +86 -0
  63. package/dist/util/glob.js.map +1 -0
  64. package/dist/util/project.d.ts +72 -0
  65. package/dist/util/project.d.ts.map +1 -0
  66. package/dist/util/project.js +586 -0
  67. package/dist/util/project.js.map +1 -0
  68. package/dist/util/yaml.d.ts +28 -0
  69. package/dist/util/yaml.d.ts.map +1 -0
  70. package/dist/util/yaml.js +48 -0
  71. package/dist/util/yaml.js.map +1 -0
  72. package/docs/ARCHITECTURE.md +119 -0
  73. package/docs/README.md +27 -0
  74. package/docs/adr/0001-record-architecture-decisions.md +35 -0
  75. package/docs/adr/0002-typescript-engine-over-python.md +49 -0
  76. package/docs/adr/0003-rules-are-data-not-code.md +50 -0
  77. package/docs/adr/0004-markdown-only-output.md +41 -0
  78. package/docs/adr/0005-maturity-dampens-severity.md +56 -0
  79. package/docs/adr/0006-severity-status-two-axes.md +48 -0
  80. package/docs/adr/0007-suppressions-are-visible-and-expiring.md +46 -0
  81. package/docs/adr/0008-report-trailer-and-diff.md +48 -0
  82. package/docs/adr/0009-fail-closed-on-malformed-input.md +56 -0
  83. package/docs/adr/0010-detector-design.md +54 -0
  84. package/docs/adr/0011-coexist-with-deep-scanners.md +52 -0
  85. package/docs/adr/README.md +32 -0
  86. package/docs/agent-integration.md +129 -0
  87. package/docs/ci-integration.md +163 -0
  88. package/docs/concepts.md +196 -0
  89. package/docs/configuration.md +105 -0
  90. package/docs/detectors.md +186 -0
  91. package/docs/getting-started.md +99 -0
  92. package/docs/maturity-profiles.md +156 -0
  93. package/docs/reference/api.md +193 -0
  94. package/docs/reference/cli.md +412 -0
  95. package/docs/rule-packs.md +278 -0
  96. package/docs/standards-mapping.md +171 -0
  97. package/package.json +96 -0
  98. package/rules/core/architecture.yaml +190 -0
  99. package/rules/core/cicd.yaml +212 -0
  100. package/rules/core/code-quality.yaml +261 -0
  101. package/rules/core/dependencies.yaml +132 -0
  102. package/rules/core/documentation.yaml +119 -0
  103. package/rules/core/future-readiness.yaml +91 -0
  104. package/rules/core/release.yaml +131 -0
  105. package/rules/core/repo.yaml +303 -0
  106. package/rules/core/security.yaml +494 -0
  107. package/rules/core/supply-chain.yaml +357 -0
  108. package/rules/core/testing.yaml +260 -0
  109. package/rules/detectors.yaml +2255 -0
  110. package/rules/index.yaml +41 -0
  111. package/rules/profiles/maturity.yaml +135 -0
  112. package/rules/stacks/ai-era.yaml +193 -0
  113. package/rules/stacks/api-backend.yaml +121 -0
  114. package/rules/stacks/cli.yaml +105 -0
  115. package/rules/stacks/compliance.yaml +157 -0
  116. package/rules/stacks/containers.yaml +124 -0
  117. package/rules/stacks/data.yaml +165 -0
  118. package/rules/stacks/go.yaml +134 -0
  119. package/rules/stacks/iac.yaml +128 -0
  120. package/rules/stacks/jvm.yaml +150 -0
  121. package/rules/stacks/ml-ai.yaml +140 -0
  122. package/rules/stacks/mobile.yaml +121 -0
  123. package/rules/stacks/node-typescript.yaml +166 -0
  124. package/rules/stacks/python.yaml +175 -0
  125. package/rules/stacks/rust.yaml +129 -0
  126. package/rules/stacks/solidity.yaml +139 -0
  127. package/rules/stacks/web-frontend.yaml +159 -0
  128. package/templates/AGENTS.audit.md +135 -0
  129. package/templates/AUDIT_REPORT.md +155 -0
package/USAT.md ADDED
@@ -0,0 +1,596 @@
1
+ # 🧠 USAT β€” Universal Software Audit Template
2
+
3
+ ### _A self-adapting audit framework: any project, any stack, any stage_
4
+
5
+ **USAT is two things at once.**
6
+
7
+ 1. **A prompt/process template** β€” this document. Point any coding agent at a repository and say _"audit this with USAT"_, and it will detect what it is looking at, activate the relevant sections, skip the rest, and produce a severity-tagged report.
8
+ 2. **A deterministic rule engine** β€” `rules/` plus the `usat` CLI. Everything that can be settled by looking at a file is settled by the tool, so the agent spends its budget on the things only judgement can settle.
9
+
10
+ Run both. The tool gives you a reproducible number; the agent gives you the reasoning. Neither is complete alone.
11
+
12
+ ```
13
+ usat audit . # 1. deterministic pass β†’ AUDIT.md
14
+ # then hand AUDIT.md + this file to your agent for the judgement queue
15
+ ```
16
+
17
+ ---
18
+
19
+ ## 0 Β· How the agent uses this template
20
+
21
+ | Step | Action | Output |
22
+ | ---- | --------------------------------------------------------- | ------------------------------ |
23
+ | 1 | Run `usat detect <path>` (or read `rules/detectors.yaml`) | The project's **facts** |
24
+ | 2 | Match facts against `applies_when` in `rules/` | The **applicable rule set** |
25
+ | 3 | Run `usat audit <path>` | Deterministic findings + score |
26
+ | 4 | Work the **Judgement Queue** in the generated report | Evidence-backed findings |
27
+ | 5 | Emit the [Section 14 report](#14--report-output-template) | The deliverable |
28
+
29
+ **Ten behaviour rules.** They are not stylistic; each one prevents a specific failure mode.
30
+
31
+ | # | Rule | Failure it prevents |
32
+ | --- | -------------------------------------------------------------------------------------- | ------------------------------------------------------- |
33
+ | 1 | **Skip non-applicable sections silently.** Do not write "N/A: not a web app" 40 times. | Report bloat that hides the signal. |
34
+ | 2 | **Partially applicable β‡’ audit the applicable parts only.** | Abandoning a section because 3 of 10 checks do not fit. |
35
+ | 3 | **CRITICAL findings always go first**, above every summary and chart. | Burying the one thing that matters. |
36
+ | 4 | **Never mark βœ… GOOD without evidence.** Cite `file:line` or a command output. | Confident-sounding audits that are fiction. |
37
+ | 5 | **Every finding carries: location + severity + why + fix.** | Findings nobody can act on. |
38
+ | 6 | **Score sections 0–10** from the share of applicable checks that pass. | Ungrounded vibes-based scores. |
39
+ | 7 | **Never assume.** A file you did not find is 🚫 MISSING, not "probably fine". | Optimistic audits. |
40
+ | 8 | **Audit what is absent as well as what is present.** | The dangerous gaps are omissions. |
41
+ | 9 | **Always surface ⚠️ WRONG over 🚫 MISSING.** Wrong is worse than absent. | Prioritising the cheaper problem. |
42
+ | 10 | **Priority order: Security > Correctness > Maintainability > Style.** | Perfect formatting over a leaked key. |
43
+
44
+ ---
45
+
46
+ ## The severity model
47
+
48
+ Most checklists conflate two different axes. USAT keeps them separate, which is what makes the scoring reproducible.
49
+
50
+ **Severity β€” how bad, if violated.** Set by the rule, not by the auditor.
51
+
52
+ | Tag | Meaning | Response |
53
+ | ------------- | ------------------------------------------------- | --------------------------- |
54
+ | πŸ”΄ `CRITICAL` | Breaks security, data integrity, or core function | Fix now. Today. |
55
+ | 🟠 `HIGH` | Major risk or substantial debt | Fix before the next release |
56
+ | 🟑 `MEDIUM` | Important gap | Fix in the near-term sprint |
57
+ | 🟒 `LOW` | Minor improvement | Fix when convenient |
58
+ | πŸ”΅ `FUTURE` | Not needed now, needed at scale | Plan it; do not do it |
59
+
60
+ **Status β€” what was actually observed.** Set by the evidence.
61
+
62
+ | Tag | Status | Score credit |
63
+ | ----------------- | ---------------------------------------- | ------------ |
64
+ | βœ… `GOOD` | Verified present and correct | 1.00 |
65
+ | πŸ§ͺ `EXPERIMENTAL` | Present but unvalidated | 0.50 |
66
+ | πŸ’€ `DEPRECATED` | Present but EOL / abandoned | 0.40 |
67
+ | ⚠️ `WRONG` | Present but implemented incorrectly | 0.15 |
68
+ | 🚫 `MISSING` | Required and absent | 0.00 |
69
+ | ❓ `NEEDS REVIEW` | Judgement required, no evidence recorded | _excluded_ |
70
+ | βž– `SKIPPED` | Not applicable to this project | _excluded_ |
71
+
72
+ > ⚠️ WRONG scoring 0.15 and not 0.00 is deliberate: something exists, so there is partial credit β€” but a wrong implementation is more dangerous than nothing, because it looks done.
73
+
74
+ ---
75
+
76
+ ## Maturity profiles β€” the "any stage" part
77
+
78
+ The same repository deserves a different report at different ages. Grading a three-day prototype against a production bar produces a wall of noise nobody reads; grading production with prototype standards produces a false all-clear.
79
+
80
+ USAT detects a lifecycle stage and **dampens** severity accordingly.
81
+
82
+ | Stage | Detected when | Security | Docs/Style | Expected score |
83
+ | ----------------- | --------------------------------------------- | -------- | ---------- | -------------- |
84
+ | 🌱 **Prototype** | Score < 2.5 β€” no tests, no CI, no history | βˆ’1 step | βˆ’2 steps | 30–65 |
85
+ | πŸš€ **MVP** | Score β‰₯ 2.5 β€” some process, real users | βˆ’0 | βˆ’2 steps | 45–75 |
86
+ | πŸ§ͺ **Beta** | Score β‰₯ 5 β€” CI, tests, changelog | βˆ’0 | βˆ’1 step | 60–85 |
87
+ | 🏭 **Production** | Score β‰₯ 7 **and** release tags exist | βˆ’0 | βˆ’0 | 75–95 |
88
+ | 🏚️ **Legacy** | No commits in ~18 months, or stale with no CI | βˆ’0 | βˆ’1 step | 40–70 |
89
+
90
+ > **Hard rule: πŸ”΄ CRITICAL is never dampened, at any stage.**
91
+ > A leaked credential in a weekend prototype is still a leaked credential.
92
+ > Everything else is negotiable with the calendar.
93
+
94
+ Two consequences worth internalising:
95
+
96
+ - A low score on a prototype is **not** an indictment. Check the band, not the number.
97
+ - Use `usat audit . --profile production` to grade against the full bar regardless of detected age. This is the "what would it take to ship this?" view.
98
+
99
+ ---
100
+
101
+ ## Sections
102
+
103
+ Sections are activated by detection, not by the auditor's attention span. `S15 Β· Platform-Specific` is where every stack pack lands.
104
+
105
+ | # | Section | Activated when | Weight |
106
+ | ------- | ------------------------------------- | -------------------------------------------------------------------------------------------- | ------- |
107
+ | **S1** | Repository & Project Structure | always | 0.7 |
108
+ | **S2** | Security | always | **1.7** |
109
+ | **S3** | Supply Chain & Build Provenance | always | 1.3 |
110
+ | **S4** | Architecture & Design | always | 1.0 |
111
+ | **S5** | Code Quality | always | 1.0 |
112
+ | **S6** | Data & Database | database / ORM / migrations detected | 1.0 |
113
+ | **S7** | Testing & Quality Assurance | always | **1.3** |
114
+ | **S8** | CI/CD, Infrastructure & Observability | always | 1.0 |
115
+ | **S9** | Release & Change Management | always | 0.7 |
116
+ | **S10** | Dependencies & Third-Party | always | 1.2 |
117
+ | **S11** | Performance & Resilience | always | 0.8 |
118
+ | **S12** | Documentation & Knowledge | always | 0.7 |
119
+ | **S13** | Accessibility, i18n & Compliance | β‰₯ MVP | 0.9 |
120
+ | **S14** | **AI / LLM-Era Risks** | LLM SDK, agents, MCP, RAG, or prompts detected | 1.1 |
121
+ | **S15** | Platform-Specific | per stack: Node, Python, Go, Rust, JVM, Web, Mobile, Containers, IaC, Solidity, ML, CLI, API | 1.0 |
122
+ | **S16** | Future Readiness | always | 0.4 |
123
+
124
+ The machine-readable version of every section lives in [`rules/core/`](rules/core), [`rules/stacks/`](rules/stacks), and [`rules/sections.yaml`](rules/sections.yaml).
125
+
126
+ ### What USAT added to the classic 14-section audit
127
+
128
+ The original checklist this project grew from covered sections S1–S13 well. Four additions:
129
+
130
+ - **S3 Supply Chain & Build Provenance** was four bullets under "Dependency Security". It is now a full section: SLSA provenance, workflow script-injection, token permissions, action pinning, SBOM. You can write flawless code and still ship someone else's backdoor.
131
+ - **S9 Release & Change Management** β€” versioning, tags, migration ordering, feature flags, runbooks. The gap between "we deploy" and "we ship".
132
+ - **S14 AI / LLM-Era Risks** β€” mapped to OWASP Top 10 for LLM Applications (2026) and OWASP Top 10 for Agentic AI (ASI, 2026): prompt injection, excessive agency, unbounded consumption, RAG tenant leakage, memory/context poisoning.
133
+ - **Maturity profiles** and **approved-risk suppressions**, so the report is honest about stage and about decisions that were made deliberately.
134
+
135
+ ---
136
+
137
+ ## 1 Β· Repository & Project Structure
138
+
139
+ ### 1.1 Root hygiene
140
+
141
+ - [ ] Is the folder structure logical, consistent, and predictable?
142
+ - [ ] Are concerns separated (`/src`, `/tests`, `/docs`, `/scripts`, `/config`)?
143
+ - [ ] Is there unnecessary nesting β€” or flat chaos?
144
+ - [ ] Are there orphan files: unused, forgotten, `foo-v2-final-FINAL.ts`?
145
+ - [ ] Is the project root clean of build artifacts?
146
+
147
+ ### 1.2 Essential files
148
+
149
+ | File | Severity if missing | Note |
150
+ | ------------------------- | ------------------- | ------------------------------------- |
151
+ | `.gitignore` | πŸ”΄ `CRITICAL` | Everything else is downstream of this |
152
+ | `README.md` | 🟠 `HIGH` | The front door |
153
+ | `LICENSE` | 🟠 `HIGH` | No license β‡’ all rights reserved |
154
+ | `SECURITY.md` | 🟠 `HIGH` | Disclosure route for researchers |
155
+ | `.env.example` | 🟠 `HIGH` | Only when config is actually required |
156
+ | `CHANGELOG.md` | 🟑 `MEDIUM` | What changed, and will it break me? |
157
+ | `CONTRIBUTING.md` | 🟒 `LOW` | Turns questions into links |
158
+ | `CODE_OF_CONDUCT.md` | 🟒 `LOW` | |
159
+ | `.editorconfig` | 🟒 `LOW` | Kills whitespace diffs |
160
+ | `AGENTS.md` / `CLAUDE.md` | 🟒 `LOW` | Agents follow it literally β€” see S14 |
161
+
162
+ ### 1.3 Version control quality
163
+
164
+ - [ ] πŸ”΄ Are secrets or `.env` files in the repository?
165
+ - [ ] πŸ”΄ Are secrets present in **git history**? (Deleting from HEAD does not remove them.)
166
+ - [ ] Are commit messages meaningful and consistent?
167
+ - [ ] Is there a branching strategy, and are stale branches pruned?
168
+ - [ ] Are large binaries committed? (Use LFS or object storage.)
169
+ - [ ] Is the default branch protected? (Required review, required checks, no force-push.)
170
+
171
+ ---
172
+
173
+ ## 2 Β· Security
174
+
175
+ > Applicable to every project type. Severity is never dampened below CRITICAL here.
176
+
177
+ ### 2.1 Secrets & credentials
178
+
179
+ - [ ] πŸ”΄ No API keys, passwords, or tokens hardcoded in source
180
+ - [ ] πŸ”΄ No `.env`, `*.pem`, `*.key`, or credential files committed
181
+ - [ ] πŸ”΄ No secrets in git history (`gitleaks detect --log-opts=--all`)
182
+ - [ ] Environment variables validated at startup
183
+ - [ ] A secret manager is used in production
184
+
185
+ ### 2.2 Authentication & authorization
186
+
187
+ - [ ] Authentication matches the project type
188
+ - [ ] **Authorization is enforced per resource, not per route** (IDOR is the most common auth bug and no linter finds it)
189
+ - [ ] Tokens are short-lived; refresh with rotation and revocation
190
+ - [ ] Sessions invalidated on logout and password change
191
+ - [ ] Failed logins rate-limited and eventually locked out
192
+ - [ ] MFA available where the risk warrants it
193
+
194
+ ### 2.3 Input validation & output encoding
195
+
196
+ - [ ] πŸ”΄ All input validated server-side β€” client validation is a UX feature
197
+ - [ ] πŸ”΄ SQL/NoSQL/command injection prevented (parameterise everything)
198
+ - [ ] πŸ”΄ XSS prevented β€” no `dangerouslySetInnerHTML` / `innerHTML` / `v-html` on untrusted data
199
+ - [ ] πŸ”΄ CSRF protection for cookie-based sessions
200
+ - [ ] Uploads validated by allowlist, size, and content sniffing
201
+ - [ ] Path traversal prevented on every filesystem call
202
+
203
+ ### 2.4 Data protection
204
+
205
+ - [ ] Sensitive data encrypted at rest
206
+ - [ ] TLS enforced β€” no plaintext HTTP to real hosts, TLS verification never disabled
207
+ - [ ] Passwords hashed with bcrypt/scrypt/argon2id β€” never a plain digest
208
+ - [ ] PII inventoried, encrypted, and retention-scheduled
209
+ - [ ] Secrets and PII redacted from logs and telemetry
210
+
211
+ ### 2.5 API security
212
+
213
+ - [ ] Every endpoint authenticated by default; allowlist the public ones
214
+ - [ ] Rate limiting on auth and on expensive endpoints
215
+ - [ ] API versioned
216
+ - [ ] CORS restricted to named origins β€” never `*`
217
+ - [ ] GraphQL depth/complexity limits; introspection off in production
218
+
219
+ ### 2.6 Platform-specific controls
220
+
221
+ | Platform | Controls |
222
+ | --------------- | ----------------------------------------------------------------------------------------------------- |
223
+ | **Web** | CSP, HSTS, `X-Content-Type-Options`, `Referrer-Policy`, `Permissions-Policy` |
224
+ | **Mobile** | Certificate/ATS config, Keychain & Keystore, jailbreak/root signals, privacy manifests |
225
+ | **Cloud / IaC** | IAM least privilege, no public buckets, no `0.0.0.0/0`, encryption at rest, remote state with locking |
226
+ | **Blockchain** | Reentrancy (CEI), access control, `tx.origin`, unchecked external calls, pause mechanism |
227
+ | **Containers** | Non-root user, minimal pinned base, no baked secrets, healthchecks, resource limits |
228
+ | **Desktop** | Auto-update signature verification, local data encryption |
229
+
230
+ ---
231
+
232
+ ## 3 Β· Supply Chain & Build Provenance
233
+
234
+ > Aligned with **SLSA v1.2**, **NIST SSDF (SP 800-218)**, and the **OpenSSF Scorecard**.
235
+
236
+ - [ ] A lockfile is committed **and** CI installs with it frozen (`npm ci`, `--frozen-lockfile`, `--locked`)
237
+ - [ ] Dependency versions pinned β€” no `*` or `latest`
238
+ - [ ] Automated dependency updates (Dependabot / Renovate)
239
+ - [ ] Dependency vulnerability scanning in CI
240
+ - [ ] SAST in CI (CodeQL / Semgrep)
241
+ - [ ] Secret scanning in CI _and_ as a pre-commit hook
242
+ - [ ] πŸ”΄ No secrets in CI configuration
243
+ - [ ] πŸ”΄ Workflows free of script injection β€” never interpolate `github.event.*` into `run:`
244
+ - [ ] Least-privilege `permissions:` declared per workflow
245
+ - [ ] Third-party actions pinned to a SHA or version, never `@main`
246
+ - [ ] Default branch protected (β‰₯1 review, dismiss stale approvals, checks required)
247
+ - [ ] SBOM published with releases (CycloneDX / SPDX)
248
+ - [ ] Release artifacts carry provenance attestation (SLSA Build L2+)
249
+ - [ ] Container images scanned and signed
250
+
251
+ ---
252
+
253
+ ## 4 Β· Architecture & Design
254
+
255
+ - [ ] Architecture documented (one page: components, data flow, external dependencies)
256
+ - [ ] Architecture decisions recorded as ADRs
257
+ - [ ] Pattern appropriate to scale β€” monolith, modular monolith, services, serverless, event-driven
258
+ - [ ] No god files (>800 lines) and no god objects
259
+ - [ ] Layers separated: transport β†’ domain β†’ data
260
+ - [ ] No circular dependencies between modules
261
+ - [ ] Boundaries enforced by tooling, not by memory
262
+ - [ ] Configuration externalised β€” no hardcoded production URLs
263
+ - [ ] Side effects isolated and injectable
264
+ - [ ] Single points of failure identified, with a mitigation or an accepted risk
265
+ - [ ] Async work offloaded to a queue
266
+
267
+ ---
268
+
269
+ ## 5 Β· Code Quality
270
+
271
+ - [ ] Linter configured **and** run in CI
272
+ - [ ] Formatter configured
273
+ - [ ] Type checking enabled and strict
274
+ - [ ] Type escapes (`any`, `@ts-ignore`) used sparingly, with cause
275
+ - [ ] πŸ”΄ No empty catch / bare except β€” errors are handled, not swallowed
276
+ - [ ] A central error handler or error boundary exists
277
+ - [ ] Errors returned to clients are generic + correlation ID, never stack traces
278
+ - [ ] Logging is structured and levelled; every request carries a trace/correlation ID
279
+ - [ ] No debug statements in production paths
280
+ - [ ] `TODO`/`FIXME` linked to tracked issues, or deleted
281
+ - [ ] Complexity measured (cyclomatic/cognitive) β€” at least reported
282
+
283
+ **Language anti-patterns**
284
+
285
+ | Stack | Look for |
286
+ | --------------- | ----------------------------------------------------------------------------------------- |
287
+ | JavaScript / TS | `var`, callback hell, unhandled rejections, `any` sprawl, mixed ESM/CJS |
288
+ | Python | Mutable default args, bare `except`, `shell=True`, `pickle.load`, `DEBUG=True` |
289
+ | Go | Discarded errors, missing context, `panic` in handlers, goroutine leaks, no HTTP timeouts |
290
+ | Rust | `unwrap()` in prod paths, unjustified `unsafe`, `todo!()` |
291
+ | Java / Kotlin | `printStackTrace`, empty catch, concatenated JPQL, `!!`, insecure deserialisation |
292
+ | Solidity | `tx.origin` auth, unchecked calls, timestamp dependence, missing access control |
293
+
294
+ ---
295
+
296
+ ## 6 Β· Data & Database
297
+
298
+ - [ ] A migration system exists; no manual production schema edits
299
+ - [ ] Foreign keys and constraints enforced **at the DB level**
300
+ - [ ] Indexes on every foreign key and every large-table query path
301
+ - [ ] πŸ”΄ No N+1 query patterns on list endpoints
302
+ - [ ] All list queries paginated, with a maximum page size
303
+ - [ ] Connection pooling configured
304
+ - [ ] Multi-step writes wrapped in transactions
305
+ - [ ] Row-level / tenant scoping enforced in the data layer, not by remembering a `WHERE`
306
+ - [ ] Migrations separated from application deploys; destructive changes use expand/contract
307
+ - [ ] Delete strategy (hard vs soft) defined, consistent with retention and erasure duties
308
+
309
+ ---
310
+
311
+ ## 7 Β· Testing & Quality Assurance
312
+
313
+ | Type | Present | Target |
314
+ | ----------- | ------- | ------------------------------------------ |
315
+ | Unit | βœ… / 🚫 | 80%+ on new code |
316
+ | Integration | βœ… / 🚫 | Every external seam |
317
+ | End-to-end | βœ… / 🚫 | The 3 critical journeys |
318
+ | Security | βœ… / 🚫 | Every permission boundary (negative tests) |
319
+ | Performance | βœ… / 🚫 | Critical paths |
320
+ | Mutation | βœ… / 🚫 | πŸ”΅ FUTURE |
321
+
322
+ - [ ] Tests run in CI on every PR and block merge
323
+ - [ ] Coverage measured; thresholds set at today's number and ratcheted
324
+ - [ ] Tests are independent β€” pass in random order, twice in a row
325
+ - [ ] No test depends on wall-clock time, network, or global state
326
+ - [ ] Fixtures/factories rather than hand-built literals in every test
327
+ - [ ] Flaky tests quarantined, then fixed within a sprint
328
+ - [ ] Mocks used at boundaries, not to make the code under test disappear
329
+
330
+ ---
331
+
332
+ ## 8 Β· CI/CD, Infrastructure & Observability
333
+
334
+ - [ ] CI runs lint β†’ typecheck β†’ test β†’ build β†’ scan
335
+ - [ ] Separate environments; dev cannot reach production data
336
+ - [ ] Deployment automated from a tag or main-branch push
337
+ - [ ] Rollback is one command, and has been rehearsed
338
+ - [ ] Infrastructure defined as code
339
+ - [ ] πŸ”΄ Backups exist **and** a restore has actually been performed
340
+ - [ ] Disaster recovery plan with RTO/RPO and a named owner
341
+ - [ ] Health (`/health`) and readiness (`/ready`) endpoints wired to the orchestrator
342
+ - [ ] Error tracking (Sentry et al.) with release/source-map tracking
343
+ - [ ] Alerting on symptoms users feel β€” error rate, latency, saturation
344
+ - [ ] Golden signals on one dashboard, linked from the runbook
345
+
346
+ ---
347
+
348
+ ## 9 Β· Release & Change Management
349
+
350
+ - [ ] Semantic versioning, applied consistently
351
+ - [ ] Every release tagged; deploys reference the tag
352
+ - [ ] Release notes published (generated + a hand-written breaking-changes section)
353
+ - [ ] Risky changes behind feature flags with a kill switch
354
+ - [ ] Migrations ordered: expand β†’ backfill β†’ switch β†’ contract
355
+ - [ ] A runbook exists per service: health, restart, rollback, escalate, owner
356
+
357
+ ---
358
+
359
+ ## 10 Β· Dependencies & Third-Party
360
+
361
+ - [ ] πŸ”΄ No known HIGH/CRITICAL CVEs in the dependency graph
362
+ - [ ] πŸ’€ No dependency unmaintained for 24+ months without a decision
363
+ - [ ] No unused or redundant dependencies (two HTTP clients = two CVE surfaces)
364
+ - [ ] Licenses inventoried; copyleft reviewed before shipping
365
+ - [ ] External services have explicit timeouts, bounded retries, and a fallback
366
+ - [ ] Webhook payloads signature-verified before processing
367
+ - [ ] Peer dependencies compatible with the runtime version
368
+
369
+ ---
370
+
371
+ ## 11 Β· Performance & Resilience
372
+
373
+ - [ ] Profiling data for the critical paths
374
+ - [ ] Expensive operations cached, with an invalidation story
375
+ - [ ] Background jobs on a queue with retries and a dead-letter queue
376
+ - [ ] No blocking I/O inside async contexts
377
+ - [ ] Slow queries identified and explained
378
+ - [ ] Load tests run before releases; p95/p99 recorded
379
+ - [ ] Auto-scaling configured
380
+ - [ ] CDN/edge caching for static assets
381
+ - [ ] Rate limits protect against traffic spikes
382
+ - [ ] Retries bounded with jitter; circuit breakers on failing dependencies
383
+
384
+ ---
385
+
386
+ ## 12 Β· Documentation & Knowledge
387
+
388
+ - [ ] README has: what it is Β· how to install Β· how to run Β· how to contribute
389
+ - [ ] Setup instructions verified recently (a clean-machine clone-and-run)
390
+ - [ ] Public APIs documented (OpenAPI / typedoc, generated in CI)
391
+ - [ ] Complex logic explained with **why**, not what
392
+ - [ ] Docs live in the repo, next to the code
393
+ - [ ] Onboarding page for new contributors
394
+ - [ ] Doc examples executed in CI (πŸ”΅ FUTURE)
395
+
396
+ ---
397
+
398
+ ## 13 Β· Accessibility, i18n & Compliance
399
+
400
+ - [ ] WCAG 2.2 AA: keyboard reachable, visible focus, labelled inputs, contrast β‰₯4.5:1
401
+ - [ ] Screen reader tested on the main flow
402
+ - [ ] Error messages descriptive and linked to their inputs (`aria-describedby`)
403
+ - [ ] Strings externalised, not hardcoded
404
+ - [ ] Dates/numbers/currencies formatted with `Intl`, stored in UTC
405
+ - [ ] Privacy policy and terms match what the code actually does
406
+ - [ ] Data subject rights implemented: access, export, erasure, correction
407
+ - [ ] Card data kept out of scope via tokenisation (PCI-DSS)
408
+ - [ ] Cookie consent is opt-in and as easy to refuse as to accept
409
+ - [ ] SPDX license identifiers on source files
410
+
411
+ ---
412
+
413
+ ## 14 Β· AI / LLM-Era Risks
414
+
415
+ > New in USAT. Mapped to **OWASP Top 10 for LLM Applications (2026)** and
416
+ > **OWASP Top 10 for Agentic AI β€” ASI (2026)**.
417
+
418
+ | Ref | Risk | Check |
419
+ | --------------------- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
420
+ | LLM01 / ASI01 | **Prompt injection** | Untrusted content (retrieved docs, web pages, tickets) is separated from instructions by role; never feeds a privileged tool call directly |
421
+ | LLM02 | **Sensitive information disclosure** | No credentials or PII in prompts; redaction before send; no-training/no-retention terms |
422
+ | LLM03 / ASI02, ASI03 | **Excessive agency** | Tool allowlist, per-tool credentials, sandboxed FS/network, human approval for irreversible actions |
423
+ | LLM04 / ASI04 | **Supply chain** | Model versions and digests pinned; prompts versioned in git; MCP servers reviewed as production dependencies |
424
+ | LLM05 / ASI06 | **Data & model poisoning / memory poisoning** | Ingestion is validated; agent memory is scoped and inspectable |
425
+ | LLM06 / ASI08 | **Unbounded consumption** | Max tokens, timeouts, retry caps, step limits, per-user spend ceilings |
426
+ | LLM07 | **Misinformation** | Outputs grounded or labelled; eval suite covers the failure cases |
427
+ | LLM08 | **Hidden context exposure** | System prompts and tool schemas are not reachable by end users or error paths |
428
+ | LLM09 | **Vector & embedding weaknesses** | Retrieval is filtered by tenant/ACL at query time, not after generation |
429
+ | LLM10 / ASI05 | **Improper output handling** | Model output parsed into a constrained schema and validated before reaching a shell, SQL, or the DOM |
430
+ | ASI07 / ASI09 / ASI10 | **Inter-agent trust, rogue agents** | Agent identities are distinct and least-privileged; inter-agent messages authenticated; logging covers who did what |
431
+
432
+ Also: **`AGENTS.md` / `CLAUDE.md` are executable-ish instructions.** They commit as easily as code and agents follow them literally. They should carry an explicit denylist (no force-push, no `rm -rf`, no reading `.env`) plus the exact build/test commands to use.
433
+
434
+ ---
435
+
436
+ ## 15 Β· Platform-Specific Playbooks
437
+
438
+ Activated by detection. Each lives in [`rules/stacks/`](rules/stacks).
439
+
440
+ | Pack | Activates on | Highlights |
441
+ | ----------------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
442
+ | `node-typescript` | `lang:typescript` / `lang:javascript` / `package.json` | Runtime pinning, strict mode, unhandled rejections, npmrc tokens, deprecated APIs, env validation |
443
+ | `python` | `lang:python` | Manifests, pinned versions, bare `except`, mutable defaults, `pickle`, `shell=True`, `DEBUG=True` |
444
+ | `go` | `lang:go` | Error checking, context propagation, panic-free handlers, `go vet`/lint, goroutine lifecycle, parameterised SQL, HTTP timeouts |
445
+ | `rust` | `lang:rust` | Edition, `unwrap`, `unsafe` justification, clippy, `todo!`, cargo-audit/deny, release profiles |
446
+ | `jvm` | `lang:java` / `kotlin` / `scala` | Central version management, config secrets, `printStackTrace`, JPQL injection, nullability, SpotBugs/detekt, container memory |
447
+ | `web-frontend` | React / Vue / Svelte / Angular / Next / Nuxt | Core Web Vitals, code splitting, image optimisation, a11y, bundle budget, error boundaries, secrets in bundles |
448
+ | `mobile` | iOS / Android / RN / Expo / Flutter | Crash reporting, bundle secrets, Keychain/Keystore, ATS/cleartext, permissions, privacy manifests, device matrix |
449
+ | `containers` | Dockerfile / compose | Non-root, multi-stage, pinned base, `.dockerignore`, no baked secrets, healthchecks, K8s limits, image signing |
450
+ | `iac` | Terraform / K8s / Pulumi | Public exposure, encryption at rest, validate+scan in CI, remote locked state, least-privilege IAM, no privileged pods |
451
+ | `solidity` | `.sol` / Foundry / Hardhat | Reentrancy, compiler β‰₯0.8, access control, `tx.origin`, unchecked calls, timestamp dependence, pause, invariants, audit |
452
+ | `ml-ai` | torch / notebooks / models | Data & model versioning, reproducibility, drift monitoring, prediction logging, bias evaluation, notebook-to-pipeline, cost |
453
+ | `cli` | `bin` / `[project.scripts]` / `cmd/` | `--help`, exit codes, `--dry-run`, input validation, idempotency, stderr/stdout, `--json` |
454
+ | `data` | database / ORM / migrations | Migrations, constraints, indexes, N+1, pagination, pooling, transactions, row-level scoping |
455
+ | `api-backend` | server / API | Versioning, timeouts, retry policy, idempotency keys, response envelopes, OpenAPI, GraphQL limits |
456
+ | `compliance` | β‰₯ MVP | Keyboard/labels/contrast, i18n, locale formatting, privacy policy, data subject rights, PCI scope, cookie consent, SPDX |
457
+ | `ai-era` | LLM SDK / agents / MCP / RAG / prompts | The full table in Β§14, as enforceable rules |
458
+
459
+ ---
460
+
461
+ ## 16 Β· Future Readiness
462
+
463
+ All πŸ”΅ `FUTURE` β€” these are plans, not defects, and they never block a release.
464
+
465
+ - [ ] A path off the current architecture is written down (limits, trigger, direction)
466
+ - [ ] No core technology at or near EOL
467
+ - [ ] Data archiving/retention strategy exists
468
+ - [ ] Multi-region or failover is designed β€” or explicitly declined with a stated RTO
469
+ - [ ] A tech radar exists (adopt / trial / assess / hold) if the team is >4 people
470
+ - [ ] Cost is tagged, budgeted, and alerted on
471
+
472
+ ---
473
+
474
+ ## 14 Β· Report Output Template
475
+
476
+ > The `usat` CLI emits exactly this structure. If you are an agent writing it by hand, match it β€” a report that looks the same every time is a report you can diff.
477
+
478
+ ```
479
+ ══════════════════════════════════════════════════════════
480
+ UNIVERSAL SOFTWARE AUDIT REPORT
481
+ ══════════════════════════════════════════════════════════
482
+ Project : [name]
483
+ Repository : [url]
484
+ Commit : [sha] ([ref])
485
+ Audited by : USAT [version] + [agent/human]
486
+ Date : [ISO-8601]
487
+ Detected type: [auto] Stack: [auto]
488
+ Platform : [auto] Maturity: [auto-detected stage]
489
+ Depth : [quick | standard | deep]
490
+
491
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
492
+ EXECUTIVE SUMMARY
493
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
494
+ Overall Health Score : [X/100]
495
+ Expected band for [maturity]: [lo]–[hi] β†’ [verdict]
496
+
497
+ Dimension Score Confidence
498
+ S1 Repository & Structure X/10 N%
499
+ S2 Security X/10 N%
500
+ S3 Supply Chain X/10 N%
501
+ ... (one row per applicable section)
502
+
503
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
504
+ FINDINGS SUMMARY
505
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
506
+ πŸ”΄ CRITICAL : N βœ… GOOD : N
507
+ 🟠 HIGH : N ⚠️ WRONG : N
508
+ 🟑 MEDIUM : N 🚫 MISSING : N
509
+ 🟒 LOW : N πŸ’€ DEPRECATED : N
510
+ πŸ”΅ FUTURE : N ❓ TO REVIEW : N
511
+
512
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
513
+ IMMEDIATE ACTION REQUIRED
514
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
515
+ 1. πŸ”΄ [Finding] β†’ [file:line] β†’ [fix]
516
+ 2. 🟠 [Finding] β†’ [file:line] β†’ [fix]
517
+
518
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
519
+ SECTION-BY-SECTION FINDINGS
520
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
521
+ [S1] Repository & Structure β†’ X/10 β†’ [findings]
522
+ [S2] Security β†’ X/10 β†’ [findings]
523
+ ...
524
+
525
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
526
+ JUDGEMENT QUEUE
527
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
528
+ | Rule | Section | Severity | What to look for | Evidence to record |
529
+ | SEC-015 | S2 | 🟠 HIGH | Authorization per resource | file:line of the ownership check |
530
+
531
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
532
+ ACCEPTED RISK
533
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
534
+ [Suppressed findings, each with a reason and an expiry]
535
+
536
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
537
+ RECOMMENDED ROADMAP
538
+ ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
539
+ SPRINT 0 (now) : CRITICAL + security HIGH
540
+ SPRINT 1 (1–2 wk) : remaining HIGH
541
+ SPRINT 2 (1 month) : MEDIUM
542
+ BACKLOG : LOW + FUTURE
543
+ DEFERRED (this stage): what the maturity profile says to ignore
544
+
545
+ ══════════════════════════════════════════════════════════
546
+ ```
547
+
548
+ Every generated report also embeds a machine-readable trailer, so
549
+ `usat diff previous.md current.md` turns the next audit into a progress report.
550
+
551
+ ---
552
+
553
+ ## Scoring
554
+
555
+ Deterministic and reproducible β€” the same tree, rules, and depth always produce the same number.
556
+
557
+ ```
558
+ creditα΅’ = weightα΅’ Γ— CREDIT[statusα΅’] Γ— sectionWeight(sectionα΅’)
559
+ overall = 100 Γ— Ξ£ creditα΅’ / Ξ£ (weightα΅’ Γ— sectionWeightα΅’)
560
+
561
+ section = 10 Γ— Ξ£(weightα΅’ Γ— CREDIT[statusα΅’]) / Ξ£ weightα΅’
562
+ ```
563
+
564
+ - Rule-level weighting (not an average of section scores) means a section with three rules cannot swing the total as hard as one with thirty.
565
+ - Default weights follow severity: `CRITICAL 10 Β· HIGH 6 Β· MEDIUM 3 Β· LOW 1.5 Β· FUTURE 0.5`.
566
+ - Sections with **zero** resolvable rules are reported as _not verified_ and excluded from the total β€” you cannot earn points for questions nobody answered.
567
+ - **Confidence** = resolved Γ· applicable. A 90/100 at 40% confidence is a report that found nothing wrong with a fifth of the surface.
568
+
569
+ ---
570
+
571
+ ## Using USAT as an agent skill
572
+
573
+ ```
574
+ skills/usat-audit/SKILL.md # drop into ~/.claude/skills, .cursor/skills, …
575
+ templates/AGENTS.audit.md # paste into a target repo as AGENTS.md
576
+ ```
577
+
578
+ Both follow the Agent Skills convention (YAML frontmatter + `references/`), so the same pack works in Claude Code, Cursor, Codex, Copilot, and Gemini CLI.
579
+
580
+ ---
581
+
582
+ ## What USAT is not
583
+
584
+ Stated plainly, because an audit tool that oversells itself is worse than none:
585
+
586
+ - **Not a penetration test.** No dynamic analysis, no fuzzing, no exploit chain. It finds open doors; it does not walk through them.
587
+ - **Not a replacement for CodeQL / Semgrep / Snyk / Trivy.** It checks whether those tools are _configured_, and tells you to run them.
588
+ - **Not a compliance certification.** It maps to ASVS, SSDF, SLSA, WCAG, and GDPR, and tells you what evidence you would need. An auditor still has to certify.
589
+ - **Not a code review.** It does not understand your product. A senior engineer reading a diff still catches things no rule pack will.
590
+ - **Not a guarantee.** A 95/100 means the observable hygiene is good. It does not mean there is no bug.
591
+
592
+ ---
593
+
594
+ ## Licence
595
+
596
+ MIT. Use it, fork it, ship it in a product, add rule packs and send them back.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export declare function main(argv: string[]): number;
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAoFA,wBAAgB,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,CAkC3C"}