hullproof 0.0.0-stage → 0.5.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 (363) hide show
  1. package/LICENSE +222 -0
  2. package/NOTICE +32 -0
  3. package/README.md +313 -2
  4. package/checks/db.firebase-rules-not-open.json +24 -0
  5. package/checks/db.rls-every-table.json +25 -0
  6. package/checks/log.no-credential-in-logs.json +30 -0
  7. package/checks/secrets.no-env-file-committed.json +31 -0
  8. package/checks/secrets.no-secret-in-public-env.json +37 -0
  9. package/checks/storage.firebase-rules-not-open.json +22 -0
  10. package/checks/supply.no-untrusted-event-in-run.json +23 -0
  11. package/checks/web.cors-no-reflected-origin.json +31 -0
  12. package/detectors/ai.json +25 -0
  13. package/detectors/auth.json +27 -0
  14. package/detectors/ci.json +19 -0
  15. package/detectors/containers.json +8 -0
  16. package/detectors/data_stores.json +38 -0
  17. package/detectors/frameworks.json +94 -0
  18. package/detectors/hosting.json +44 -0
  19. package/detectors/iac.json +43 -0
  20. package/detectors/languages.json +48 -0
  21. package/detectors/mobile.json +22 -0
  22. package/detectors/package_managers.json +39 -0
  23. package/detectors/payments.json +19 -0
  24. package/detectors/runtimes.json +17 -0
  25. package/dist/checks/code/admin-role.js +46 -0
  26. package/dist/checks/code/owner-filter.js +91 -0
  27. package/dist/checks/code/shared.js +84 -0
  28. package/dist/checks/code/webhook-verify.js +77 -0
  29. package/dist/checks/context.js +64 -0
  30. package/dist/checks/map/config-checks.js +74 -0
  31. package/dist/checks/map/entry-checks.js +97 -0
  32. package/dist/checks/map/shared.js +44 -0
  33. package/dist/checks/ops.js +307 -0
  34. package/dist/checks/pro-map.js +1 -0
  35. package/dist/checks/run.js +92 -0
  36. package/dist/checks/types.js +1 -0
  37. package/dist/ci/comment.js +44 -0
  38. package/dist/ci/sarif-check.js +157 -0
  39. package/dist/ci/sarif.js +61 -0
  40. package/dist/cli.js +358 -0
  41. package/dist/commands/ci.js +115 -0
  42. package/dist/commands/git.js +58 -0
  43. package/dist/commands/hooks.js +30 -0
  44. package/dist/commands/hunt-pro.js +1 -0
  45. package/dist/commands/hunt.js +86 -0
  46. package/dist/commands/map.js +33 -0
  47. package/dist/commands/mcp.js +17 -0
  48. package/dist/commands/pack.js +48 -0
  49. package/dist/commands/prove-pro.js +1 -0
  50. package/dist/commands/prove.js +173 -0
  51. package/dist/commands/report-gate.js +92 -0
  52. package/dist/commands/scan.js +158 -0
  53. package/dist/confirm/agreement.js +18 -0
  54. package/dist/confirm/chain.js +84 -0
  55. package/dist/confirm/confirm.js +112 -0
  56. package/dist/confirm/honesty.js +75 -0
  57. package/dist/confirm/lead.js +92 -0
  58. package/dist/confirm/merge.js +88 -0
  59. package/dist/confirm/query.js +145 -0
  60. package/dist/confirm/rule.js +86 -0
  61. package/dist/confirm/store.js +42 -0
  62. package/dist/confirm/summary.js +6 -0
  63. package/dist/confirm/synthesis.js +28 -0
  64. package/dist/discover/detectors.js +50 -0
  65. package/dist/discover/discover.js +270 -0
  66. package/dist/discover/extract.js +282 -0
  67. package/dist/discover/git.js +40 -0
  68. package/dist/discover/kit-files.js +47 -0
  69. package/dist/discover/walk.js +110 -0
  70. package/dist/env.js +57 -0
  71. package/dist/gate/gate.js +173 -0
  72. package/dist/hooks/install.js +153 -0
  73. package/dist/hooks/run.js +112 -0
  74. package/dist/map/analyze.js +201 -0
  75. package/dist/map/build.js +253 -0
  76. package/dist/map/candidates.js +49 -0
  77. package/dist/map/cblocks.js +77 -0
  78. package/dist/map/config.js +291 -0
  79. package/dist/map/dotnet.js +242 -0
  80. package/dist/map/entry.js +78 -0
  81. package/dist/map/expo.js +190 -0
  82. package/dist/map/go.js +292 -0
  83. package/dist/map/js-express.js +143 -0
  84. package/dist/map/js-misc.js +295 -0
  85. package/dist/map/js-next.js +292 -0
  86. package/dist/map/laravel.js +389 -0
  87. package/dist/map/lex-more.js +305 -0
  88. package/dist/map/lex.js +425 -0
  89. package/dist/map/light-index.js +191 -0
  90. package/dist/map/light-profiles.js +324 -0
  91. package/dist/map/light.js +574 -0
  92. package/dist/map/local-vocab.js +27 -0
  93. package/dist/map/mobile.js +326 -0
  94. package/dist/map/py-django.js +281 -0
  95. package/dist/map/py.js +391 -0
  96. package/dist/map/rails.js +391 -0
  97. package/dist/map/repo.js +178 -0
  98. package/dist/map/rust.js +312 -0
  99. package/dist/map/spring.js +207 -0
  100. package/dist/map/taint.js +96 -0
  101. package/dist/map/touches.js +355 -0
  102. package/dist/map/vocab.js +88 -0
  103. package/dist/mapping/controls.js +34 -0
  104. package/dist/mapping/dependency-policy.js +44 -0
  105. package/dist/mapping/map.js +44 -0
  106. package/dist/mapping/maps/gitleaks.json +12 -0
  107. package/dist/mapping/maps/osv-scanner.json +7 -0
  108. package/dist/mapping/maps/trivy.json +13 -0
  109. package/dist/mcp/confine.js +59 -0
  110. package/dist/mcp/protocol.js +140 -0
  111. package/dist/mcp/schema.js +43 -0
  112. package/dist/mcp/server.js +37 -0
  113. package/dist/mcp/tools.js +238 -0
  114. package/dist/packs/coverage.js +79 -0
  115. package/dist/packs/manifest.js +36 -0
  116. package/dist/packs/validate.js +271 -0
  117. package/dist/prove/container.js +276 -0
  118. package/dist/prove/exec-main.js +20 -0
  119. package/dist/prove/executor.js +149 -0
  120. package/dist/prove/local.js +131 -0
  121. package/dist/prove/probes.js +65 -0
  122. package/dist/prove/recipe.js +278 -0
  123. package/dist/prove/run.js +136 -0
  124. package/dist/prove/runner.js +1 -0
  125. package/dist/prove/safety.js +126 -0
  126. package/dist/prove/spec.js +357 -0
  127. package/dist/prove/store.js +65 -0
  128. package/dist/report/build.js +297 -0
  129. package/dist/report/entry-points.js +75 -0
  130. package/dist/report/hunt-section.js +71 -0
  131. package/dist/report/kit.js +41 -0
  132. package/dist/report/load.js +35 -0
  133. package/dist/report/messages.js +273 -0
  134. package/dist/report/prove-section.js +65 -0
  135. package/dist/report/report.js +156 -0
  136. package/dist/report/surface.js +21 -0
  137. package/dist/report/test-code.js +51 -0
  138. package/dist/report/tiers.js +44 -0
  139. package/dist/scanners/common.js +162 -0
  140. package/dist/scanners/gitleaks.js +90 -0
  141. package/dist/scanners/index.js +113 -0
  142. package/dist/scanners/osv-scanner.js +77 -0
  143. package/dist/scanners/run-targets.js +34 -0
  144. package/dist/scanners/secret-noise.js +89 -0
  145. package/dist/scanners/semgrep.js +142 -0
  146. package/dist/scanners/trivy.js +65 -0
  147. package/dist/scanners/types.js +1 -0
  148. package/dist/types/check.js +1 -0
  149. package/dist/types/codemap.js +1 -0
  150. package/dist/types/findings.js +5 -0
  151. package/dist/types/hunt.js +1 -0
  152. package/dist/types/index.js +1 -0
  153. package/dist/types/prove.js +1 -0
  154. package/dist/types/results.js +2 -0
  155. package/dist/types/scan.js +1 -0
  156. package/dist/types/stack.js +5 -0
  157. package/dist/util.js +71 -0
  158. package/dist/version.js +2 -0
  159. package/package.json +46 -4
  160. package/packs/android/fixture-result.json +43 -0
  161. package/packs/android/pack.json +56 -0
  162. package/packs/dotnet/fixture-result.json +62 -0
  163. package/packs/dotnet/pack.json +88 -0
  164. package/packs/expo/answer-key.json +51 -0
  165. package/packs/expo/fixture-result.json +62 -0
  166. package/packs/expo/pack.json +79 -0
  167. package/packs/firebase/answer-key.json +27 -0
  168. package/packs/firebase/fixture-result.json +43 -0
  169. package/packs/firebase/pack.json +58 -0
  170. package/packs/go/answer-key.json +101 -0
  171. package/packs/go/fixture-result.json +64 -0
  172. package/packs/go/pack.json +99 -0
  173. package/packs/ios/fixture-result.json +43 -0
  174. package/packs/ios/pack.json +55 -0
  175. package/packs/laravel/answer-key.json +84 -0
  176. package/packs/laravel/fixture-result.json +60 -0
  177. package/packs/laravel/pack.json +91 -0
  178. package/packs/node-ts/answer-key.json +220 -0
  179. package/packs/node-ts/fixture-result.json +114 -0
  180. package/packs/node-ts/pack.json +134 -0
  181. package/packs/python/answer-key.json +195 -0
  182. package/packs/python/fixture-result.json +119 -0
  183. package/packs/python/pack.json +121 -0
  184. package/packs/rails/answer-key.json +84 -0
  185. package/packs/rails/fixture-result.json +60 -0
  186. package/packs/rails/pack.json +78 -0
  187. package/packs/rust/fixture-result.json +43 -0
  188. package/packs/rust/pack.json +69 -0
  189. package/packs/spring/fixture-result.json +63 -0
  190. package/packs/spring/pack.json +103 -0
  191. package/packs/supabase/answer-key.json +52 -0
  192. package/packs/supabase/fixture-result.json +58 -0
  193. package/packs/supabase/pack.json +60 -0
  194. package/rules/gitleaks.toml +256 -0
  195. package/rules/semgrep/api-route-no-auth.yaml +31 -0
  196. package/rules/semgrep/cors-reflect-origin.yaml +48 -0
  197. package/rules/semgrep/eval-or-new-function.yaml +185 -0
  198. package/rules/semgrep/log-session-token.yaml +48 -0
  199. package/rules/semgrep/math-random-tokens.yaml +24 -0
  200. package/rules/semgrep/next-public-secret-name.yaml +32 -0
  201. package/rules/semgrep/postgrest-filter-injection.yaml +78 -0
  202. package/rules/semgrep/raw-sql-concat.yaml +42 -0
  203. package/rules/semgrep/read-by-id-no-owner.yaml +49 -0
  204. package/rules/semgrep/server-action-no-auth.yaml +26 -0
  205. package/rules/semgrep/sql-variants.yaml +99 -0
  206. package/rules/semgrep/ssrf-unguarded-url.yaml +137 -0
  207. package/rules/semgrep/subprocess-injection.yaml +163 -0
  208. package/rules/semgrep/taint-go.yaml +333 -0
  209. package/rules/semgrep/taint-java.yaml +317 -0
  210. package/rules/semgrep/taint-javascript.yaml +412 -0
  211. package/rules/semgrep/taint-php.yaml +361 -0
  212. package/rules/semgrep/taint-python.yaml +414 -0
  213. package/rules/semgrep/tool-endpoint-admin-client.yaml +86 -0
  214. package/rules/semgrep/user-metadata-authz.yaml +22 -0
  215. package/rules/semgrep/verify-result-unused.yaml +62 -0
  216. package/rules/semgrep/webhook-parse-before-verify.yaml +29 -0
  217. package/rules/test-artifact-ids.json +4 -0
  218. package/rules/tiers.json +427 -0
  219. package/schemas/check-results.schema.json +55 -0
  220. package/schemas/check.schema.json +41 -0
  221. package/schemas/codemap.schema.json +216 -0
  222. package/schemas/findings.schema.json +1048 -0
  223. package/schemas/hunt-output.schema.json +46 -0
  224. package/schemas/hunt-result.schema.json +58 -0
  225. package/schemas/results.schema.json +17 -0
  226. package/schemas/scan-hits.schema.json +32 -0
  227. package/schemas/scan-meta.schema.json +25 -0
  228. package/schemas/stack.schema.json +93 -0
  229. package/src/checks/README.md +32 -0
  230. package/src/checks/code/admin-role.ts +49 -0
  231. package/src/checks/code/owner-filter.ts +95 -0
  232. package/src/checks/code/shared.ts +66 -0
  233. package/src/checks/code/webhook-verify.ts +75 -0
  234. package/src/checks/context.ts +72 -0
  235. package/src/checks/map/config-checks.ts +79 -0
  236. package/src/checks/map/entry-checks.ts +116 -0
  237. package/src/checks/map/shared.ts +63 -0
  238. package/src/checks/ops.ts +280 -0
  239. package/src/checks/pro-map.ts +4 -0
  240. package/src/checks/run.ts +80 -0
  241. package/src/checks/types.ts +12 -0
  242. package/src/ci/comment.ts +52 -0
  243. package/src/ci/sarif-check.ts +100 -0
  244. package/src/ci/sarif.ts +72 -0
  245. package/src/cli.ts +273 -0
  246. package/src/commands/ci.ts +104 -0
  247. package/src/commands/git.ts +59 -0
  248. package/src/commands/hooks.ts +27 -0
  249. package/src/commands/hunt-pro.ts +4 -0
  250. package/src/commands/hunt.ts +68 -0
  251. package/src/commands/map.ts +27 -0
  252. package/src/commands/mcp.ts +18 -0
  253. package/src/commands/pack.ts +34 -0
  254. package/src/commands/prove-pro.ts +4 -0
  255. package/src/commands/prove.ts +126 -0
  256. package/src/commands/report-gate.ts +75 -0
  257. package/src/commands/scan.ts +156 -0
  258. package/src/confirm/agreement.ts +23 -0
  259. package/src/confirm/chain.ts +67 -0
  260. package/src/confirm/confirm.ts +107 -0
  261. package/src/confirm/honesty.ts +65 -0
  262. package/src/confirm/lead.ts +76 -0
  263. package/src/confirm/merge.ts +89 -0
  264. package/src/confirm/query.ts +126 -0
  265. package/src/confirm/rule.ts +76 -0
  266. package/src/confirm/store.ts +42 -0
  267. package/src/confirm/summary.ts +9 -0
  268. package/src/confirm/synthesis.ts +33 -0
  269. package/src/discover/detectors.ts +71 -0
  270. package/src/discover/discover.ts +253 -0
  271. package/src/discover/extract.ts +235 -0
  272. package/src/discover/git.ts +31 -0
  273. package/src/discover/kit-files.ts +37 -0
  274. package/src/discover/walk.ts +88 -0
  275. package/src/env.ts +51 -0
  276. package/src/gate/gate.ts +169 -0
  277. package/src/hooks/install.ts +142 -0
  278. package/src/hooks/run.ts +121 -0
  279. package/src/map/analyze.ts +219 -0
  280. package/src/map/build.ts +206 -0
  281. package/src/map/candidates.ts +47 -0
  282. package/src/map/cblocks.ts +55 -0
  283. package/src/map/config.ts +207 -0
  284. package/src/map/dotnet.ts +205 -0
  285. package/src/map/entry.ts +80 -0
  286. package/src/map/expo.ts +171 -0
  287. package/src/map/go.ts +271 -0
  288. package/src/map/js-express.ts +135 -0
  289. package/src/map/js-misc.ts +221 -0
  290. package/src/map/js-next.ts +282 -0
  291. package/src/map/laravel.ts +327 -0
  292. package/src/map/lex-more.ts +152 -0
  293. package/src/map/lex.ts +274 -0
  294. package/src/map/light-index.ts +134 -0
  295. package/src/map/light-profiles.ts +363 -0
  296. package/src/map/light.ts +484 -0
  297. package/src/map/local-vocab.ts +30 -0
  298. package/src/map/mobile.ts +263 -0
  299. package/src/map/py-django.ts +239 -0
  300. package/src/map/py.ts +329 -0
  301. package/src/map/rails.ts +291 -0
  302. package/src/map/repo.ts +150 -0
  303. package/src/map/rust.ts +256 -0
  304. package/src/map/spring.ts +185 -0
  305. package/src/map/taint.ts +86 -0
  306. package/src/map/touches.ts +296 -0
  307. package/src/map/vocab.ts +106 -0
  308. package/src/mapping/controls.ts +47 -0
  309. package/src/mapping/dependency-policy.ts +55 -0
  310. package/src/mapping/map.ts +59 -0
  311. package/src/mapping/maps/gitleaks.json +12 -0
  312. package/src/mapping/maps/osv-scanner.json +7 -0
  313. package/src/mapping/maps/trivy.json +13 -0
  314. package/src/mcp/confine.ts +44 -0
  315. package/src/mcp/protocol.ts +144 -0
  316. package/src/mcp/schema.ts +35 -0
  317. package/src/mcp/server.ts +32 -0
  318. package/src/mcp/tools.ts +235 -0
  319. package/src/packs/coverage.ts +98 -0
  320. package/src/packs/manifest.ts +97 -0
  321. package/src/packs/validate.ts +204 -0
  322. package/src/prove/container.ts +237 -0
  323. package/src/prove/exec-main.ts +16 -0
  324. package/src/prove/executor.ts +130 -0
  325. package/src/prove/local.ts +100 -0
  326. package/src/prove/probes.ts +68 -0
  327. package/src/prove/recipe.ts +215 -0
  328. package/src/prove/run.ts +124 -0
  329. package/src/prove/runner.ts +28 -0
  330. package/src/prove/safety.ts +98 -0
  331. package/src/prove/spec.ts +256 -0
  332. package/src/prove/store.ts +48 -0
  333. package/src/report/build.ts +304 -0
  334. package/src/report/entry-points.ts +78 -0
  335. package/src/report/hunt-section.ts +67 -0
  336. package/src/report/kit.ts +59 -0
  337. package/src/report/load.ts +49 -0
  338. package/src/report/messages.ts +270 -0
  339. package/src/report/prove-section.ts +61 -0
  340. package/src/report/report.ts +160 -0
  341. package/src/report/surface.ts +32 -0
  342. package/src/report/test-code.ts +56 -0
  343. package/src/report/tiers.ts +50 -0
  344. package/src/scanners/common.ts +149 -0
  345. package/src/scanners/gitleaks.ts +89 -0
  346. package/src/scanners/index.ts +103 -0
  347. package/src/scanners/osv-scanner.ts +90 -0
  348. package/src/scanners/run-targets.ts +35 -0
  349. package/src/scanners/secret-noise.ts +80 -0
  350. package/src/scanners/semgrep.ts +139 -0
  351. package/src/scanners/trivy.ts +66 -0
  352. package/src/scanners/types.ts +98 -0
  353. package/src/types/check.ts +52 -0
  354. package/src/types/codemap.ts +142 -0
  355. package/src/types/findings.ts +107 -0
  356. package/src/types/hunt.ts +97 -0
  357. package/src/types/index.ts +10 -0
  358. package/src/types/prove.ts +83 -0
  359. package/src/types/results.ts +15 -0
  360. package/src/types/scan.ts +63 -0
  361. package/src/types/stack.ts +61 -0
  362. package/src/util.ts +59 -0
  363. package/src/version.ts +2 -0
@@ -0,0 +1,389 @@
1
+ import { empty, joinPath, makeEntry } from './entry.js';
2
+ import { phpFunc } from './light-index.js';
3
+ import { analyzeLight } from './light.js';
4
+ import { closeOf, splitArgs } from './lex.js';
5
+ const VERBS = new Set(['get', 'post', 'put', 'patch', 'delete', 'options', 'any']);
6
+ const singular = (s) => (/ies$/.test(s) ? s.replace(/ies$/, 'y') : s.replace(/s$/, ''));
7
+ const phpPath = (p) => p.replace(/\{(\w+)\??(?::[^}]*)?\}/g, ':$1');
8
+ const strs = (s) => [...s.matchAll(/['"]([^'"]*)['"]/g)].map((m) => m[1]);
9
+ export function laravelFiles(repo) {
10
+ return repo.filesOf('php').filter((f) => /(?:^|\/)routes\/(?!console|channels)[\w.-]+\.php$/.test(f));
11
+ }
12
+ function chainAt(v, at) {
13
+ const m = v.masked;
14
+ const calls = [];
15
+ let pos = at + 'Route::'.length;
16
+ for (let guard = 0; guard < 24; guard++) {
17
+ const id = /^\s*(\w+)\s*\(/.exec(m.slice(pos, pos + 800));
18
+ if (!id)
19
+ break;
20
+ const open = pos + id[0].length - 1;
21
+ const close = closeOf(m, open);
22
+ if (close < 0)
23
+ break;
24
+ calls.push({ name: id[1], open, close });
25
+ pos = close;
26
+ const arrow = /^\s*->\s*/.exec(m.slice(pos, pos + 800)); // comments are blank in the masked copy and can be long
27
+ if (!arrow)
28
+ break;
29
+ pos += arrow[0].length;
30
+ }
31
+ return { calls, end: pos };
32
+ }
33
+ export function extractLaravelAll(repo, fn, local) {
34
+ const out = empty();
35
+ const files = laravelFiles(repo);
36
+ if (!files.length)
37
+ return out;
38
+ // Classes by short name: controllers, models and middleware.
39
+ const classes = new Map();
40
+ for (const f of repo.filesOf('php')) {
41
+ if (/(?:^|\/)(?:vendor|node_modules)\//.test(f))
42
+ continue;
43
+ const v = repo.view(f);
44
+ if (!v)
45
+ continue;
46
+ const m = /^[ \t]*(?:final\s+|abstract\s+)?class\s+(\w+)/m.exec(v.masked);
47
+ if (m && !classes.has(m[1]))
48
+ classes.set(m[1], v);
49
+ }
50
+ const isModel = (cls) => { const v = classes.get(cls); return !!v && (/\/Models\//.test(v.file) || /\bextends\s+(?:Model|Authenticatable|Pivot|\\?Illuminate\\Database\\Eloquent\\Model)\b/.test(v.masked)); };
51
+ // Aliases of route middleware: 'admin' => EnsureUserIsAdmin::class.
52
+ const aliases = new Map();
53
+ const bootText = ['bootstrap/app.php', 'app/Http/Kernel.php', 'app/Providers/RouteServiceProvider.php'].map((f) => ({ f, t: repo.ctx.text(f) }));
54
+ for (const { t } of bootText)
55
+ for (const m of t.matchAll(/['"]([\w.-]+)['"]\s*=>\s*\\?(?:[\w\\]*\\)?(\w+)::class/g))
56
+ aliases.set(m[1], m[2]);
57
+ let apiThrottle = null;
58
+ for (const { f, t } of bootText) {
59
+ const m = /throttleApi\s*\(|['"]throttle:api['"]|['"]api['"]\s*=>\s*\[[^\]]*throttle/.exec(t);
60
+ if (m && !apiThrottle)
61
+ apiThrottle = { kind: 'rate_limit', scope: 'global', file: f, line: t.slice(0, m.index).split('\n').length, via: 'api middleware group throttle', enforced: true, confidence: 'medium' };
62
+ }
63
+ // Controller level middleware: constructor, HasMiddleware, attributes, authorizeResource.
64
+ const ctrlFilters = (cls) => {
65
+ const v = classes.get(cls);
66
+ const filters = [];
67
+ let policy = false;
68
+ if (!v)
69
+ return { filters, policy };
70
+ const m = v.masked;
71
+ const lists = (text) => ({
72
+ only: /->\s*only\s*\(([^)]*)\)/.exec(text) ? strs(/->\s*only\s*\(([^)]*)\)/.exec(text)[1]) : null,
73
+ except: /->\s*except\s*\(([^)]*)\)/.exec(text) ? strs(/->\s*except\s*\(([^)]*)\)/.exec(text)[1]) : null,
74
+ });
75
+ for (const x of m.matchAll(/\$this->middleware\s*\(/g)) {
76
+ const open = x.index + x[0].length - 1;
77
+ const close = closeOf(m, open);
78
+ if (close < 0)
79
+ continue;
80
+ const stmtEnd = m.indexOf(';', close);
81
+ const tail = v.text.slice(close, stmtEnd < 0 ? close : stmtEnd);
82
+ filters.push({ view: v, start: x.index, end: Math.max(close, stmtEnd < 0 ? close : stmtEnd), ...lists(tail) });
83
+ }
84
+ for (const x of m.matchAll(/\$this->authorizeResource\s*\(/g)) {
85
+ const open = x.index + x[0].length - 1;
86
+ const close = closeOf(m, open);
87
+ policy = true;
88
+ filters.push({ view: v, start: x.index, end: close < 0 ? open : close, only: null, except: null });
89
+ }
90
+ const sm = /static\s+function\s+middleware\s*\(/.exec(m);
91
+ if (sm) {
92
+ const f = phpFunc(m, sm.index);
93
+ if (f) {
94
+ const body = v.text.slice(f.bodyStart, f.end);
95
+ const bm = m.slice(f.bodyStart, f.end);
96
+ let covered = 0;
97
+ for (const x of bm.matchAll(/new\s+(?:\\?[\w\\]*\\)?Middleware\s*\(/g)) {
98
+ const open = f.bodyStart + x.index + x[0].length - 1;
99
+ const close = closeOf(m, open);
100
+ if (close < 0)
101
+ continue;
102
+ const t = v.text.slice(open, close);
103
+ filters.push({ view: v, start: open, end: close, only: /only:\s*\[([^\]]*)\]/.exec(t) ? strs(/only:\s*\[([^\]]*)\]/.exec(t)[1]) : null, except: /except:\s*\[([^\]]*)\]/.exec(t) ? strs(/except:\s*\[([^\]]*)\]/.exec(t)[1]) : null });
104
+ covered += close - open;
105
+ }
106
+ if (body.length)
107
+ for (const x of body.matchAll(/(?<![\w(,]\s*)['"]([\w.:,-]+)['"]/g)) {
108
+ void x;
109
+ }
110
+ if (!filters.some((fl) => fl.view === v && fl.start >= f.bodyStart && fl.end <= f.end))
111
+ filters.push({ view: v, start: f.bodyStart, end: f.end, only: null, except: null });
112
+ void covered;
113
+ }
114
+ }
115
+ const cm = /^[ \t]*(?:#\[[^\n]*\]\s*)+(?=(?:final\s+|abstract\s+)?class\b)/m.exec(m);
116
+ if (cm)
117
+ filters.push({ view: v, start: cm.index, end: cm.index + cm[0].length, only: null, except: null });
118
+ return { filters, policy };
119
+ };
120
+ const methodAttrs = (v, fnStart) => {
121
+ const before = v.text.slice(Math.max(0, fnStart - 400), fnStart);
122
+ const am = /((?:^|\n)[ \t]*#\[[^\n]*\][ \t]*\n[ \t]*)+(?:(?:public|protected|private|static)\s+)*$/.exec(before);
123
+ return am ? { view: v, start: fnStart - am[0].length, end: fnStart, scope: 'router' } : null;
124
+ };
125
+ for (const rf of files) {
126
+ const v = repo.view(rf);
127
+ if (!v)
128
+ continue;
129
+ const m = v.masked;
130
+ const isApi = /(?:^|\/)api\.php$/.test(rf);
131
+ const base = { prefix: isApi ? '/api' : '', mws: [], controller: null, without: [] };
132
+ // Providers that load this file through a group: Route::prefix('api/v1')->middleware('api')->group(base_path('routes/api.php'))
133
+ const name = /([\w-]+)\.php$/.exec(rf)[1];
134
+ for (const { f, t } of bootText) {
135
+ const pm = new RegExp(`Route::([^;]*?)->group\\s*\\(\\s*base_path\\s*\\(\\s*['"]routes/${name}\\.php['"]`).exec(t);
136
+ if (pm) {
137
+ const bv = repo.view(f);
138
+ const pre = /prefix\s*\(\s*['"]([^'"]*)['"]/.exec(pm[1]);
139
+ if (pre)
140
+ base.prefix = joinPath('', pre[1]);
141
+ if (bv && pm.index !== undefined)
142
+ base.mws.push({ view: bv, start: pm.index, end: pm.index + pm[0].length });
143
+ }
144
+ }
145
+ const handle = (calls, ctx, at) => {
146
+ // Modifiers before the terminal call apply to everything under it; modifiers after it apply to the route.
147
+ let c = { ...ctx, mws: ctx.mws.slice(), without: ctx.without.slice() };
148
+ const term = calls.findIndex((x) => VERBS.has(x.name) || ['match', 'resource', 'apiResource', 'resources', 'apiResources', 'singleton', 'group', 'webhooks'].includes(x.name));
149
+ const route = [];
150
+ const apply = (x, into, routeLevel) => {
151
+ const a = splitArgs(m, x.open);
152
+ const range = { view: v, start: x.open - x.name.length - 2, end: x.close };
153
+ if (x.name === 'prefix' && a[0])
154
+ into.prefix = joinPath(into.prefix, strs(v.text.slice(a[0].start, a[0].end))[0] ?? '');
155
+ else if (x.name === 'middleware')
156
+ (routeLevel ? route : into.mws).push(range);
157
+ else if (x.name === 'can')
158
+ (routeLevel ? route : into.mws).push(range);
159
+ else if (x.name === 'withoutMiddleware')
160
+ into.without.push(...strs(v.text.slice(x.open, x.close)));
161
+ else if (x.name === 'controller' && a[0])
162
+ into.controller = /(\w+)::class/.exec(v.text.slice(a[0].start, a[0].end))?.[1] ?? null;
163
+ };
164
+ const mods = term < 0 ? calls : calls.slice(0, term);
165
+ for (const x of mods)
166
+ apply(x, c, false);
167
+ if (term < 0)
168
+ return;
169
+ const t = calls[term];
170
+ const after = calls.slice(term + 1);
171
+ if (t.name === 'group') {
172
+ const a = splitArgs(m, t.open);
173
+ // Route::group(['prefix' => 'x', 'middleware' => ['auth']], function () { ... })
174
+ if (a.length === 2) {
175
+ const arr = v.text.slice(a[0].start, a[0].end);
176
+ const px = /['"]prefix['"]\s*=>\s*['"]([^'"]*)['"]/.exec(arr);
177
+ if (px)
178
+ c.prefix = joinPath(c.prefix, px[1]);
179
+ const mw = /['"]middleware['"]\s*=>/.exec(arr);
180
+ if (mw)
181
+ c.mws.push({ view: v, start: a[0].start + mw.index, end: a[0].end });
182
+ }
183
+ const closure = a.find((x) => /^(?:static\s+)?(?:function|fn)\b/.test(m.slice(x.start, x.end)));
184
+ if (closure) {
185
+ const body = /\{/.exec(m.slice(closure.start, closure.end));
186
+ if (body) {
187
+ const bs = closure.start + body.index;
188
+ const be = closeOf(m, bs);
189
+ for (const x of after)
190
+ apply(x, c, false);
191
+ walk(bs + 1, be < 0 ? closure.end : be - 1, c);
192
+ }
193
+ else if (/^(?:static\s+)?fn\b/.test(m.slice(closure.start, closure.end)))
194
+ walk(closure.start, closure.end, c);
195
+ }
196
+ return;
197
+ }
198
+ for (const x of after)
199
+ apply(x, c, true);
200
+ const args = splitArgs(m, t.open);
201
+ const line = v.lines.at(at);
202
+ const text = (a) => v.text.slice(a.start, a.end);
203
+ const emit = (verb, path, handler, cls, method, extraName, ctrlOverride) => {
204
+ const full = joinPath(c.prefix, phpPath(path));
205
+ const cname = cls ?? ctrlOverride ?? null;
206
+ const cv = cname ? classes.get(cname) : undefined;
207
+ const fnDef = cv && method ? fn.defs(method).find((d) => d.view.file === cv.file) : undefined;
208
+ const mws = [...c.mws.filter((x) => !c.without.some((w) => v.text.slice(x.start, x.end).includes(w))), ...route];
209
+ const decos = [];
210
+ const extra = [];
211
+ for (const x of mws) {
212
+ decos.push({ view: x.view, start: x.start, end: x.end, scope: x.view === v && route.includes(x) ? 'wrapper' : 'router' });
213
+ // A middleware alias or class that lives in the repository: read the class.
214
+ for (const nm of [...strs(x.view.text.slice(x.start, x.end)), ...[...x.view.text.slice(x.start, x.end).matchAll(/(\w+)::class/g)].map((y) => y[1])]) {
215
+ const cls2 = aliases.get(nm.split(':')[0]) ?? nm;
216
+ const mv = classes.get(cls2);
217
+ if (mv && /Middleware\//.test(mv.file))
218
+ decos.push({ view: mv, start: 0, end: mv.text.length, scope: 'router' });
219
+ }
220
+ }
221
+ let policy = false;
222
+ let seeds = [];
223
+ const bound = [];
224
+ let hv = v;
225
+ let start = m.lastIndexOf('\n', at) + 1;
226
+ let end = t.close;
227
+ let params = '';
228
+ let found = false;
229
+ if (handler) {
230
+ const isClosure = /^(?:static\s+)?(?:function|fn)\b/.test(m.slice(handler.start, handler.end));
231
+ if (isClosure) {
232
+ const f = /^(?:static\s+)?function\b/.test(m.slice(handler.start, handler.end)) ? phpFunc(m, handler.start + m.slice(handler.start).indexOf('function')) : null;
233
+ if (f) {
234
+ start = f.start;
235
+ end = f.end;
236
+ params = f.params;
237
+ found = true;
238
+ }
239
+ else {
240
+ start = handler.start;
241
+ end = handler.end;
242
+ params = /\(([^)]*)\)/.exec(m.slice(handler.start, handler.end))?.[1] ?? '';
243
+ found = true;
244
+ }
245
+ }
246
+ }
247
+ else if (fnDef && cv) {
248
+ hv = cv;
249
+ start = fnDef.start;
250
+ end = fnDef.end;
251
+ found = true;
252
+ const f = phpFunc(cv.masked, fnDef.start);
253
+ params = f?.params ?? '';
254
+ const { filters, policy: pol } = ctrlFilters(cname);
255
+ for (const fl of filters) {
256
+ if (fl.only && (!method || !fl.only.includes(method)))
257
+ continue;
258
+ if (fl.except && method && fl.except.includes(method))
259
+ continue;
260
+ decos.push({ view: fl.view, start: fl.start, end: fl.end, scope: 'router' });
261
+ }
262
+ policy = pol;
263
+ const attr = methodAttrs(cv, fnDef.start);
264
+ if (attr)
265
+ decos.push(attr);
266
+ }
267
+ for (const part of params.split(/,(?![^(]*\))/)) {
268
+ const pm = /^\s*(?:(?:public|protected|private|readonly)\s+)*(?:\??([\w\\]+)\s+)?(?:\.\.\.)?&?(\$\w+)/.exec(part);
269
+ if (!pm)
270
+ continue;
271
+ const typ = pm[1]?.split('\\').pop() ?? null;
272
+ if (typ && /Request$/.test(typ))
273
+ continue;
274
+ if (typ && isModel(typ))
275
+ bound.push({ name: pm[2], target: typ });
276
+ else if (!typ || /^(?:int|string|float|bool|mixed|array)$/.test(typ))
277
+ seeds.push(pm[2]);
278
+ }
279
+ if (apiThrottle && isApi)
280
+ extra.push(apiThrottle);
281
+ const a = analyzeLight(hv, { start, end, seeds, decorators: decos, extra, lookup: fn.find, local, policyScoped: policy, bound });
282
+ out.entries.push(makeEntry(repo, {
283
+ kind: 'http_route', framework: 'laravel', file: rf, line, method: verb, path: full || '/', name: extraName ?? (cname && method ? `${cname}@${method}` : null),
284
+ confidence: found ? 'high' : 'low', handlerView: hv, spec: { start, end, seeds }, analysis: a,
285
+ }));
286
+ };
287
+ const parseHandler = (a) => {
288
+ if (!a)
289
+ return { handler: null, cls: c.controller, method: null };
290
+ const t2 = text(a).trim();
291
+ const arr = /^\[\s*\\?(?:[\w\\]*\\)?(\w+)::class\s*,\s*['"](\w+)['"]\s*\]$/.exec(t2);
292
+ if (arr)
293
+ return { handler: null, cls: arr[1], method: arr[2] };
294
+ const str = /^['"](?:[\w\\]*\\)?(\w+)@(\w+)['"]$/.exec(t2);
295
+ if (str)
296
+ return { handler: null, cls: str[1], method: str[2] };
297
+ const inv = /^\\?(?:[\w\\]*\\)?(\w+)::class$/.exec(t2);
298
+ if (inv)
299
+ return { handler: null, cls: inv[1], method: '__invoke' };
300
+ const mt = /^['"](\w+)['"]$/.exec(t2);
301
+ if (mt && c.controller)
302
+ return { handler: null, cls: c.controller, method: mt[1] };
303
+ if (/^(?:static\s+)?(?:function|fn)\b/.test(m.slice(a.start, a.end).trim()))
304
+ return { handler: a, cls: null, method: null };
305
+ return { handler: null, cls: null, method: null };
306
+ };
307
+ if (VERBS.has(t.name)) {
308
+ const p = strs(text(args[0] ?? { start: 0, end: 0 }))[0];
309
+ if (p === undefined)
310
+ return;
311
+ const h = parseHandler(args[1]);
312
+ if (!h.handler && !h.cls && args[1] === undefined)
313
+ return;
314
+ emit(t.name === 'any' ? 'ANY' : t.name.toUpperCase(), p, h.handler, h.cls, h.method, null);
315
+ }
316
+ else if (t.name === 'match') {
317
+ const verbs = strs(text(args[0] ?? { start: 0, end: 0 })).map((x) => x.toUpperCase());
318
+ const p = strs(text(args[1] ?? { start: 0, end: 0 }))[0];
319
+ if (p === undefined)
320
+ return;
321
+ const h = parseHandler(args[2]);
322
+ for (const verb of verbs.length ? verbs : ['ANY'])
323
+ emit(verb, p, h.handler, h.cls, h.method, null);
324
+ }
325
+ else if (t.name === 'resource' || t.name === 'apiResource' || t.name === 'singleton') {
326
+ const nm = strs(text(args[0] ?? { start: 0, end: 0 }))[0];
327
+ const cls = /(\w+)::class/.exec(text(args[1] ?? { start: 0, end: 0 }))?.[1] ?? null;
328
+ if (!nm || !cls)
329
+ return;
330
+ const only = after.find((x) => x.name === 'only');
331
+ const except = after.find((x) => x.name === 'except');
332
+ const onlyL = only ? strs(v.text.slice(only.open, only.close)) : null;
333
+ const exceptL = except ? strs(v.text.slice(except.open, except.close)) : null;
334
+ const segs = nm.split('.');
335
+ const prefix = segs.slice(0, -1).map((s) => `/${s}/:${singular(s)}`).join('');
336
+ const last = segs[segs.length - 1];
337
+ const param = singular(last);
338
+ const acts = t.name === 'singleton'
339
+ ? [['show', 'GET', ''], ['update', 'PUT', ''], ['update', 'PATCH', '']]
340
+ : [['index', 'GET', ''], ['create', 'GET', '/create'], ['store', 'POST', ''], ['show', 'GET', `/:${param}`], ['edit', 'GET', `/:${param}/edit`], ['update', 'PUT', `/:${param}`], ['update', 'PATCH', `/:${param}`], ['destroy', 'DELETE', `/:${param}`]];
341
+ for (const [act, verb, sfx] of acts) {
342
+ if (t.name === 'apiResource' && (act === 'create' || act === 'edit'))
343
+ continue;
344
+ if (onlyL && !onlyL.includes(act))
345
+ continue;
346
+ if (exceptL && exceptL.includes(act))
347
+ continue;
348
+ emit(verb, `${prefix}/${last}${sfx}`, null, cls, act, null);
349
+ }
350
+ }
351
+ else if (t.name === 'resources' || t.name === 'apiResources') {
352
+ for (const x of v.text.slice(t.open, t.close).matchAll(/['"]([\w.-]+)['"]\s*=>\s*(\w+)::class/g)) {
353
+ const param = singular(x[1]);
354
+ const acts = [['index', 'GET', ''], ['store', 'POST', ''], ['show', 'GET', `/:${param}`], ['update', 'PUT', `/:${param}`], ['update', 'PATCH', `/:${param}`], ['destroy', 'DELETE', `/:${param}`]];
355
+ for (const [act, verb, sfx] of acts)
356
+ emit(verb, `/${x[1]}${sfx}`, null, x[2], act, null);
357
+ }
358
+ }
359
+ else if (t.name === 'webhooks') {
360
+ const p = strs(text(args[0] ?? { start: 0, end: 0 }))[0];
361
+ if (p)
362
+ emit('POST', p, null, null, null, 'webhook-client');
363
+ }
364
+ void c;
365
+ };
366
+ const walk = (from, to, ctx) => {
367
+ let i = from;
368
+ while (i < to) {
369
+ const at = m.indexOf('Route::', i);
370
+ if (at < 0 || at >= to)
371
+ break;
372
+ const prev = m.slice(Math.max(0, at - 1), at);
373
+ if (/[\w$>]/.test(prev)) {
374
+ i = at + 7;
375
+ continue;
376
+ }
377
+ const ch = chainAt(v, at);
378
+ if (!ch.calls.length) {
379
+ i = at + 7;
380
+ continue;
381
+ }
382
+ handle(ch.calls, ctx, at);
383
+ i = Math.max(ch.end, at + 7);
384
+ }
385
+ };
386
+ walk(0, m.length, base);
387
+ }
388
+ return out;
389
+ }