himaya 0.0.0-stage → 0.1.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 (195) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/LICENSE +201 -0
  3. package/PRIVACY.md +64 -0
  4. package/README.md +283 -2
  5. package/SECURITY.md +29 -0
  6. package/agent/AGENTS.section.md +11 -0
  7. package/agent/skill/SKILL.md +118 -0
  8. package/dist/ci/codeowners.js +62 -0
  9. package/dist/ci/reviews.js +62 -0
  10. package/dist/ci/run.js +347 -0
  11. package/dist/ci/workflow.js +150 -0
  12. package/dist/cli/answer.js +77 -0
  13. package/dist/cli/args.js +53 -0
  14. package/dist/cli/ci.js +77 -0
  15. package/dist/cli/diff.js +21 -0
  16. package/dist/cli/explain.js +62 -0
  17. package/dist/cli/feedback.js +59 -0
  18. package/dist/cli/fix.js +184 -0
  19. package/dist/cli/history.js +36 -0
  20. package/dist/cli/hunt.js +116 -0
  21. package/dist/cli/index.js +36 -0
  22. package/dist/cli/init.js +36 -0
  23. package/dist/cli/main.js +243 -0
  24. package/dist/cli/promise.js +100 -0
  25. package/dist/cli/shield.js +93 -0
  26. package/dist/cli/threats.js +129 -0
  27. package/dist/cli/tripwire.js +94 -0
  28. package/dist/cli/watch.js +77 -0
  29. package/dist/copy/checks.js +422 -0
  30. package/dist/copy/ci.js +65 -0
  31. package/dist/copy/data.js +68 -0
  32. package/dist/copy/feedback.js +36 -0
  33. package/dist/copy/fix-steps.js +229 -0
  34. package/dist/copy/fixes.js +64 -0
  35. package/dist/copy/guard.js +20 -0
  36. package/dist/copy/init.js +92 -0
  37. package/dist/copy/mcp.js +34 -0
  38. package/dist/copy/platforms.js +93 -0
  39. package/dist/copy/promises.js +108 -0
  40. package/dist/copy/report.js +81 -0
  41. package/dist/copy/shields.js +68 -0
  42. package/dist/copy/threats.js +231 -0
  43. package/dist/copy/watch.js +69 -0
  44. package/dist/data/index.js +25 -0
  45. package/dist/data/known-bad-packages.json +56 -0
  46. package/dist/data/popular-packages.json +712 -0
  47. package/dist/data/shields/GHSA-f82v-jwr5-mffw.json +25 -0
  48. package/dist/data/shields.js +22 -0
  49. package/dist/data/tripwire-decoys.json +37 -0
  50. package/dist/diff/accessmap.js +202 -0
  51. package/dist/diff/compare.js +107 -0
  52. package/dist/diff/render.js +38 -0
  53. package/dist/diff/run.js +124 -0
  54. package/dist/diff/snapshot.js +163 -0
  55. package/dist/engine/basis.js +26 -0
  56. package/dist/engine/checks-list.js +234 -0
  57. package/dist/engine/code.js +400 -0
  58. package/dist/engine/configs.js +130 -0
  59. package/dist/engine/context.js +1 -0
  60. package/dist/engine/discover.js +212 -0
  61. package/dist/engine/files.js +151 -0
  62. package/dist/engine/finding.js +10 -0
  63. package/dist/engine/git-branch.js +212 -0
  64. package/dist/engine/git.js +160 -0
  65. package/dist/engine/gitignore.js +156 -0
  66. package/dist/engine/hash.js +7 -0
  67. package/dist/engine/himaya-guards.js +50 -0
  68. package/dist/engine/invisible.js +187 -0
  69. package/dist/engine/links.js +18 -0
  70. package/dist/engine/lockfile.js +75 -0
  71. package/dist/engine/make-finding.js +37 -0
  72. package/dist/engine/mask.js +68 -0
  73. package/dist/engine/package-names.js +143 -0
  74. package/dist/engine/packs.js +1 -0
  75. package/dist/engine/pg-worker.js +112 -0
  76. package/dist/engine/pool.js +16 -0
  77. package/dist/engine/profile.js +340 -0
  78. package/dist/engine/project.js +283 -0
  79. package/dist/engine/rank.js +185 -0
  80. package/dist/engine/safe-db.js +307 -0
  81. package/dist/engine/scan.js +412 -0
  82. package/dist/engine/schema.js +317 -0
  83. package/dist/engine/secret-formats.js +133 -0
  84. package/dist/engine/secrets-names.js +71 -0
  85. package/dist/engine/shipped.js +14 -0
  86. package/dist/engine/specifiers.js +27 -0
  87. package/dist/engine/sql-split.js +87 -0
  88. package/dist/engine/supabase-shim.js +111 -0
  89. package/dist/engine/text.js +19 -0
  90. package/dist/engine/tripwire-lures.js +15 -0
  91. package/dist/engine/versions.js +103 -0
  92. package/dist/fixes/code-access.js +944 -0
  93. package/dist/fixes/code-ai.js +1094 -0
  94. package/dist/fixes/code-common.js +145 -0
  95. package/dist/fixes/code-edit.js +164 -0
  96. package/dist/fixes/code-pay.js +933 -0
  97. package/dist/fixes/data.js +779 -0
  98. package/dist/fixes/diff.js +166 -0
  99. package/dist/fixes/registry.js +13 -0
  100. package/dist/fixes/secrets.js +32 -0
  101. package/dist/fixes/static.js +1159 -0
  102. package/dist/guard/bash.js +252 -0
  103. package/dist/guard/index.js +158 -0
  104. package/dist/guard/install.js +17 -0
  105. package/dist/guard/redlines.js +345 -0
  106. package/dist/guard/rules.js +18 -0
  107. package/dist/guard/stop.js +194 -0
  108. package/dist/history/git.js +40 -0
  109. package/dist/history/replay.js +403 -0
  110. package/dist/history/report.js +146 -0
  111. package/dist/history/since.js +36 -0
  112. package/dist/hunt/candidates.js +119 -0
  113. package/dist/hunt/merge.js +290 -0
  114. package/dist/hunt/surfaces.js +129 -0
  115. package/dist/init/init.js +456 -0
  116. package/dist/mcp/server.js +230 -0
  117. package/dist/net/registry.js +116 -0
  118. package/dist/packs/core/checks/agent.js +831 -0
  119. package/dist/packs/core/checks/ai.js +1219 -0
  120. package/dist/packs/core/checks/deps.js +455 -0
  121. package/dist/packs/core/checks/hard08.js +258 -0
  122. package/dist/packs/core/checks/hard09.js +192 -0
  123. package/dist/packs/core/checks/sec02.js +337 -0
  124. package/dist/packs/core/pack.js +16 -0
  125. package/dist/packs/index.js +15 -0
  126. package/dist/packs/nextjs/auth.js +312 -0
  127. package/dist/packs/nextjs/checks/access.js +612 -0
  128. package/dist/packs/nextjs/checks/hard.js +783 -0
  129. package/dist/packs/nextjs/checks/inj01.js +774 -0
  130. package/dist/packs/nextjs/checks/sec01.js +254 -0
  131. package/dist/packs/nextjs/pack.js +13 -0
  132. package/dist/packs/payments/checks.js +678 -0
  133. package/dist/packs/razorpay/pack.js +10 -0
  134. package/dist/packs/stripe/pack.js +11 -0
  135. package/dist/packs/supabase/checks/data.js +1213 -0
  136. package/dist/packs/supabase/checks/sec03.js +94 -0
  137. package/dist/packs/supabase/pack.js +11 -0
  138. package/dist/packs/supabase/sql.js +269 -0
  139. package/dist/packs/vite/pack.js +18 -0
  140. package/dist/promises/changes.js +187 -0
  141. package/dist/promises/check.js +253 -0
  142. package/dist/promises/code.js +159 -0
  143. package/dist/promises/db.js +921 -0
  144. package/dist/promises/readback.js +58 -0
  145. package/dist/promises/schema.js +277 -0
  146. package/dist/promises/world.js +395 -0
  147. package/dist/proofs/code.js +118 -0
  148. package/dist/proofs/db.js +248 -0
  149. package/dist/proofs/engine.js +235 -0
  150. package/dist/proofs/file.js +129 -0
  151. package/dist/proofs/harness/mocks.js +573 -0
  152. package/dist/proofs/harness/run.js +316 -0
  153. package/dist/proofs/promise-test.js +99 -0
  154. package/dist/proofs/promise.js +122 -0
  155. package/dist/proofs/runtime.js +50 -0
  156. package/dist/proofs/together.js +131 -0
  157. package/dist/proofs/tree.js +77 -0
  158. package/dist/proofs/types.js +2 -0
  159. package/dist/report/gate.js +63 -0
  160. package/dist/report/json.js +64 -0
  161. package/dist/report/sarif.js +165 -0
  162. package/dist/report/terminal.js +182 -0
  163. package/dist/report/threats.js +134 -0
  164. package/dist/rules/security-rules.js +52 -0
  165. package/dist/shields/manager.js +762 -0
  166. package/dist/shields/record.js +45 -0
  167. package/dist/shields/schema.js +212 -0
  168. package/dist/shields/templates/app.js +197 -0
  169. package/dist/threats/evaluate.js +107 -0
  170. package/dist/threats/tracks.js +108 -0
  171. package/dist/threats/tracks.yaml +281 -0
  172. package/dist/tripwires/manager.js +415 -0
  173. package/dist/tripwires/routes.js +47 -0
  174. package/dist/tripwires/templates/app.js +140 -0
  175. package/dist/universal/budget.js +44 -0
  176. package/dist/universal/commands.js +169 -0
  177. package/dist/universal/datastores.js +30 -0
  178. package/dist/universal/egress.js +209 -0
  179. package/dist/universal/entrypoints.js +568 -0
  180. package/dist/universal/gate.js +331 -0
  181. package/dist/universal/manifests.js +89 -0
  182. package/dist/universal/map.js +202 -0
  183. package/dist/universal/merge.js +118 -0
  184. package/dist/universal/parsers.js +60 -0
  185. package/dist/universal/roles.js +110 -0
  186. package/dist/universal/run.js +291 -0
  187. package/dist/universal/runner.js +113 -0
  188. package/dist/universal/schemas.js +149 -0
  189. package/dist/universal/serve.js +61 -0
  190. package/dist/universal/settings.js +96 -0
  191. package/dist/universal/workspace.js +67 -0
  192. package/dist/version.js +2 -0
  193. package/dist/watch/manager.js +816 -0
  194. package/dist/watch/templates/app.js +407 -0
  195. package/package.json +55 -4
@@ -0,0 +1,337 @@
1
+ import { makeFinding, repoExposure } from "../../../engine/make-finding.js";
2
+ import { trackedFiles } from "../../../engine/git.js";
3
+ import { findSecrets, isPlaceholder } from "../../../engine/secret-formats.js";
4
+ import { secretKind, touchesFor } from "../../../engine/secrets-names.js";
5
+ import { registeredLures } from "../../../engine/tripwire-lures.js";
6
+ import { parseEnvFile } from "../../../universal/settings.js";
7
+ import { isRecord, parseConfig } from "../../../engine/configs.js";
8
+ import { sha256 } from "../../../engine/hash.js";
9
+ import { maskValue } from "../../../engine/mask.js";
10
+ import { copyFor, SEC02_TEXT } from "../../../copy/checks.js";
11
+ const ENV_FILE = /(^|\/)\.env(\.[^/]+)?$/;
12
+ const ENV_TEMPLATE = /\.(example|sample|template|dist)$/;
13
+ const AGENT_CONFIG = /(^|\/)(\.mcp\.json|\.cursor\/mcp\.json|\.vscode\/mcp\.json|\.amazonq\/mcp\.json|\.claude\/settings(\.local)?\.json|\.windsurf\/[^/]+\.json|\.gemini\/[^/]+\.json)$/;
14
+ const TEST_DIRS = /(^|\/)(fixtures|__tests__|test|tests)\//;
15
+ /** Files never worth reading for secrets: lockfiles, images, media, archives, fonts, binaries. */
16
+ const SKIP = /(^|\/)(package-lock\.json|pnpm-lock\.yaml|yarn\.lock|bun\.lockb?|Cargo\.lock|poetry\.lock|go\.sum)$|\.(png|jpe?g|gif|webp|ico|svg|mp[34]|mov|webm|wav|pdf|zip|gz|tgz|tar|7z|woff2?|ttf|otf|eot|wasm|so|dylib|dll|exe|bin|class|jar|map)$/i;
17
+ const SECRETISH_KEY = /(token|secret|password|passwd|api[_-]?key|access[_-]?key|private[_-]?key|authorization)/i;
18
+ const ARG_TOKEN = /(?:^|\s)--?(?:token|api[-_]?key|key|secret|password|access[-_]?token)(?:=|\s+)([^\s"']{12,})/i;
19
+ const URL_TOKEN = /[?&](?:token|key|apikey|api_key|access_token|secret)=([^&\s"']{12,})/i;
20
+ const lineOf = (text, index) => text.slice(0, index).split("\n").length;
21
+ /** A value that looks like a credential, not a setting ("oauth2", "true", "prod"). */
22
+ function credentialLike(value) {
23
+ const v = value.replace(/^Bearer\s+/i, "").trim();
24
+ return (!isPlaceholder(v) && v.length >= 16 && /[A-Za-z]/.test(v) && /[0-9]/.test(v) && !/\s/.test(v));
25
+ }
26
+ /** Secret-looking values in an agent config: env/headers entries, tokens in args, tokens in URLs. */
27
+ function configSecrets(value, out, inBlock = false, depth = 0) {
28
+ if (depth > 20)
29
+ return;
30
+ if (typeof value === "string") {
31
+ const fromArg = ARG_TOKEN.exec(value)?.[1] ?? URL_TOKEN.exec(value)?.[1];
32
+ if (fromArg && credentialLike(fromArg))
33
+ out.push({ key: "args", value: fromArg });
34
+ return;
35
+ }
36
+ if (Array.isArray(value)) {
37
+ const list = value;
38
+ list.forEach((v, i) => {
39
+ // ["--token", "abc..."]
40
+ const prev = list[i - 1];
41
+ if (typeof v === "string" &&
42
+ typeof prev === "string" &&
43
+ /^--?(token|api[-_]?key|key|secret|password)$/i.test(prev) &&
44
+ credentialLike(v)) {
45
+ out.push({ key: prev.replace(/^-+/, ""), value: v });
46
+ }
47
+ else
48
+ configSecrets(v, out, inBlock, depth + 1);
49
+ });
50
+ return;
51
+ }
52
+ if (!isRecord(value))
53
+ return;
54
+ for (const [k, v] of Object.entries(value)) {
55
+ const block = inBlock || /^(env|headers|environment)$/i.test(k);
56
+ if (typeof v === "string" && block && SECRETISH_KEY.test(k) && credentialLike(v))
57
+ out.push({ key: k, value: v });
58
+ else
59
+ configSecrets(v, out, block, depth + 1);
60
+ }
61
+ }
62
+ /** Passwords that ship as defaults or examples with local databases. */
63
+ const DEFAULT_PASSWORDS = new Set([
64
+ "",
65
+ "postgres",
66
+ "postgrespassword",
67
+ "password",
68
+ "pass",
69
+ "admin",
70
+ "root",
71
+ "secret",
72
+ "mysecretpassword",
73
+ "changeme",
74
+ "change_me",
75
+ "test",
76
+ "example",
77
+ "dev",
78
+ "local",
79
+ "docker",
80
+ "mysql",
81
+ "user",
82
+ "default",
83
+ "123456",
84
+ "12345678",
85
+ ]);
86
+ /** Defaults and placeholders only: never "any short password" (isPlaceholder's length rule). */
87
+ function defaultPassword(password, user) {
88
+ const p = password.toLowerCase();
89
+ return (DEFAULT_PASSWORDS.has(p) ||
90
+ p === user.toLowerCase() ||
91
+ /^(change|replace|your|example|placeholder|dummy|sample|xxx)/i.test(p));
92
+ }
93
+ /**
94
+ * A database connection string whose only host is this machine (localhost, a loopback address) or
95
+ * a local container name (one label, no dots, such as "db"), with a default or placeholder
96
+ * password, and nothing in its query that names another host or password.
97
+ */
98
+ export function localDefaultDatabase(value) {
99
+ const m = /^[a-z][a-z0-9+.-]*:\/\/([^:@/\s]+):([^@/\s]*)@([^/?#\s]+)(\/[^?#\s]*)?(\?[^#\s]*)?$/i.exec(value.trim());
100
+ if (!m)
101
+ return false;
102
+ const [, user = "", rawPassword = "", hostPort = "", , query = ""] = m;
103
+ // Several hosts, or a host or password in the query, can point somewhere else.
104
+ if (hostPort.includes(",") || /[?&](host|hostaddr|password|sslpassword)=/i.test(query))
105
+ return false;
106
+ const host = hostPort.replace(/:\d+$/, "");
107
+ let password;
108
+ try {
109
+ password = decodeURIComponent(rawPassword);
110
+ }
111
+ catch {
112
+ // A malformed % escape: not a value Himaya can judge, so it stays a finding.
113
+ return false;
114
+ }
115
+ const local = /^(localhost|127(\.\d{1,3}){3}|0\.0\.0\.0|\[::1\]|host\.docker\.internal)$/i.test(host) ||
116
+ /^[a-z][a-z0-9_-]*$/i.test(host);
117
+ return local && defaultPassword(password, user);
118
+ }
119
+ /** Names that hold a credential, whatever Himaya's name list says about them. */
120
+ const CREDENTIAL_NAME = /KEY|TOKEN|SECRET|PASS|PWD|AUTH|CRED/i;
121
+ /**
122
+ * The whole .env file, comments included, holds nothing but local default databases: every
123
+ * connection string with a password is one, and every value named like a credential is empty or
124
+ * a placeholder. Production and staging files never qualify.
125
+ */
126
+ export function onlyLocalDefaults(path, text) {
127
+ if (/\.env\.(prod|production|staging|stage)\b/i.test(path))
128
+ return false;
129
+ for (const m of text.matchAll(/[a-z][a-z0-9+.-]*:\/\/[^\s"'`]*@[^\s"'`#]*/gi))
130
+ if (!localDefaultDatabase(m[0]))
131
+ return false;
132
+ for (const line of text.split("\n")) {
133
+ const kv = /^\s*#?\s*(export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/.exec(line);
134
+ if (!kv)
135
+ continue;
136
+ const name = kv[2] ?? "";
137
+ const value = (kv[3] ?? "").trim().replace(/^["']|["']$/g, "");
138
+ if (!value || !CREDENTIAL_NAME.test(name) || /:\/\//.test(value))
139
+ continue;
140
+ if (!isPlaceholder(value) || value.length < 6) {
141
+ if (!defaultPassword(value, ""))
142
+ return false;
143
+ }
144
+ }
145
+ return true;
146
+ }
147
+ /** A compose file that publishes a database port to the host makes a "local" database reachable. */
148
+ function publishesDatabasePort(ctx) {
149
+ return ctx.files.some((f) => /(^|\/)(docker-)?compose[^/]*\.ya?ml$/i.test(f.path) &&
150
+ /["'\s-](\d{1,3}(\.\d{1,3}){3}:)?(5432|3306|27017|6379|1433|5433):(5432|3306|27017|6379|1433|5433)\b/.test(ctx.read(f) ?? ""));
151
+ }
152
+ /** Documentation files: a key written in a guide or a README is there to be read, not used. */
153
+ const DOC_FILE = /\.(md|mdx|markdown|rst|adoc)$/i;
154
+ /** A top-level examples folder. Deeper `examples/` or `samples/` folders can be live routes. */
155
+ const EXAMPLE_PATH = /^(examples?|samples?)\//i;
156
+ /** .env-style files: a value there is configuration, wherever the file sits. */
157
+ const ENV_STYLE = /(^|\/)\.env([.\-_][^/]*)?$|(^|\/)[^/]*\.env$/i;
158
+ /** Code where a comment line can hold an example value. Not .env or config files. */
159
+ const CODE_FILE = /\.(m?[jt]sx?|cjs|py|rb|go|rs|java|kt|php|cs|swift|sql|sh)$/i;
160
+ /** Keys published in providers' own documentation. Only these exact values count. */
161
+ const DOC_EXAMPLE_KEYS = [
162
+ "AKIAIOSFODNN7EXAMPLE",
163
+ "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
164
+ "sk_test_4eC39HqLyjWDarjtT1zdp7dc",
165
+ "pk_test_TYooMQauvdEDq54NiTphI7jx",
166
+ ];
167
+ /** The shortest body any real private key can have (an Ed25519 key is 64 characters). */
168
+ const SHORTEST_KEY_BODY = 40;
169
+ /**
170
+ * Why a value found as a secret can't be a live key, if it can't: it sits in documentation or a
171
+ * top-level examples folder; its own line in code is a comment that calls it an example before
172
+ * the value; it's a provider's published documentation key; or it's cut short (a private key with
173
+ * no end, or one whose body is elided or too short for any key; a value followed by "..."). A
174
+ * real-shaped key on an ordinary line of code, config or .env is live, and a .env-style file is
175
+ * never excused by where it sits.
176
+ */
177
+ export function notLiveReason(path, text, value, line) {
178
+ const envStyle = ENV_STYLE.test(path);
179
+ if (!envStyle && DOC_FILE.test(path))
180
+ return SEC02_TEXT.notLive.docs;
181
+ if (!envStyle && EXAMPLE_PATH.test(path))
182
+ return SEC02_TEXT.notLive.examples;
183
+ if (DOC_EXAMPLE_KEYS.some((k) => value.includes(k) && !/[A-Za-z0-9+/]{16,}/.test(value.replace(k, ""))))
184
+ return SEC02_TEXT.notLive.knownExample;
185
+ const own = text.split("\n")[line - 1] ?? "";
186
+ const inOwn = own.indexOf(value);
187
+ if (!envStyle &&
188
+ CODE_FILE.test(path) &&
189
+ /^\s*(\/\/|#|\*|\/\*|--)/.test(own) &&
190
+ /(\be\.g\.|\beg[.,:]|\bfor example\b|\bexample\b|\bfor instance\b)/i.test(inOwn >= 0 ? own.slice(0, inOwn) : ""))
191
+ return SEC02_TEXT.notLive.exampleComment;
192
+ if (inOwn >= 0) {
193
+ const after = own.slice(inOwn + value.length, inOwn + value.length + 3);
194
+ if (/^(\.\.\.|…)/.test(after))
195
+ return SEC02_TEXT.notLive.truncated;
196
+ }
197
+ if (/\.\.\.|…/.test(value))
198
+ return SEC02_TEXT.notLive.truncated;
199
+ if (/-----BEGIN [A-Z ]*PRIVATE KEY-----/.test(value)) {
200
+ const lineStart = text
201
+ .split("\n")
202
+ .slice(0, line - 1)
203
+ .join("\n").length;
204
+ const at = text.indexOf(value, lineStart);
205
+ if (at >= 0) {
206
+ const rest = text.slice(at, at + 20_000);
207
+ const end = /-----END [A-Z ]*PRIVATE KEY-----/.exec(rest);
208
+ const raw = (end ? rest.slice(0, end.index) : rest).replace(/-----BEGIN [A-Z ]*PRIVATE KEY-----/, "");
209
+ const body = raw.replace(/\\n|[^A-Za-z0-9+/=]/g, "");
210
+ if (!end || /\.\.\.|…/.test(raw) || body.length < SHORTEST_KEY_BODY)
211
+ return SEC02_TEXT.notLive.truncated;
212
+ }
213
+ }
214
+ return null;
215
+ }
216
+ export const sec02 = {
217
+ id: "SEC-02",
218
+ run(ctx) {
219
+ const tracked = trackedFiles(ctx.root);
220
+ if (!tracked)
221
+ ctx.notes.push({
222
+ kind: "no-git",
223
+ message: "Not a git repository: SEC-02 treated every file that isn't gitignored as committed.",
224
+ });
225
+ const lureHashes = new Set(registeredLures(ctx).map((l) => l.valueHash));
226
+ const committed = ctx.files.filter((f) => (tracked ? tracked.has(f.path) : !f.gitignored) && !SKIP.test(f.path));
227
+ const out = [];
228
+ const c = copyFor("SEC-02");
229
+ for (const f of committed) {
230
+ const text = ctx.read(f);
231
+ if (text === null)
232
+ continue;
233
+ const hits = [];
234
+ const add = (h) => {
235
+ if (!lureHashes.has(sha256(h.value)) && !hits.some((x) => x.line === h.line))
236
+ hits.push(h);
237
+ };
238
+ const lines = text.split("\n");
239
+ const template = ENV_TEMPLATE.test(f.path);
240
+ if (ENV_FILE.test(f.path) && !template) {
241
+ for (const [name, value] of parseEnvFile(text)) {
242
+ const kind = secretKind(name);
243
+ const v = value.trim().replace(/^["']|["']$/g, "");
244
+ if (!kind || isPlaceholder(v))
245
+ continue;
246
+ if (kind === "database" && !/:\/\/[^:/\s]+:[^@/\s]+@/.test(v))
247
+ continue;
248
+ const line = lines.findIndex((l) => new RegExp(`^\\s*(export\\s+)?${name}\\s*=`).test(l)) + 1;
249
+ add({
250
+ line: line || 1,
251
+ label: tracked
252
+ ? `${name} in a committed ${f.path.split("/").pop() ?? ".env"} file`
253
+ : name,
254
+ touches: touchesFor(kind),
255
+ value: v,
256
+ });
257
+ }
258
+ }
259
+ // Known formats anywhere, templates included: a real key in .env.example is still a leak.
260
+ for (const s of findSecrets(text, f.path)) {
261
+ if (TEST_DIRS.test(f.path) && /_test_|test[-_]?key/i.test(s.value))
262
+ continue;
263
+ add({ line: lineOf(text, s.index), label: s.label, touches: s.touches, value: s.value });
264
+ }
265
+ if (AGENT_CONFIG.test(f.path)) {
266
+ const parsed = parseConfig(f.path, text);
267
+ const found = [];
268
+ if (parsed.ok)
269
+ configSecrets(parsed.value, found);
270
+ for (const s of found) {
271
+ const line = lines.findIndex((l) => l.includes(s.value)) + 1;
272
+ add({
273
+ line: line || 1,
274
+ label: `a token in the "${s.key}" setting of an agent or MCP config`,
275
+ touches: ["developer-machine"],
276
+ value: s.value,
277
+ });
278
+ }
279
+ }
280
+ if (!hits.length)
281
+ continue;
282
+ ctx.knownSecrets.push(...hits.map((h) => h.value));
283
+ const first = hits[0];
284
+ if (!first)
285
+ continue;
286
+ const touches = [...new Set(hits.flatMap((h) => h.touches))];
287
+ const labels = [...new Set(hits.map((h) => h.label))];
288
+ // Outside git, a .env file is where settings belong: nothing is committed. Still noted,
289
+ // because the folder may become a repository later.
290
+ const envOutsideGit = !tracked && ENV_FILE.test(f.path) && !template;
291
+ // Every secret in the file is a database on this machine or a local container, with a
292
+ // default or placeholder password: a fact worth a look, not a leaked credential. Any other
293
+ // real key, or a database anywhere else, keeps the file in Fix now.
294
+ // Every value found can't be a live key: worth a look, with why.
295
+ const notLive = hits.map((h) => notLiveReason(f.path, text, h.value, h.line));
296
+ const cantBeLive = notLive.every((x) => x !== null) ? (notLive[0] ?? null) : null;
297
+ const localOnly = ENV_FILE.test(f.path) &&
298
+ hits.every((h) => localDefaultDatabase(h.value)) &&
299
+ onlyLocalDefaults(f.path, text) &&
300
+ !publishesDatabasePort(ctx);
301
+ const what = hits.length === 1
302
+ ? `${f.path} contains ${first.label}.`
303
+ : `${f.path} contains ${hits.length} secrets (${labels.slice(0, 3).join(", ")}).`;
304
+ out.push(makeFinding(ctx, {
305
+ checkId: "SEC-02",
306
+ pack: "core",
307
+ tracks: ["TT-02", "TT-03", "TT-04"],
308
+ file: f.path,
309
+ line: first.line,
310
+ anchor: "secrets",
311
+ title: c.says(""),
312
+ explanation: envOutsideGit ? SEC02_TEXT.envOutsideGit(what) : c.explain(what),
313
+ // Never the raw line: only what was found and a masked value.
314
+ evidence: `${first.label}: ${maskValue(first.value)}`,
315
+ exposure: repoExposure(ctx),
316
+ touches,
317
+ confidence: tracked ? "certain" : "likely",
318
+ ...(envOutsideGit
319
+ ? { severity: "low", severityReason: SEC02_TEXT.envOutsideGitWhy }
320
+ : cantBeLive
321
+ ? {
322
+ severity: "high",
323
+ severityReason: cantBeLive,
324
+ worthALookBecause: cantBeLive,
325
+ }
326
+ : localOnly
327
+ ? {
328
+ severity: "high",
329
+ severityReason: SEC02_TEXT.localDefaultWhy,
330
+ worthALookBecause: SEC02_TEXT.localDefaultWhy,
331
+ }
332
+ : { humanStep: c.humanStep?.("") ?? "" }),
333
+ }));
334
+ }
335
+ return out;
336
+ },
337
+ };
@@ -0,0 +1,16 @@
1
+ import { sec02 } from "./checks/sec02.js";
2
+ import { hard08 } from "./checks/hard08.js";
3
+ import { hard09 } from "./checks/hard09.js";
4
+ import { AI_CHECKS } from "./checks/ai.js";
5
+ import { AGENT_CHECKS } from "./checks/agent.js";
6
+ import { DEPS_CHECKS } from "./checks/deps.js";
7
+ /** Stack-independent checks: SEC-02, HARD-08, HARD-09, AI, AGENT and DEPS. Always runs. */
8
+ export const corePack = {
9
+ id: "core",
10
+ version: "0.1.0",
11
+ label: "Core",
12
+ appliesTo: () => true,
13
+ skipReason: "",
14
+ checks: [sec02, hard08, hard09, ...AI_CHECKS, ...AGENT_CHECKS, ...DEPS_CHECKS],
15
+ tracks: ["TT-01", "TT-02", "TT-03", "TT-04", "TT-05", "TT-06"],
16
+ };
@@ -0,0 +1,15 @@
1
+ import { corePack } from "./core/pack.js";
2
+ import { nextjsPack } from "./nextjs/pack.js";
3
+ import { vitePack } from "./vite/pack.js";
4
+ import { supabasePack } from "./supabase/pack.js";
5
+ import { razorpayPack } from "./razorpay/pack.js";
6
+ import { stripePack } from "./stripe/pack.js";
7
+ /** Built-in packs, in the order they run. v0.1 never loads third-party packs (TT-04). */
8
+ export const PACKS = [
9
+ corePack,
10
+ nextjsPack,
11
+ vitePack,
12
+ supabasePack,
13
+ razorpayPack,
14
+ stripePack,
15
+ ];