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.
- package/LICENSE +222 -0
- package/NOTICE +32 -0
- package/README.md +313 -2
- package/checks/db.firebase-rules-not-open.json +24 -0
- package/checks/db.rls-every-table.json +25 -0
- package/checks/log.no-credential-in-logs.json +30 -0
- package/checks/secrets.no-env-file-committed.json +31 -0
- package/checks/secrets.no-secret-in-public-env.json +37 -0
- package/checks/storage.firebase-rules-not-open.json +22 -0
- package/checks/supply.no-untrusted-event-in-run.json +23 -0
- package/checks/web.cors-no-reflected-origin.json +31 -0
- package/detectors/ai.json +25 -0
- package/detectors/auth.json +27 -0
- package/detectors/ci.json +19 -0
- package/detectors/containers.json +8 -0
- package/detectors/data_stores.json +38 -0
- package/detectors/frameworks.json +94 -0
- package/detectors/hosting.json +44 -0
- package/detectors/iac.json +43 -0
- package/detectors/languages.json +48 -0
- package/detectors/mobile.json +22 -0
- package/detectors/package_managers.json +39 -0
- package/detectors/payments.json +19 -0
- package/detectors/runtimes.json +17 -0
- package/dist/checks/code/admin-role.js +46 -0
- package/dist/checks/code/owner-filter.js +91 -0
- package/dist/checks/code/shared.js +84 -0
- package/dist/checks/code/webhook-verify.js +77 -0
- package/dist/checks/context.js +64 -0
- package/dist/checks/map/config-checks.js +74 -0
- package/dist/checks/map/entry-checks.js +97 -0
- package/dist/checks/map/shared.js +44 -0
- package/dist/checks/ops.js +307 -0
- package/dist/checks/pro-map.js +1 -0
- package/dist/checks/run.js +92 -0
- package/dist/checks/types.js +1 -0
- package/dist/ci/comment.js +44 -0
- package/dist/ci/sarif-check.js +157 -0
- package/dist/ci/sarif.js +61 -0
- package/dist/cli.js +358 -0
- package/dist/commands/ci.js +115 -0
- package/dist/commands/git.js +58 -0
- package/dist/commands/hooks.js +30 -0
- package/dist/commands/hunt-pro.js +1 -0
- package/dist/commands/hunt.js +86 -0
- package/dist/commands/map.js +33 -0
- package/dist/commands/mcp.js +17 -0
- package/dist/commands/pack.js +48 -0
- package/dist/commands/prove-pro.js +1 -0
- package/dist/commands/prove.js +173 -0
- package/dist/commands/report-gate.js +92 -0
- package/dist/commands/scan.js +158 -0
- package/dist/confirm/agreement.js +18 -0
- package/dist/confirm/chain.js +84 -0
- package/dist/confirm/confirm.js +112 -0
- package/dist/confirm/honesty.js +75 -0
- package/dist/confirm/lead.js +92 -0
- package/dist/confirm/merge.js +88 -0
- package/dist/confirm/query.js +145 -0
- package/dist/confirm/rule.js +86 -0
- package/dist/confirm/store.js +42 -0
- package/dist/confirm/summary.js +6 -0
- package/dist/confirm/synthesis.js +28 -0
- package/dist/discover/detectors.js +50 -0
- package/dist/discover/discover.js +270 -0
- package/dist/discover/extract.js +282 -0
- package/dist/discover/git.js +40 -0
- package/dist/discover/kit-files.js +47 -0
- package/dist/discover/walk.js +110 -0
- package/dist/env.js +57 -0
- package/dist/gate/gate.js +173 -0
- package/dist/hooks/install.js +153 -0
- package/dist/hooks/run.js +112 -0
- package/dist/map/analyze.js +201 -0
- package/dist/map/build.js +253 -0
- package/dist/map/candidates.js +49 -0
- package/dist/map/cblocks.js +77 -0
- package/dist/map/config.js +291 -0
- package/dist/map/dotnet.js +242 -0
- package/dist/map/entry.js +78 -0
- package/dist/map/expo.js +190 -0
- package/dist/map/go.js +292 -0
- package/dist/map/js-express.js +143 -0
- package/dist/map/js-misc.js +295 -0
- package/dist/map/js-next.js +292 -0
- package/dist/map/laravel.js +389 -0
- package/dist/map/lex-more.js +305 -0
- package/dist/map/lex.js +425 -0
- package/dist/map/light-index.js +191 -0
- package/dist/map/light-profiles.js +324 -0
- package/dist/map/light.js +574 -0
- package/dist/map/local-vocab.js +27 -0
- package/dist/map/mobile.js +326 -0
- package/dist/map/py-django.js +281 -0
- package/dist/map/py.js +391 -0
- package/dist/map/rails.js +391 -0
- package/dist/map/repo.js +178 -0
- package/dist/map/rust.js +312 -0
- package/dist/map/spring.js +207 -0
- package/dist/map/taint.js +96 -0
- package/dist/map/touches.js +355 -0
- package/dist/map/vocab.js +88 -0
- package/dist/mapping/controls.js +34 -0
- package/dist/mapping/dependency-policy.js +44 -0
- package/dist/mapping/map.js +44 -0
- package/dist/mapping/maps/gitleaks.json +12 -0
- package/dist/mapping/maps/osv-scanner.json +7 -0
- package/dist/mapping/maps/trivy.json +13 -0
- package/dist/mcp/confine.js +59 -0
- package/dist/mcp/protocol.js +140 -0
- package/dist/mcp/schema.js +43 -0
- package/dist/mcp/server.js +37 -0
- package/dist/mcp/tools.js +238 -0
- package/dist/packs/coverage.js +79 -0
- package/dist/packs/manifest.js +36 -0
- package/dist/packs/validate.js +271 -0
- package/dist/prove/container.js +276 -0
- package/dist/prove/exec-main.js +20 -0
- package/dist/prove/executor.js +149 -0
- package/dist/prove/local.js +131 -0
- package/dist/prove/probes.js +65 -0
- package/dist/prove/recipe.js +278 -0
- package/dist/prove/run.js +136 -0
- package/dist/prove/runner.js +1 -0
- package/dist/prove/safety.js +126 -0
- package/dist/prove/spec.js +357 -0
- package/dist/prove/store.js +65 -0
- package/dist/report/build.js +297 -0
- package/dist/report/entry-points.js +75 -0
- package/dist/report/hunt-section.js +71 -0
- package/dist/report/kit.js +41 -0
- package/dist/report/load.js +35 -0
- package/dist/report/messages.js +273 -0
- package/dist/report/prove-section.js +65 -0
- package/dist/report/report.js +156 -0
- package/dist/report/surface.js +21 -0
- package/dist/report/test-code.js +51 -0
- package/dist/report/tiers.js +44 -0
- package/dist/scanners/common.js +162 -0
- package/dist/scanners/gitleaks.js +90 -0
- package/dist/scanners/index.js +113 -0
- package/dist/scanners/osv-scanner.js +77 -0
- package/dist/scanners/run-targets.js +34 -0
- package/dist/scanners/secret-noise.js +89 -0
- package/dist/scanners/semgrep.js +142 -0
- package/dist/scanners/trivy.js +65 -0
- package/dist/scanners/types.js +1 -0
- package/dist/types/check.js +1 -0
- package/dist/types/codemap.js +1 -0
- package/dist/types/findings.js +5 -0
- package/dist/types/hunt.js +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/prove.js +1 -0
- package/dist/types/results.js +2 -0
- package/dist/types/scan.js +1 -0
- package/dist/types/stack.js +5 -0
- package/dist/util.js +71 -0
- package/dist/version.js +2 -0
- package/package.json +46 -4
- package/packs/android/fixture-result.json +43 -0
- package/packs/android/pack.json +56 -0
- package/packs/dotnet/fixture-result.json +62 -0
- package/packs/dotnet/pack.json +88 -0
- package/packs/expo/answer-key.json +51 -0
- package/packs/expo/fixture-result.json +62 -0
- package/packs/expo/pack.json +79 -0
- package/packs/firebase/answer-key.json +27 -0
- package/packs/firebase/fixture-result.json +43 -0
- package/packs/firebase/pack.json +58 -0
- package/packs/go/answer-key.json +101 -0
- package/packs/go/fixture-result.json +64 -0
- package/packs/go/pack.json +99 -0
- package/packs/ios/fixture-result.json +43 -0
- package/packs/ios/pack.json +55 -0
- package/packs/laravel/answer-key.json +84 -0
- package/packs/laravel/fixture-result.json +60 -0
- package/packs/laravel/pack.json +91 -0
- package/packs/node-ts/answer-key.json +220 -0
- package/packs/node-ts/fixture-result.json +114 -0
- package/packs/node-ts/pack.json +134 -0
- package/packs/python/answer-key.json +195 -0
- package/packs/python/fixture-result.json +119 -0
- package/packs/python/pack.json +121 -0
- package/packs/rails/answer-key.json +84 -0
- package/packs/rails/fixture-result.json +60 -0
- package/packs/rails/pack.json +78 -0
- package/packs/rust/fixture-result.json +43 -0
- package/packs/rust/pack.json +69 -0
- package/packs/spring/fixture-result.json +63 -0
- package/packs/spring/pack.json +103 -0
- package/packs/supabase/answer-key.json +52 -0
- package/packs/supabase/fixture-result.json +58 -0
- package/packs/supabase/pack.json +60 -0
- package/rules/gitleaks.toml +256 -0
- package/rules/semgrep/api-route-no-auth.yaml +31 -0
- package/rules/semgrep/cors-reflect-origin.yaml +48 -0
- package/rules/semgrep/eval-or-new-function.yaml +185 -0
- package/rules/semgrep/log-session-token.yaml +48 -0
- package/rules/semgrep/math-random-tokens.yaml +24 -0
- package/rules/semgrep/next-public-secret-name.yaml +32 -0
- package/rules/semgrep/postgrest-filter-injection.yaml +78 -0
- package/rules/semgrep/raw-sql-concat.yaml +42 -0
- package/rules/semgrep/read-by-id-no-owner.yaml +49 -0
- package/rules/semgrep/server-action-no-auth.yaml +26 -0
- package/rules/semgrep/sql-variants.yaml +99 -0
- package/rules/semgrep/ssrf-unguarded-url.yaml +137 -0
- package/rules/semgrep/subprocess-injection.yaml +163 -0
- package/rules/semgrep/taint-go.yaml +333 -0
- package/rules/semgrep/taint-java.yaml +317 -0
- package/rules/semgrep/taint-javascript.yaml +412 -0
- package/rules/semgrep/taint-php.yaml +361 -0
- package/rules/semgrep/taint-python.yaml +414 -0
- package/rules/semgrep/tool-endpoint-admin-client.yaml +86 -0
- package/rules/semgrep/user-metadata-authz.yaml +22 -0
- package/rules/semgrep/verify-result-unused.yaml +62 -0
- package/rules/semgrep/webhook-parse-before-verify.yaml +29 -0
- package/rules/test-artifact-ids.json +4 -0
- package/rules/tiers.json +427 -0
- package/schemas/check-results.schema.json +55 -0
- package/schemas/check.schema.json +41 -0
- package/schemas/codemap.schema.json +216 -0
- package/schemas/findings.schema.json +1048 -0
- package/schemas/hunt-output.schema.json +46 -0
- package/schemas/hunt-result.schema.json +58 -0
- package/schemas/results.schema.json +17 -0
- package/schemas/scan-hits.schema.json +32 -0
- package/schemas/scan-meta.schema.json +25 -0
- package/schemas/stack.schema.json +93 -0
- package/src/checks/README.md +32 -0
- package/src/checks/code/admin-role.ts +49 -0
- package/src/checks/code/owner-filter.ts +95 -0
- package/src/checks/code/shared.ts +66 -0
- package/src/checks/code/webhook-verify.ts +75 -0
- package/src/checks/context.ts +72 -0
- package/src/checks/map/config-checks.ts +79 -0
- package/src/checks/map/entry-checks.ts +116 -0
- package/src/checks/map/shared.ts +63 -0
- package/src/checks/ops.ts +280 -0
- package/src/checks/pro-map.ts +4 -0
- package/src/checks/run.ts +80 -0
- package/src/checks/types.ts +12 -0
- package/src/ci/comment.ts +52 -0
- package/src/ci/sarif-check.ts +100 -0
- package/src/ci/sarif.ts +72 -0
- package/src/cli.ts +273 -0
- package/src/commands/ci.ts +104 -0
- package/src/commands/git.ts +59 -0
- package/src/commands/hooks.ts +27 -0
- package/src/commands/hunt-pro.ts +4 -0
- package/src/commands/hunt.ts +68 -0
- package/src/commands/map.ts +27 -0
- package/src/commands/mcp.ts +18 -0
- package/src/commands/pack.ts +34 -0
- package/src/commands/prove-pro.ts +4 -0
- package/src/commands/prove.ts +126 -0
- package/src/commands/report-gate.ts +75 -0
- package/src/commands/scan.ts +156 -0
- package/src/confirm/agreement.ts +23 -0
- package/src/confirm/chain.ts +67 -0
- package/src/confirm/confirm.ts +107 -0
- package/src/confirm/honesty.ts +65 -0
- package/src/confirm/lead.ts +76 -0
- package/src/confirm/merge.ts +89 -0
- package/src/confirm/query.ts +126 -0
- package/src/confirm/rule.ts +76 -0
- package/src/confirm/store.ts +42 -0
- package/src/confirm/summary.ts +9 -0
- package/src/confirm/synthesis.ts +33 -0
- package/src/discover/detectors.ts +71 -0
- package/src/discover/discover.ts +253 -0
- package/src/discover/extract.ts +235 -0
- package/src/discover/git.ts +31 -0
- package/src/discover/kit-files.ts +37 -0
- package/src/discover/walk.ts +88 -0
- package/src/env.ts +51 -0
- package/src/gate/gate.ts +169 -0
- package/src/hooks/install.ts +142 -0
- package/src/hooks/run.ts +121 -0
- package/src/map/analyze.ts +219 -0
- package/src/map/build.ts +206 -0
- package/src/map/candidates.ts +47 -0
- package/src/map/cblocks.ts +55 -0
- package/src/map/config.ts +207 -0
- package/src/map/dotnet.ts +205 -0
- package/src/map/entry.ts +80 -0
- package/src/map/expo.ts +171 -0
- package/src/map/go.ts +271 -0
- package/src/map/js-express.ts +135 -0
- package/src/map/js-misc.ts +221 -0
- package/src/map/js-next.ts +282 -0
- package/src/map/laravel.ts +327 -0
- package/src/map/lex-more.ts +152 -0
- package/src/map/lex.ts +274 -0
- package/src/map/light-index.ts +134 -0
- package/src/map/light-profiles.ts +363 -0
- package/src/map/light.ts +484 -0
- package/src/map/local-vocab.ts +30 -0
- package/src/map/mobile.ts +263 -0
- package/src/map/py-django.ts +239 -0
- package/src/map/py.ts +329 -0
- package/src/map/rails.ts +291 -0
- package/src/map/repo.ts +150 -0
- package/src/map/rust.ts +256 -0
- package/src/map/spring.ts +185 -0
- package/src/map/taint.ts +86 -0
- package/src/map/touches.ts +296 -0
- package/src/map/vocab.ts +106 -0
- package/src/mapping/controls.ts +47 -0
- package/src/mapping/dependency-policy.ts +55 -0
- package/src/mapping/map.ts +59 -0
- package/src/mapping/maps/gitleaks.json +12 -0
- package/src/mapping/maps/osv-scanner.json +7 -0
- package/src/mapping/maps/trivy.json +13 -0
- package/src/mcp/confine.ts +44 -0
- package/src/mcp/protocol.ts +144 -0
- package/src/mcp/schema.ts +35 -0
- package/src/mcp/server.ts +32 -0
- package/src/mcp/tools.ts +235 -0
- package/src/packs/coverage.ts +98 -0
- package/src/packs/manifest.ts +97 -0
- package/src/packs/validate.ts +204 -0
- package/src/prove/container.ts +237 -0
- package/src/prove/exec-main.ts +16 -0
- package/src/prove/executor.ts +130 -0
- package/src/prove/local.ts +100 -0
- package/src/prove/probes.ts +68 -0
- package/src/prove/recipe.ts +215 -0
- package/src/prove/run.ts +124 -0
- package/src/prove/runner.ts +28 -0
- package/src/prove/safety.ts +98 -0
- package/src/prove/spec.ts +256 -0
- package/src/prove/store.ts +48 -0
- package/src/report/build.ts +304 -0
- package/src/report/entry-points.ts +78 -0
- package/src/report/hunt-section.ts +67 -0
- package/src/report/kit.ts +59 -0
- package/src/report/load.ts +49 -0
- package/src/report/messages.ts +270 -0
- package/src/report/prove-section.ts +61 -0
- package/src/report/report.ts +160 -0
- package/src/report/surface.ts +32 -0
- package/src/report/test-code.ts +56 -0
- package/src/report/tiers.ts +50 -0
- package/src/scanners/common.ts +149 -0
- package/src/scanners/gitleaks.ts +89 -0
- package/src/scanners/index.ts +103 -0
- package/src/scanners/osv-scanner.ts +90 -0
- package/src/scanners/run-targets.ts +35 -0
- package/src/scanners/secret-noise.ts +80 -0
- package/src/scanners/semgrep.ts +139 -0
- package/src/scanners/trivy.ts +66 -0
- package/src/scanners/types.ts +98 -0
- package/src/types/check.ts +52 -0
- package/src/types/codemap.ts +142 -0
- package/src/types/findings.ts +107 -0
- package/src/types/hunt.ts +97 -0
- package/src/types/index.ts +10 -0
- package/src/types/prove.ts +83 -0
- package/src/types/results.ts +15 -0
- package/src/types/scan.ts +63 -0
- package/src/types/stack.ts +61 -0
- package/src/util.ts +59 -0
- 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
|
+
}
|