deployready 0.2.0 → 0.4.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/README.md +166 -40
- package/SECURITY.md +34 -0
- package/dist/active/accessControl.js +62 -10
- package/dist/active/accessControl.js.map +1 -1
- package/dist/active/httpAdapter.js +13 -6
- package/dist/active/httpAdapter.js.map +1 -1
- package/dist/active/mutationProbe.js +132 -0
- package/dist/active/mutationProbe.js.map +1 -0
- package/dist/active/requestPlan.js +52 -26
- package/dist/active/requestPlan.js.map +1 -1
- package/dist/active/runner.js +121 -23
- package/dist/active/runner.js.map +1 -1
- package/dist/active/scope.js +74 -0
- package/dist/active/scope.js.map +1 -0
- package/dist/active/tamper.js +17 -4
- package/dist/active/tamper.js.map +1 -1
- package/dist/agent/FileEditor.js +122 -20
- package/dist/agent/FileEditor.js.map +1 -1
- package/dist/agent/FixManager.js +120 -6
- package/dist/agent/FixManager.js.map +1 -1
- package/dist/agent/context.js +199 -0
- package/dist/agent/context.js.map +1 -0
- package/dist/agent/fixPrompt.js +31 -0
- package/dist/agent/fixPrompt.js.map +1 -0
- package/dist/ai/CliHandler.js +80 -0
- package/dist/ai/CliHandler.js.map +1 -0
- package/dist/ai/ModelRouter.js +45 -4
- package/dist/ai/ModelRouter.js.map +1 -1
- package/dist/ai/PromptBuilder.js +7 -3
- package/dist/ai/PromptBuilder.js.map +1 -1
- package/dist/ai/cli/argv.js +67 -0
- package/dist/ai/cli/argv.js.map +1 -0
- package/dist/ai/cli/env.js +46 -0
- package/dist/ai/cli/env.js.map +1 -0
- package/dist/ai/cli/errors.js +15 -0
- package/dist/ai/cli/errors.js.map +1 -0
- package/dist/ai/cli/parseOutput.js +151 -0
- package/dist/ai/cli/parseOutput.js.map +1 -0
- package/dist/ai/cli/providers.js +30 -0
- package/dist/ai/cli/providers.js.map +1 -0
- package/dist/ai/cli/ready.js +121 -0
- package/dist/ai/cli/ready.js.map +1 -0
- package/dist/ai/cli/resolve.js +108 -0
- package/dist/ai/cli/resolve.js.map +1 -0
- package/dist/ai/cli/runCli.js +265 -0
- package/dist/ai/cli/runCli.js.map +1 -0
- package/dist/ai/parseAiResponse.js +24 -11
- package/dist/ai/parseAiResponse.js.map +1 -1
- package/dist/ai/verifyAiFindings.js +106 -0
- package/dist/ai/verifyAiFindings.js.map +1 -0
- package/dist/analysis/ScoreCalculator.js +22 -2
- package/dist/analysis/ScoreCalculator.js.map +1 -1
- package/dist/analysis/SeverityScorer.js +7 -1
- package/dist/analysis/SeverityScorer.js.map +1 -1
- package/dist/analysis/VulnerabilityDetector.js +271 -41
- package/dist/analysis/VulnerabilityDetector.js.map +1 -1
- package/dist/analysis/idor.js +261 -0
- package/dist/analysis/idor.js.map +1 -0
- package/dist/analysis/rls.js +81 -15
- package/dist/analysis/rls.js.map +1 -1
- package/dist/analysis/routeAuth.js +93 -0
- package/dist/analysis/routeAuth.js.map +1 -0
- package/dist/analysis/rules.js +98 -2
- package/dist/analysis/rules.js.map +1 -1
- package/dist/cli/Commands.js +75 -6
- package/dist/cli/Commands.js.map +1 -1
- package/dist/cli/InteractiveShell.js +149 -28
- package/dist/cli/InteractiveShell.js.map +1 -1
- package/dist/cli/Onboarding.js +13 -1
- package/dist/cli/Onboarding.js.map +1 -1
- package/dist/cli/cliSetup.js +48 -0
- package/dist/cli/cliSetup.js.map +1 -0
- package/dist/config/ConfigManager.js +11 -0
- package/dist/config/ConfigManager.js.map +1 -1
- package/dist/core/CiGate.js +38 -16
- package/dist/core/CiGate.js.map +1 -1
- package/dist/core/Orchestrator.js +207 -25
- package/dist/core/Orchestrator.js.map +1 -1
- package/dist/core/Verifier.js +239 -15
- package/dist/core/Verifier.js.map +1 -1
- package/dist/dynamic/APIAnalyzer.js +5 -0
- package/dist/dynamic/APIAnalyzer.js.map +1 -1
- package/dist/dynamic/DynamicTester.js +92 -8
- package/dist/dynamic/DynamicTester.js.map +1 -1
- package/dist/dynamic/EndpointMapper.js +54 -24
- package/dist/dynamic/EndpointMapper.js.map +1 -1
- package/dist/dynamic/LocalhostDetector.js +11 -23
- package/dist/dynamic/LocalhostDetector.js.map +1 -1
- package/dist/dynamic/PerformanceTester.js +12 -0
- package/dist/dynamic/PerformanceTester.js.map +1 -1
- package/dist/dynamic/SecurityTester.js +100 -11
- package/dist/dynamic/SecurityTester.js.map +1 -1
- package/dist/dynamic/adminEvidence.js +47 -0
- package/dist/dynamic/adminEvidence.js.map +1 -0
- package/dist/dynamic/advertised.js +293 -0
- package/dist/dynamic/advertised.js.map +1 -0
- package/dist/dynamic/catchAll.js +57 -0
- package/dist/dynamic/catchAll.js.map +1 -0
- package/dist/dynamic/commonPaths/evidence.js +112 -0
- package/dist/dynamic/commonPaths/evidence.js.map +1 -0
- package/dist/dynamic/commonPaths/prober.js +217 -0
- package/dist/dynamic/commonPaths/prober.js.map +1 -0
- package/dist/dynamic/commonPaths/signatures.js +381 -0
- package/dist/dynamic/commonPaths/signatures.js.map +1 -0
- package/dist/dynamic/proof.js +79 -0
- package/dist/dynamic/proof.js.map +1 -0
- package/dist/firebase/conditions.js +61 -0
- package/dist/firebase/conditions.js.map +1 -0
- package/dist/firebase/index.js +31 -0
- package/dist/firebase/index.js.map +1 -0
- package/dist/firebase/rtdbParser.js +96 -0
- package/dist/firebase/rtdbParser.js.map +1 -0
- package/dist/firebase/rules.js +171 -0
- package/dist/firebase/rules.js.map +1 -0
- package/dist/firebase/rulesParser.js +193 -0
- package/dist/firebase/rulesParser.js.map +1 -0
- package/dist/firebase/static.js +179 -0
- package/dist/firebase/static.js.map +1 -0
- package/dist/mcp/analyzeFix.js +62 -0
- package/dist/mcp/analyzeFix.js.map +1 -0
- package/dist/mcp/fixes.js +69 -0
- package/dist/mcp/fixes.js.map +1 -0
- package/dist/mcp/readiness.js +21 -0
- package/dist/mcp/readiness.js.map +1 -0
- package/dist/mcp/server.js +77 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/supabase.js +65 -0
- package/dist/mcp/supabase.js.map +1 -0
- package/dist/mcp/tools.js +186 -0
- package/dist/mcp/tools.js.map +1 -0
- package/dist/parser/CodeParser.js +138 -28
- package/dist/parser/CodeParser.js.map +1 -1
- package/dist/parser/adapters/BabelAdapter.js +558 -27
- package/dist/parser/adapters/BabelAdapter.js.map +1 -1
- package/dist/parser/adapters/PythonAdapter.js +360 -14
- package/dist/parser/adapters/PythonAdapter.js.map +1 -1
- package/dist/parser/adapters/authMiddleware.js +256 -0
- package/dist/parser/adapters/authMiddleware.js.map +1 -0
- package/dist/parser/adapters/nest.js +162 -0
- package/dist/parser/adapters/nest.js.map +1 -0
- package/dist/parser/miniYaml.js +308 -0
- package/dist/parser/miniYaml.js.map +1 -0
- package/dist/parser/nextRoutes.js +204 -0
- package/dist/parser/nextRoutes.js.map +1 -0
- package/dist/parser/openapi.js +180 -0
- package/dist/parser/openapi.js.map +1 -0
- package/dist/parser/pathUtil.js +22 -0
- package/dist/parser/pathUtil.js.map +1 -0
- package/dist/supabase/guard.js +95 -0
- package/dist/supabase/guard.js.map +1 -0
- package/dist/supabase/http.js +113 -0
- package/dist/supabase/http.js.map +1 -0
- package/dist/supabase/index.js +156 -0
- package/dist/supabase/index.js.map +1 -0
- package/dist/supabase/keys.js +56 -0
- package/dist/supabase/keys.js.map +1 -0
- package/dist/supabase/live.js +397 -0
- package/dist/supabase/live.js.map +1 -0
- package/dist/supabase/static.js +213 -0
- package/dist/supabase/static.js.map +1 -0
- package/dist/ui/ExportManager.js +71 -3
- package/dist/ui/ExportManager.js.map +1 -1
- package/dist/ui/HtmlReporter.js +78 -5
- package/dist/ui/HtmlReporter.js.map +1 -1
- package/dist/ui/IssuePresenter.js +68 -5
- package/dist/ui/IssuePresenter.js.map +1 -1
- package/dist/ui/Sarif.js +101 -0
- package/dist/ui/Sarif.js.map +1 -0
- package/dist/ui/badge.js +60 -0
- package/dist/ui/badge.js.map +1 -0
- package/dist/ui/commonPathSection.js +42 -0
- package/dist/ui/commonPathSection.js.map +1 -0
- package/dist/utils/FileWalker.js +128 -16
- package/dist/utils/FileWalker.js.map +1 -1
- package/dist/utils/GitIgnore.js +162 -0
- package/dist/utils/GitIgnore.js.map +1 -0
- package/dist/utils/finding.js +5 -0
- package/dist/utils/finding.js.map +1 -1
- package/dist/utils/logger.js +4 -0
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/redact.js +2 -1
- package/dist/utils/redact.js.map +1 -1
- package/dist/utils/sanitize.js +30 -0
- package/dist/utils/sanitize.js.map +1 -0
- package/docs/sample-config.json +2 -1
- package/package.json +18 -6
- package/skills/deployready/SKILL.md +55 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.verifyAiFindings = verifyAiFindings;
|
|
37
|
+
exports.droppedNote = droppedNote;
|
|
38
|
+
/**
|
|
39
|
+
* Model output is untrusted. Before an AI finding is merged it is checked
|
|
40
|
+
* against the real project (its `file` must be an existing regular file inside
|
|
41
|
+
* the scanned root, file contents are never read), its model-suggested severity
|
|
42
|
+
* is demoted to info (the suggestion stays visible in the description), and it
|
|
43
|
+
* is labelled unverified so it can never affect the score or the CI gate.
|
|
44
|
+
*/
|
|
45
|
+
const fs = __importStar(require("fs/promises"));
|
|
46
|
+
const path = __importStar(require("path"));
|
|
47
|
+
async function verifyAiFindings(findings, projectRoot) {
|
|
48
|
+
let realRoot = null;
|
|
49
|
+
try {
|
|
50
|
+
realRoot = await fs.realpath(path.resolve(projectRoot));
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
realRoot = null;
|
|
54
|
+
}
|
|
55
|
+
const kept = [];
|
|
56
|
+
let dropped = 0;
|
|
57
|
+
for (const f of findings) {
|
|
58
|
+
let file = f.file || undefined;
|
|
59
|
+
if (file !== undefined) {
|
|
60
|
+
const rel = realRoot ? await resolveInsideRoot(realRoot, file) : null;
|
|
61
|
+
if (rel === null) {
|
|
62
|
+
dropped++;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
file = rel;
|
|
66
|
+
}
|
|
67
|
+
kept.push({
|
|
68
|
+
...f,
|
|
69
|
+
file,
|
|
70
|
+
source: 'ai',
|
|
71
|
+
severity: 'info',
|
|
72
|
+
unverified: true,
|
|
73
|
+
description: `AI-suggested severity: ${f.severity}. ${f.description}`.trim(),
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return { findings: kept, dropped };
|
|
77
|
+
}
|
|
78
|
+
function droppedNote(dropped) {
|
|
79
|
+
return `${dropped} AI finding(s) dropped: referenced file not found`;
|
|
80
|
+
}
|
|
81
|
+
/** Returns the forward-slash path relative to root if `file` is an existing regular file inside it, else null. */
|
|
82
|
+
async function resolveInsideRoot(realRoot, file) {
|
|
83
|
+
if (!file || file.includes('\0'))
|
|
84
|
+
return null;
|
|
85
|
+
if (path.isAbsolute(file) || path.win32.isAbsolute(file) || path.posix.isAbsolute(file))
|
|
86
|
+
return null;
|
|
87
|
+
const lexical = path.resolve(realRoot, file);
|
|
88
|
+
if (!isInside(realRoot, lexical))
|
|
89
|
+
return null;
|
|
90
|
+
try {
|
|
91
|
+
const real = await fs.realpath(lexical);
|
|
92
|
+
if (!isInside(realRoot, real))
|
|
93
|
+
return null;
|
|
94
|
+
if (!(await fs.stat(real)).isFile())
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return path.relative(realRoot, lexical).split(path.sep).join('/');
|
|
101
|
+
}
|
|
102
|
+
function isInside(root, target) {
|
|
103
|
+
const rel = path.relative(root, target);
|
|
104
|
+
return rel !== '' && rel !== '..' && !rel.startsWith('..' + path.sep) && !path.isAbsolute(rel);
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=verifyAiFindings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verifyAiFindings.js","sourceRoot":"","sources":["../../src/ai/verifyAiFindings.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,23 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ScoreCalculator = void 0;
|
|
4
|
+
exports.isUnverified = isUnverified;
|
|
5
|
+
exports.isNote = isNote;
|
|
6
|
+
exports.isNonScored = isNonScored;
|
|
4
7
|
const WEIGHT = { critical: 10, warning: 3, info: 1 };
|
|
5
8
|
/** Decay constant: penalty == K gives a 50/100 score. */
|
|
6
9
|
const K = 30;
|
|
10
|
+
/** Model output is never trusted: any AI-sourced finding is unverified. */
|
|
11
|
+
function isUnverified(f) {
|
|
12
|
+
return f.unverified === true || f.source === 'ai';
|
|
13
|
+
}
|
|
14
|
+
function isNote(f) {
|
|
15
|
+
return f.note === true;
|
|
16
|
+
}
|
|
17
|
+
/** Findings that are displayed but never scored, gated on, or baselined. */
|
|
18
|
+
function isNonScored(f) {
|
|
19
|
+
return isUnverified(f) || isNote(f);
|
|
20
|
+
}
|
|
7
21
|
class ScoreCalculator {
|
|
8
22
|
static summarize(findings) {
|
|
9
23
|
let critical = 0;
|
|
10
24
|
let warning = 0;
|
|
11
25
|
let info = 0;
|
|
26
|
+
let unverified = 0;
|
|
27
|
+
let notes = 0;
|
|
12
28
|
for (const f of findings) {
|
|
13
|
-
if (f
|
|
29
|
+
if (isUnverified(f))
|
|
30
|
+
unverified++;
|
|
31
|
+
else if (isNote(f))
|
|
32
|
+
notes++;
|
|
33
|
+
else if (f.severity === 'critical')
|
|
14
34
|
critical++;
|
|
15
35
|
else if (f.severity === 'warning')
|
|
16
36
|
warning++;
|
|
17
37
|
else
|
|
18
38
|
info++;
|
|
19
39
|
}
|
|
20
|
-
return { critical, warning, info, total:
|
|
40
|
+
return { critical, warning, info, total: critical + warning + info, unverified, notes };
|
|
21
41
|
}
|
|
22
42
|
static calculate(summary) {
|
|
23
43
|
const penalty = summary.critical * WEIGHT.critical + summary.warning * WEIGHT.warning + summary.info * WEIGHT.info;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ScoreCalculator.js","sourceRoot":"","sources":["../../src/analysis/ScoreCalculator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"ScoreCalculator.js","sourceRoot":"","sources":["../../src/analysis/ScoreCalculator.ts"],"names":[],"mappings":";;;AA+BA,oCAEC;AAED,wBAEC;AAGD,kCAEC;AA5BD,MAAM,MAAM,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAW,CAAC;AAC9D,yDAAyD;AACzD,MAAM,CAAC,GAAG,EAAE,CAAC;AAcb,2EAA2E;AAC3E,SAAgB,YAAY,CAAC,CAAyC;IACpE,OAAO,CAAC,CAAC,UAAU,KAAK,IAAI,IAAI,CAAC,CAAC,MAAM,KAAK,IAAI,CAAC;AACpD,CAAC;AAED,SAAgB,MAAM,CAAC,CAAwB;IAC7C,OAAO,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC;AACzB,CAAC;AAED,4EAA4E;AAC5E,SAAgB,WAAW,CAAC,CAAkD;IAC5E,OAAO,YAAY,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;AACtC,CAAC;AAED,MAAa,eAAe;IAC1B,MAAM,CAAC,SAAS,CAAC,QAAmB;QAClC,IAAI,QAAQ,GAAG,CAAC,CAAC;QACjB,IAAI,OAAO,GAAG,CAAC,CAAC;QAChB,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,IAAI,UAAU,GAAG,CAAC,CAAC;QACnB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;YACzB,IAAI,YAAY,CAAC,CAAC,CAAC;gBAAE,UAAU,EAAE,CAAC;iBAC7B,IAAI,MAAM,CAAC,CAAC,CAAC;gBAAE,KAAK,EAAE,CAAC;iBACvB,IAAI,CAAC,CAAC,QAAQ,KAAK,UAAU;gBAAE,QAAQ,EAAE,CAAC;iBAC1C,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS;gBAAE,OAAO,EAAE,CAAC;;gBACxC,IAAI,EAAE,CAAC;QACd,CAAC;QACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,GAAG,OAAO,GAAG,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IAC1F,CAAC;IAED,MAAM,CAAC,SAAS,CAAC,OAAqB;QACpC,MAAM,OAAO,GACX,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACrG,IAAI,OAAO,IAAI,CAAC;YAAE,OAAO,GAAG,CAAC;QAC7B,mEAAmE;QACnE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC;CACF;AAxBD,0CAwBC"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SeverityScorer = void 0;
|
|
4
|
-
const
|
|
4
|
+
const ScoreCalculator_1 = require("./ScoreCalculator");
|
|
5
|
+
const ALWAYS_CRITICAL = new Set(['hardcoded-secret', 'sql-injection', 'command-injection']);
|
|
5
6
|
class SeverityScorer {
|
|
6
7
|
static apply(findings) {
|
|
7
8
|
return findings.map((f) => {
|
|
9
|
+
if ((0, ScoreCalculator_1.isNote)(f) && !(0, ScoreCalculator_1.isUnverified)(f))
|
|
10
|
+
return f;
|
|
11
|
+
if ((0, ScoreCalculator_1.isUnverified)(f)) {
|
|
12
|
+
return f.severity === 'info' && f.unverified === true ? f : { ...f, severity: 'info', unverified: true };
|
|
13
|
+
}
|
|
8
14
|
const severity = ALWAYS_CRITICAL.has(f.rule) ? 'critical' : f.severity;
|
|
9
15
|
return severity === f.severity ? f : { ...f, severity };
|
|
10
16
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SeverityScorer.js","sourceRoot":"","sources":["../../src/analysis/SeverityScorer.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SeverityScorer.js","sourceRoot":"","sources":["../../src/analysis/SeverityScorer.ts"],"names":[],"mappings":";;;AAMA,uDAAyD;AAEzD,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,kBAAkB,EAAE,eAAe,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAE5F,MAAa,cAAc;IACzB,MAAM,CAAC,KAAK,CAAC,QAAmB;QAC9B,OAAO,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YACxB,IAAI,IAAA,wBAAM,EAAC,CAAC,CAAC,IAAI,CAAC,IAAA,8BAAY,EAAC,CAAC,CAAC;gBAAE,OAAO,CAAC,CAAC;YAC5C,IAAI,IAAA,8BAAY,EAAC,CAAC,CAAC,EAAE,CAAC;gBACpB,OAAO,CAAC,CAAC,QAAQ,KAAK,MAAM,IAAI,CAAC,CAAC,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;YAC3G,CAAC;YACD,MAAM,QAAQ,GAAa,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;YACjF,OAAO,QAAQ,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;QAC1D,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,CAAW;QACrB,OAAO,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC;CACF;AAfD,wCAeC"}
|
|
@@ -42,11 +42,18 @@ exports.VulnerabilityDetector = void 0;
|
|
|
42
42
|
* const findings = await VulnerabilityDetector.scan('/path/to/project');
|
|
43
43
|
*/
|
|
44
44
|
const path = __importStar(require("path"));
|
|
45
|
+
const child_process_1 = require("child_process");
|
|
45
46
|
const FileWalker_1 = require("../utils/FileWalker");
|
|
46
47
|
const redact_1 = require("../utils/redact");
|
|
47
48
|
const finding_1 = require("../utils/finding");
|
|
48
49
|
const rules_1 = require("./rules");
|
|
50
|
+
const CodeParser_1 = require("../parser/CodeParser");
|
|
51
|
+
const routeAuth_1 = require("./routeAuth");
|
|
52
|
+
const idor_1 = require("./idor");
|
|
49
53
|
const rls_1 = require("./rls");
|
|
54
|
+
const WORKFLOW_FILE_RE = /^\.github\/workflows\/[^/]+\.ya?ml$/i;
|
|
55
|
+
// `${{ secrets.NAME }}` is the safe way to reference a secret in a workflow.
|
|
56
|
+
const ACTIONS_SECRET_REF_RE = /\$\{\{\s*secrets\.[A-Za-z0-9_]+\s*\}\}/g;
|
|
50
57
|
class VulnerabilityDetector {
|
|
51
58
|
static async scan(projectPath) {
|
|
52
59
|
const files = await FileWalker_1.FileWalker.walk(projectPath);
|
|
@@ -55,6 +62,9 @@ class VulnerabilityDetector {
|
|
|
55
62
|
let gitignoreText = '';
|
|
56
63
|
const envFiles = [];
|
|
57
64
|
const sqlFiles = [];
|
|
65
|
+
let supabase = false;
|
|
66
|
+
const codeSources = new Map();
|
|
67
|
+
let ownershipModel = false;
|
|
58
68
|
for (const file of files) {
|
|
59
69
|
const base = path.basename(file.relPath);
|
|
60
70
|
if (base === '.gitignore') {
|
|
@@ -65,8 +75,9 @@ class VulnerabilityDetector {
|
|
|
65
75
|
// .env files are WHERE secrets are supposed to live. Don't scan their
|
|
66
76
|
// contents (every line would false-positive as a "hardcoded secret").
|
|
67
77
|
// The only real risk is whether they're gitignored — handled below.
|
|
68
|
-
if (
|
|
69
|
-
|
|
78
|
+
if ((0, FileWalker_1.isEnvFile)(base)) {
|
|
79
|
+
if (!(0, FileWalker_1.isEnvTemplate)(base))
|
|
80
|
+
envFiles.push(file.relPath);
|
|
70
81
|
continue;
|
|
71
82
|
}
|
|
72
83
|
const source = await safeRead(file);
|
|
@@ -74,47 +85,140 @@ class VulnerabilityDetector {
|
|
|
74
85
|
continue;
|
|
75
86
|
if (path.extname(file.relPath).toLowerCase() === '.sql') {
|
|
76
87
|
sqlFiles.push({ relPath: file.relPath, source });
|
|
88
|
+
if (SUPABASE_DIR_RE.test(file.relPath))
|
|
89
|
+
supabase = true;
|
|
77
90
|
}
|
|
91
|
+
else if (base === 'package.json' && /["']@supabase\/(?:supabase-js|ssr)["']/.test(source)) {
|
|
92
|
+
supabase = true;
|
|
93
|
+
}
|
|
94
|
+
else if (/^requirements[^/]*\.txt$/i.test(base) && /^supabase\b/im.test(source)) {
|
|
95
|
+
supabase = true;
|
|
96
|
+
}
|
|
97
|
+
else if (/(^|\/)supabase\/config\.toml$/.test(file.relPath)) {
|
|
98
|
+
supabase = true;
|
|
99
|
+
}
|
|
100
|
+
if (ROUTE_SOURCE_RE.test(file.relPath))
|
|
101
|
+
codeSources.set(file.relPath, source);
|
|
102
|
+
if (!ownershipModel && OWNERSHIP_SOURCE_RE.test(file.relPath))
|
|
103
|
+
ownershipModel = idor_1.OWNERSHIP_MODEL_RE.test(source);
|
|
78
104
|
VulnerabilityDetector.scanLines(file.relPath, source, findings);
|
|
79
105
|
}
|
|
80
|
-
VulnerabilityDetector.projectChecks(envFiles, sawGitignore, gitignoreText, findings);
|
|
81
|
-
VulnerabilityDetector.rlsChecks(sqlFiles, findings);
|
|
106
|
+
VulnerabilityDetector.projectChecks(projectPath, envFiles, sawGitignore, gitignoreText, findings);
|
|
107
|
+
VulnerabilityDetector.rlsChecks(sqlFiles, supabase, findings);
|
|
108
|
+
await VulnerabilityDetector.routeAuthChecks(projectPath, codeSources, findings, ownershipModel);
|
|
82
109
|
return findings;
|
|
83
110
|
}
|
|
84
|
-
/** Flag
|
|
85
|
-
static
|
|
86
|
-
|
|
111
|
+
/** Flag DELETE / admin / data-changing routes that have no auth guard anywhere we can see. */
|
|
112
|
+
static async routeAuthChecks(projectPath, sources, out, ownershipModel) {
|
|
113
|
+
let routes;
|
|
114
|
+
try {
|
|
115
|
+
routes = (await CodeParser_1.CodeParser.analyze(projectPath)).routes;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return; // route discovery is best-effort; never fail the static scan over it
|
|
119
|
+
}
|
|
120
|
+
for (const u of (0, routeAuth_1.unauthenticatedRoutes)(routes, sources)) {
|
|
121
|
+
const { method, path: routePath, file, line } = u.route;
|
|
122
|
+
const what = u.reason === 'admin' ? 'Admin route' : 'Route';
|
|
87
123
|
out.push((0, finding_1.makeFinding)({
|
|
88
|
-
rule: '
|
|
89
|
-
|
|
90
|
-
|
|
124
|
+
rule: 'missing-auth-route',
|
|
125
|
+
// The route itself is in the description: the report already shows file:line, and a
|
|
126
|
+
// dynamic finding for the same path keeps its own "METHOD path" line.
|
|
127
|
+
title: u.reason === 'mutating'
|
|
128
|
+
? `${what} changes data with no auth check`
|
|
129
|
+
: `${what} ${u.reason === 'admin' ? 'is reachable' : 'deletes data'} with no auth check`,
|
|
130
|
+
severity: u.severity,
|
|
91
131
|
category: 'security',
|
|
92
132
|
source: 'static',
|
|
93
|
-
file
|
|
94
|
-
line
|
|
133
|
+
file,
|
|
134
|
+
line,
|
|
95
135
|
owasp: 'A01:2025',
|
|
96
|
-
cwe: 'CWE-
|
|
97
|
-
description: `
|
|
98
|
-
recommendation:
|
|
136
|
+
cwe: 'CWE-306',
|
|
137
|
+
description: `No authentication middleware, dependency or in-handler check was found for ${method.toUpperCase()} ${routePath} in ${file}, so anyone who can reach the server can call it.`,
|
|
138
|
+
recommendation: 'Require an authenticated user before the handler runs (e.g. router-level requireAuth middleware, FastAPI Depends(get_current_user), Flask @login_required, or a session check in the Next.js route), and for admin routes also check the role. If this endpoint is intentionally public, mark the finding as ignored.',
|
|
99
139
|
}));
|
|
100
140
|
}
|
|
141
|
+
VulnerabilityDetector.idorChecks(routes, sources, ownershipModel, out);
|
|
142
|
+
}
|
|
143
|
+
/** Flag authenticated handlers that load/change a record by URL id with no ownership scoping (IDOR). */
|
|
144
|
+
static idorChecks(routes, sources, ownershipModel, out) {
|
|
145
|
+
for (const i of (0, idor_1.idorIssues)(routes, sources, ownershipModel)) {
|
|
146
|
+
const { method, path: routePath, file } = i.route;
|
|
147
|
+
const verb = i.op === 'write' ? 'changes or deletes' : 'loads';
|
|
148
|
+
out.push((0, finding_1.makeFinding)({
|
|
149
|
+
rule: 'idor-missing-ownership-check',
|
|
150
|
+
title: i.op === 'write'
|
|
151
|
+
? 'Record changed by URL id with no ownership check (IDOR)'
|
|
152
|
+
: 'Record loaded by URL id with no ownership check (IDOR)',
|
|
153
|
+
severity: i.severity,
|
|
154
|
+
category: 'security',
|
|
155
|
+
source: 'static',
|
|
156
|
+
file,
|
|
157
|
+
line: i.line,
|
|
158
|
+
owasp: 'A01:2025',
|
|
159
|
+
cwe: 'CWE-639',
|
|
160
|
+
description: `${method.toUpperCase()} ${routePath} takes "${i.param}" from the request and ${verb} the record by that id alone. The handler knows who is signed in, but nothing compares the record's owner with that user or adds the user to the query, so any logged-in user can ${i.op === 'write' ? 'change or delete' : 'read'} another user's record by changing the id.`,
|
|
161
|
+
recommendation: "Scope the query to the signed-in user (e.g. where: { id, userId: user.id }, .eq('user_id', user.id), filter_by(id=item_id, owner_id=current_user.id)) or load the record and return 404/403 when its owner is not the caller. If any user is meant to reach any record, guard the route with an admin/role check or mark the finding as ignored. To prove it live, run `deployready --active --token <user A> --token-b <user B>`: it requests user A's object with user B's token.",
|
|
162
|
+
evidence: (0, redact_1.redact)(i.evidence).slice(0, 160),
|
|
163
|
+
}));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
/** Flag tables without RLS, RLS without policies, and wide-open policies. */
|
|
167
|
+
static rlsChecks(sqlFiles, supabase, out) {
|
|
168
|
+
for (const i of (0, rls_1.analyzeRls)(sqlFiles, { supabase }))
|
|
169
|
+
out.push(rlsFinding(i));
|
|
101
170
|
}
|
|
102
171
|
/** Apply per-line rules + secret detection to one file. */
|
|
103
172
|
static scanLines(relPath, source, out) {
|
|
104
173
|
const ext = path.extname(relPath).toLowerCase();
|
|
105
|
-
const
|
|
174
|
+
const isWorkflow = WORKFLOW_FILE_RE.test(relPath);
|
|
175
|
+
// Workflows get secret detection only: the line rules target app code and
|
|
176
|
+
// fire on CI config (e.g. a SUPABASE_SERVICE_ROLE_KEY variable name).
|
|
177
|
+
const rules = isWorkflow ? [] : rules_1.LINE_RULES.filter((r) => !r.exts || r.exts.includes(ext));
|
|
178
|
+
const priorityRules = rules.filter((r) => r.beforeSecrets);
|
|
179
|
+
const otherRules = rules.filter((r) => !r.beforeSecrets);
|
|
180
|
+
const ctx = (line) => ({ relPath, source, line });
|
|
181
|
+
const emitRule = (r, line, rawLine) => {
|
|
182
|
+
out.push((0, finding_1.makeFinding)({
|
|
183
|
+
rule: r.rule,
|
|
184
|
+
title: r.title,
|
|
185
|
+
severity: r.severity,
|
|
186
|
+
category: r.category,
|
|
187
|
+
source: 'static',
|
|
188
|
+
file: relPath,
|
|
189
|
+
line,
|
|
190
|
+
owasp: r.owasp,
|
|
191
|
+
cwe: r.cwe,
|
|
192
|
+
description: `${r.title} detected in ${relPath}:${line}.`,
|
|
193
|
+
recommendation: r.recommendation,
|
|
194
|
+
evidence: r.evidence ? (0, redact_1.redact)(rawLine.trim()).slice(0, 160) : undefined,
|
|
195
|
+
}));
|
|
196
|
+
};
|
|
106
197
|
const lines = source.split('\n');
|
|
198
|
+
// `const JWT_SECRET = 'literal'` later passed to jwt.sign(..., JWT_SECRET): the literal IS the signing key.
|
|
199
|
+
const jwtRule = priorityRules.find((r) => r.rule === 'jwt-hardcoded-secret');
|
|
200
|
+
const jwtKeys = jwtRule ? jwtKeyIdentifiers(source) : new Set();
|
|
107
201
|
// Cap per-file findings so a generated/minified file can't flood the report.
|
|
108
202
|
let perFile = 0;
|
|
109
203
|
const LIMIT = 50;
|
|
110
204
|
for (let i = 0; i < lines.length && perFile < LIMIT; i++) {
|
|
111
|
-
const
|
|
112
|
-
if (
|
|
205
|
+
const rawLine = lines[i];
|
|
206
|
+
if (rawLine.length > 4000)
|
|
113
207
|
continue;
|
|
208
|
+
const line = isWorkflow ? rawLine.replace(ACTIONS_SECRET_REF_RE, '') : rawLine;
|
|
209
|
+
// Specific secret-in-context rules (e.g. a literal JWT signing key) replace the generic
|
|
210
|
+
// secret finding for the same line, so one line never yields two findings.
|
|
211
|
+
const specific = priorityRules.find((r) => r.re && r.re.test(line) && !r.skip?.(ctx(line))) ??
|
|
212
|
+
(jwtRule && jwtKeys.size > 0 && declaresLiteral(line, jwtKeys) ? jwtRule : undefined);
|
|
213
|
+
if (specific) {
|
|
214
|
+
emitRule(specific, i + 1, rawLine);
|
|
215
|
+
perFile++;
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
114
218
|
// Secret detection first — highest signal. Two tiers: a matched key SHAPE
|
|
115
219
|
// is a critical (high confidence); a secret-NAMED literal is a warning
|
|
116
220
|
// (could be a placeholder/config value, so don't cry "critical").
|
|
117
|
-
const conf = (0, redact_1.detectSecret)(line);
|
|
221
|
+
const conf = lowConfidenceIsAssignedLiteral((0, redact_1.detectSecret)(withoutFirebaseWebKey(lines, i, line)), line, ext);
|
|
118
222
|
if (conf) {
|
|
119
223
|
const high = conf === 'high';
|
|
120
224
|
out.push((0, finding_1.makeFinding)({
|
|
@@ -135,27 +239,14 @@ class VulnerabilityDetector {
|
|
|
135
239
|
recommendation: high
|
|
136
240
|
? 'Move the secret to an environment variable or secret manager, rotate the exposed value immediately, and ensure it is gitignored.'
|
|
137
241
|
: 'If this is a real secret, move it to an environment variable and rotate it. If it is a non-sensitive config value or placeholder, mark this finding as ignored.',
|
|
138
|
-
evidence: (0, redact_1.redact)(
|
|
242
|
+
evidence: (0, redact_1.redact)(rawLine.trim()).slice(0, 160),
|
|
139
243
|
}));
|
|
140
244
|
perFile++;
|
|
141
245
|
continue;
|
|
142
246
|
}
|
|
143
|
-
for (const r of
|
|
144
|
-
if (r.re && r.re.test(line)) {
|
|
145
|
-
|
|
146
|
-
rule: r.rule,
|
|
147
|
-
title: r.title,
|
|
148
|
-
severity: r.severity,
|
|
149
|
-
category: r.category,
|
|
150
|
-
source: 'static',
|
|
151
|
-
file: relPath,
|
|
152
|
-
line: i + 1,
|
|
153
|
-
owasp: r.owasp,
|
|
154
|
-
cwe: r.cwe,
|
|
155
|
-
description: `${r.title} detected in ${relPath}:${i + 1}.`,
|
|
156
|
-
recommendation: r.recommendation,
|
|
157
|
-
evidence: r.evidence ? (0, redact_1.redact)(line.trim()).slice(0, 160) : undefined,
|
|
158
|
-
}));
|
|
247
|
+
for (const r of otherRules) {
|
|
248
|
+
if (r.re && r.re.test(line) && !r.skip?.(ctx(line))) {
|
|
249
|
+
emitRule(r, i + 1, rawLine);
|
|
159
250
|
perFile++;
|
|
160
251
|
break; // one rule hit per line is enough
|
|
161
252
|
}
|
|
@@ -163,27 +254,166 @@ class VulnerabilityDetector {
|
|
|
163
254
|
}
|
|
164
255
|
}
|
|
165
256
|
/** Project-wide checks that aren't tied to a single line. */
|
|
166
|
-
static projectChecks(envFiles, sawGitignore, gitignoreText, out) {
|
|
257
|
+
static projectChecks(projectPath, envFiles, sawGitignore, gitignoreText, out) {
|
|
167
258
|
for (const env of envFiles) {
|
|
168
259
|
const ignored = sawGitignore && /(^|\n)\s*\.env/.test(gitignoreText);
|
|
169
|
-
|
|
260
|
+
const { state: git, nested } = gitState(projectPath, env);
|
|
261
|
+
// Scanning a folder inside a larger repository (a monorepo package, a test fixture): when the
|
|
262
|
+
// folder's own .gitignore covers .env, treat it as a standalone project and stay quiet.
|
|
263
|
+
if (nested && ignored)
|
|
264
|
+
continue;
|
|
265
|
+
if (git === 'tracked' || git === 'history') {
|
|
170
266
|
out.push((0, finding_1.makeFinding)({
|
|
171
267
|
rule: 'env-not-ignored',
|
|
172
|
-
title: '.env file
|
|
268
|
+
title: git === 'tracked' ? '.env file is committed to git' : '.env file was committed to git history',
|
|
173
269
|
severity: 'critical',
|
|
174
270
|
category: 'security',
|
|
175
271
|
source: 'static',
|
|
176
272
|
file: env,
|
|
177
273
|
owasp: 'A02:2025',
|
|
178
274
|
cwe: 'CWE-538',
|
|
179
|
-
description:
|
|
180
|
-
|
|
275
|
+
description: git === 'tracked'
|
|
276
|
+
? `${env} is tracked by git, so its secrets are in version control and visible to everyone with access to the repository${ignored ? ' (adding it to .gitignore does not untrack a file that is already committed)' : ''}.`
|
|
277
|
+
: `${env} is not tracked now, but an earlier commit contains it, so its secrets are still readable in git history.`,
|
|
278
|
+
recommendation: git === 'tracked'
|
|
279
|
+
? 'Run `git rm --cached` on it, add `.env` to .gitignore, purge it from git history, and rotate every secret it contains.'
|
|
280
|
+
: 'Purge it from git history (e.g. git filter-repo) and rotate every secret it contained.',
|
|
281
|
+
}));
|
|
282
|
+
}
|
|
283
|
+
else if (!ignored) {
|
|
284
|
+
out.push((0, finding_1.makeFinding)({
|
|
285
|
+
rule: 'env-not-ignored',
|
|
286
|
+
title: '.env file is not gitignored',
|
|
287
|
+
severity: 'warning',
|
|
288
|
+
category: 'security',
|
|
289
|
+
source: 'static',
|
|
290
|
+
file: env,
|
|
291
|
+
owasp: 'A02:2025',
|
|
292
|
+
cwe: 'CWE-538',
|
|
293
|
+
description: git === 'untracked'
|
|
294
|
+
? `${env} is not tracked by git yet, but nothing in .gitignore excludes it, so a \`git add .\` would commit your secrets.`
|
|
295
|
+
: `${env} is not excluded by any .gitignore entry. No git repository was found here, so we cannot tell whether it has been committed; if you add this project to git, it would be included.`,
|
|
296
|
+
recommendation: 'Add `.env` to .gitignore before your first commit. If it was ever committed, remove it from git history and rotate any exposed secrets.',
|
|
181
297
|
}));
|
|
182
298
|
}
|
|
183
299
|
}
|
|
184
300
|
}
|
|
185
301
|
}
|
|
186
302
|
exports.VulnerabilityDetector = VulnerabilityDetector;
|
|
303
|
+
const JWT_KEY_ARG_RE = /\b(?:jwt|jsonwebtoken)\.(?:sign|verify|encode|decode)\s*\([^\n[\]]{0,300}?,\s*(?:key\s*=\s*)?([A-Za-z_$][\w$]*)\s*[,)]/g;
|
|
304
|
+
const LITERAL_DECL_RE = /^\s*(?:export\s+)?(?:(?:const|let|var)\s+)?([A-Za-z_$][\w$]*)\s*(?::\s*[\w.]+\s*)?=\s*(["'`])(?![^"'`\n]*\$\{)[^"'`\n]{3,}\2\s*;?\s*(?:#.*|\/\/.*)?$/;
|
|
305
|
+
/** Identifiers passed as the key argument of a JWT sign/verify call anywhere in the file. */
|
|
306
|
+
function jwtKeyIdentifiers(source) {
|
|
307
|
+
const ids = new Set();
|
|
308
|
+
for (const m of source.matchAll(JWT_KEY_ARG_RE))
|
|
309
|
+
ids.add(m[1]);
|
|
310
|
+
return ids;
|
|
311
|
+
}
|
|
312
|
+
/** True when the line assigns a plain string literal to one of `names`. */
|
|
313
|
+
function declaresLiteral(line, names) {
|
|
314
|
+
const m = LITERAL_DECL_RE.exec(line);
|
|
315
|
+
return Boolean(m && names.has(m[1]));
|
|
316
|
+
}
|
|
317
|
+
const GOOGLE_API_KEY_RE = /\bAIza[0-9A-Za-z_-]{35}\b/g;
|
|
318
|
+
const FIREBASE_CONFIG_KEY_RE = /\b(?:authDomain|projectId|appId|messagingSenderId|storageBucket|measurementId)\b/;
|
|
319
|
+
/**
|
|
320
|
+
* A Firebase web config (`apiKey: "AIza..."` next to authDomain/projectId/appId, or inside
|
|
321
|
+
* initializeApp(...)) is public by design: it ships to every browser and access is enforced by
|
|
322
|
+
* security rules. Returns the line with such a key removed, so only other secrets on it count;
|
|
323
|
+
* AIza keys anywhere else are still reported.
|
|
324
|
+
*/
|
|
325
|
+
function withoutFirebaseWebKey(lines, i, line) {
|
|
326
|
+
if (!GOOGLE_API_KEY_RE.test(line))
|
|
327
|
+
return line;
|
|
328
|
+
GOOGLE_API_KEY_RE.lastIndex = 0;
|
|
329
|
+
if (!/\bapi_?key\b|["']apiKey["']/i.test(line))
|
|
330
|
+
return line;
|
|
331
|
+
const near = lines.slice(Math.max(0, i - 8), i + 9).join('\n');
|
|
332
|
+
if (!FIREBASE_CONFIG_KEY_RE.test(near) && !/\binitializeApp\s*\(/.test(near))
|
|
333
|
+
return line;
|
|
334
|
+
return line.replace(GOOGLE_API_KEY_RE, '');
|
|
335
|
+
}
|
|
336
|
+
const ROUTE_SOURCE_RE = /\.(?:[cm]?[jt]sx?|py)$/i;
|
|
337
|
+
/** Files whose text can show that records have an owner (code and SQL). */
|
|
338
|
+
const OWNERSHIP_SOURCE_RE = /\.(?:[cm]?[jt]sx?|py|sql)$/i;
|
|
339
|
+
const CODE_EXTS = new Set(['.js', '.jsx', '.ts', '.tsx', '.mjs', '.cjs', '.py']);
|
|
340
|
+
const SECRET_NAMED_LITERAL_RE = /(?:secret|password|passwd|api[_-]?key|apikey|access[_-]?key|access[_-]?token|auth[_-]?token|client[_-]?secret|private[_-]?key|credential|token)[A-Za-z0-9_]*\s*(?::\s*[\w.[\]]+\s*)?[:=]\s*['"`]/i;
|
|
341
|
+
/**
|
|
342
|
+
* In code files a secret-NAMED value is only worth a warning when it is a quoted literal. Expressions
|
|
343
|
+
* like `const token = (req.headers.authorization || '')` or `token: str = Depends(oauth2)` are
|
|
344
|
+
* not hardcoded secrets. Known key shapes (high confidence) are never downgraded.
|
|
345
|
+
*/
|
|
346
|
+
function lowConfidenceIsAssignedLiteral(conf, line, ext) {
|
|
347
|
+
if (conf !== 'low' || !CODE_EXTS.has(ext))
|
|
348
|
+
return conf;
|
|
349
|
+
return SECRET_NAMED_LITERAL_RE.test(line) ? conf : null;
|
|
350
|
+
}
|
|
351
|
+
const SUPABASE_DIR_RE = /(^|\/)supabase\//;
|
|
352
|
+
function rlsFinding(i) {
|
|
353
|
+
const base = { category: 'security', source: 'static', file: i.file, line: i.line, owasp: 'A01:2025', cwe: 'CWE-285' };
|
|
354
|
+
if (i.kind === 'missing') {
|
|
355
|
+
return (0, finding_1.makeFinding)({
|
|
356
|
+
...base,
|
|
357
|
+
rule: 'rls-not-enabled',
|
|
358
|
+
title: `Table "${i.table}" created without Row-Level Security enabled`,
|
|
359
|
+
severity: 'warning',
|
|
360
|
+
description: i.rlsUsedElsewhere
|
|
361
|
+
? `Other tables in this project enable RLS, but "${i.table}" does not — if it is exposed through the API, any client holding the public key could read/write every row.`
|
|
362
|
+
: `This looks like a Supabase project (its tables are served by an auto-generated API that the public anon key can call), but RLS is not enabled on "${i.table}" or any other table in the SQL here — so anyone with your anon key can read/write every row. If you enable RLS from the dashboard instead of migrations, you can ignore this.`,
|
|
363
|
+
recommendation: `Enable RLS and add policies: ALTER TABLE ${i.table} ENABLE ROW LEVEL SECURITY; then define per-row access policies.`,
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
if (i.kind === 'no-policy') {
|
|
367
|
+
return (0, finding_1.makeFinding)({
|
|
368
|
+
...base,
|
|
369
|
+
rule: 'rls-no-policy',
|
|
370
|
+
title: `Table "${i.table}" has RLS enabled but no policy`,
|
|
371
|
+
severity: 'info',
|
|
372
|
+
description: `RLS is on for "${i.table}" but no CREATE POLICY targets it. That is safe — with RLS on and no policy every request is denied — but the app (anon/authenticated users) can't read or write it, which usually means a policy is missing.`,
|
|
373
|
+
recommendation: `Add the policies your app needs, e.g. CREATE POLICY ... ON ${i.table} FOR SELECT TO authenticated USING (auth.uid() = user_id); ignore this if only the service role should access the table.`,
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
return (0, finding_1.makeFinding)({
|
|
377
|
+
...base,
|
|
378
|
+
rule: 'rls-permissive-policy',
|
|
379
|
+
title: `Policy on "${i.table}" allows everyone (${i.clause})`,
|
|
380
|
+
severity: 'warning',
|
|
381
|
+
description: `Policy "${i.policy ?? ''}" on "${i.table}" (FOR ${i.command.toUpperCase()}) uses ${i.clause}, so it does not restrict which rows can be ${i.command === 'all' ? 'read or written' : 'changed'} — every matching role can ${i.command === 'all' ? 'read and write' : i.command} all rows.`,
|
|
382
|
+
recommendation: 'Restrict the policy to the owner of each row, e.g. USING (auth.uid() = user_id) / WITH CHECK (auth.uid() = user_id), or limit it with TO service_role.',
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* How git sees `rel` (relative to `root`): tracked, in history only, untracked, or not a git repo.
|
|
387
|
+
* `nested` is true when `root` is a subfolder of the repository rather than its top level.
|
|
388
|
+
*/
|
|
389
|
+
function gitState(root, rel) {
|
|
390
|
+
// Local-only commands; fsmonitor is disabled so a hostile repo config cannot run code.
|
|
391
|
+
const git = (args) => (0, child_process_1.execFileSync)('git', ['-c', 'core.fsmonitor=false', '-C', root, ...args], {
|
|
392
|
+
encoding: 'utf8',
|
|
393
|
+
timeout: 5000,
|
|
394
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
395
|
+
env: { ...process.env, GIT_TERMINAL_PROMPT: '0', GIT_OPTIONAL_LOCKS: '0' },
|
|
396
|
+
});
|
|
397
|
+
let nested = false;
|
|
398
|
+
try {
|
|
399
|
+
if (git(['rev-parse', '--is-inside-work-tree']).trim() !== 'true')
|
|
400
|
+
return { state: 'no-git', nested };
|
|
401
|
+
nested = git(['rev-parse', '--show-prefix']).trim() !== '';
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
return { state: 'no-git', nested };
|
|
405
|
+
}
|
|
406
|
+
try {
|
|
407
|
+
if (git(['ls-files', '--', rel]).trim())
|
|
408
|
+
return { state: 'tracked', nested };
|
|
409
|
+
if (git(['log', '--all', '-1', '--format=%h', '--', rel]).trim())
|
|
410
|
+
return { state: 'history', nested };
|
|
411
|
+
}
|
|
412
|
+
catch {
|
|
413
|
+
// fall through: a repo with no commits yet, or an odd state
|
|
414
|
+
}
|
|
415
|
+
return { state: 'untracked', nested };
|
|
416
|
+
}
|
|
187
417
|
async function safeRead(file) {
|
|
188
418
|
try {
|
|
189
419
|
return await FileWalker_1.FileWalker.read(file);
|