deployready 0.3.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 +139 -45
- package/SECURITY.md +34 -0
- 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/runner.js +77 -7
- 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/agent/FileEditor.js +31 -3
- package/dist/agent/FileEditor.js.map +1 -1
- package/dist/agent/FixManager.js +25 -12
- 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/ModelRouter.js +3 -3
- 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/analysis/SeverityScorer.js +1 -1
- package/dist/analysis/SeverityScorer.js.map +1 -1
- package/dist/analysis/VulnerabilityDetector.js +257 -35
- 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 +85 -1
- package/dist/analysis/rules.js.map +1 -1
- package/dist/cli/Commands.js +65 -3
- package/dist/cli/Commands.js.map +1 -1
- package/dist/cli/InteractiveShell.js +79 -8
- package/dist/cli/InteractiveShell.js.map +1 -1
- package/dist/core/CiGate.js +5 -0
- package/dist/core/CiGate.js.map +1 -1
- package/dist/core/Orchestrator.js +56 -9
- package/dist/core/Orchestrator.js.map +1 -1
- package/dist/core/Verifier.js +236 -18
- 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/PerformanceTester.js +12 -0
- package/dist/dynamic/PerformanceTester.js.map +1 -1
- package/dist/dynamic/SecurityTester.js +45 -1
- package/dist/dynamic/SecurityTester.js.map +1 -1
- package/dist/dynamic/commonPaths/prober.js +9 -2
- package/dist/dynamic/commonPaths/prober.js.map +1 -1
- 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/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 +10 -0
- package/dist/ui/ExportManager.js.map +1 -1
- package/dist/ui/HtmlReporter.js +31 -0
- package/dist/ui/HtmlReporter.js.map +1 -1
- package/dist/ui/IssuePresenter.js +14 -0
- 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/utils/FileWalker.js +3 -0
- package/dist/utils/FileWalker.js.map +1 -1
- package/dist/utils/redact.js +2 -1
- package/dist/utils/redact.js.map +1 -1
- package/package.json +7 -3
- package/skills/deployready/SKILL.md +55 -0
|
@@ -0,0 +1,65 @@
|
|
|
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.supabaseCheck = supabaseCheck;
|
|
37
|
+
/**
|
|
38
|
+
* MCP tool `supabase_check`: the Supabase module (src/supabase) for agents.
|
|
39
|
+
* Static checks always; live checks only with `live: true` AND the same
|
|
40
|
+
* ownership gate as the CLI (loopback URL, or a validated service key / access
|
|
41
|
+
* token). Credentials come from env vars (or, for the public URL + anon key,
|
|
42
|
+
* the project files) only: never from tool arguments, so an agent cannot point
|
|
43
|
+
* it at someone else's project with a key it found. No prompts; nothing printed.
|
|
44
|
+
*/
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const supabase_1 = require("../supabase");
|
|
47
|
+
async function supabaseCheck(defaultPath, args = {}, deps = {}) {
|
|
48
|
+
const target = path.resolve(defaultPath, args.path ?? '.');
|
|
49
|
+
const live = args.live === true;
|
|
50
|
+
const res = await (0, supabase_1.runSupabase)(target, { live, crossUser: args.crossUser === true }, deps);
|
|
51
|
+
const findings = [...res.staticFindings, ...res.liveFindings].map((f) => ({
|
|
52
|
+
id: f.id,
|
|
53
|
+
rule: f.rule,
|
|
54
|
+
severity: f.severity,
|
|
55
|
+
title: f.title,
|
|
56
|
+
source: f.source,
|
|
57
|
+
file: f.file,
|
|
58
|
+
line: f.line,
|
|
59
|
+
endpoint: f.endpoint,
|
|
60
|
+
evidence: f.evidence,
|
|
61
|
+
proof: f.proof,
|
|
62
|
+
}));
|
|
63
|
+
return { target, live, refused: res.refused === true, findings, notes: res.notes };
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=supabase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"supabase.js","sourceRoot":"","sources":["../../src/mcp/supabase.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,sCAqBC;AAjDD;;;;;;;GAOG;AACH,2CAA6B;AAC7B,0CAAgE;AAmBzD,KAAK,UAAU,aAAa,CACjC,WAAmB,EACnB,OAA0B,EAAE,EAC5B,OAAyC,EAAE;IAE3C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC;IAC3D,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC;IAChC,MAAM,GAAG,GAAG,MAAM,IAAA,sBAAW,EAAC,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,KAAK,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;IAC1F,MAAM,QAAQ,GAAG,CAAC,GAAG,GAAG,CAAC,cAAc,EAAE,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACxE,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,KAAK,EAAE,CAAC,CAAC,KAAK;KACf,CAAC,CAAC,CAAC;IACJ,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,KAAK,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,186 @@
|
|
|
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.DeployReadyTools = void 0;
|
|
37
|
+
/**
|
|
38
|
+
* MCP tool handlers. Plain async functions so tests (and the stdio server) call the same code.
|
|
39
|
+
* Everything here is non-interactive: no prompts, no AI analysis. Nothing may write to stdout.
|
|
40
|
+
*/
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const Orchestrator_1 = require("../core/Orchestrator");
|
|
43
|
+
const Verifier_1 = require("../core/Verifier");
|
|
44
|
+
const FileEditor_1 = require("../agent/FileEditor");
|
|
45
|
+
const FixManager_1 = require("../agent/FixManager");
|
|
46
|
+
const fixPrompt_1 = require("../agent/fixPrompt");
|
|
47
|
+
const ScoreCalculator_1 = require("../analysis/ScoreCalculator");
|
|
48
|
+
const fixes_1 = require("./fixes");
|
|
49
|
+
const readiness_1 = require("./readiness");
|
|
50
|
+
const EVIDENCE_MAX = 200;
|
|
51
|
+
const FILE_MAX_BYTES = 256 * 1024;
|
|
52
|
+
class DeployReadyTools {
|
|
53
|
+
defaultPath;
|
|
54
|
+
cache = new Map();
|
|
55
|
+
/** @param defaultPath project used when a tool call omits `path` (the `mcp [path]` argument). */
|
|
56
|
+
constructor(defaultPath = '.') {
|
|
57
|
+
this.defaultPath = defaultPath;
|
|
58
|
+
}
|
|
59
|
+
resolve(p) {
|
|
60
|
+
return path.resolve(this.defaultPath, p ?? '.');
|
|
61
|
+
}
|
|
62
|
+
async runScan(target, dynamic) {
|
|
63
|
+
// Active (token-based) checks run only when DEPLOYREADY_TOKEN is set in the server env.
|
|
64
|
+
const tokens = dynamic ? (0, Verifier_1.tokensFromEnv)() : undefined;
|
|
65
|
+
const report = await Orchestrator_1.Orchestrator.analyze(target, {
|
|
66
|
+
yes: true,
|
|
67
|
+
json: true,
|
|
68
|
+
noAi: true,
|
|
69
|
+
noDynamic: !dynamic,
|
|
70
|
+
...(tokens ? { active: true, token: tokens.token, tokenB: tokens.tokenB } : {}),
|
|
71
|
+
});
|
|
72
|
+
const known = this.cache.get(target)?.known ?? new Map();
|
|
73
|
+
for (const f of report.findings)
|
|
74
|
+
known.set(f.id, f);
|
|
75
|
+
const entry = { target, dynamic, report, known };
|
|
76
|
+
this.cache.set(target, entry);
|
|
77
|
+
return entry;
|
|
78
|
+
}
|
|
79
|
+
async scan(args = {}) {
|
|
80
|
+
const entry = await this.runScan(this.resolve(args.path), args.dynamic === true);
|
|
81
|
+
return {
|
|
82
|
+
target: entry.target,
|
|
83
|
+
dynamic: entry.dynamic,
|
|
84
|
+
...(0, readiness_1.assess)(entry.report.findings),
|
|
85
|
+
findings: entry.report.findings.map(summarize),
|
|
86
|
+
hint: 'Next: apply_safe_fixes, then get_finding for each remaining finding, fix it with your own edits, verify(id), and finish with score.',
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
find(id, p) {
|
|
90
|
+
const candidates = p ? [this.cache.get(this.resolve(p))] : [...this.cache.values()];
|
|
91
|
+
if (candidates.every((c) => !c))
|
|
92
|
+
throw new Error('No scan yet for this path. Call scan first.');
|
|
93
|
+
for (const entry of candidates) {
|
|
94
|
+
const finding = entry?.known.get(id);
|
|
95
|
+
if (entry && finding)
|
|
96
|
+
return { entry, finding };
|
|
97
|
+
}
|
|
98
|
+
throw new Error(`Unknown finding id "${id}". Call scan to list current ids.`);
|
|
99
|
+
}
|
|
100
|
+
async getFinding(args) {
|
|
101
|
+
const { entry, finding } = this.find(args.id, args.path);
|
|
102
|
+
const out = {
|
|
103
|
+
...summarize(finding),
|
|
104
|
+
category: finding.category,
|
|
105
|
+
description: finding.description,
|
|
106
|
+
fixPrompt: (0, fixPrompt_1.buildFixPrompt)(finding),
|
|
107
|
+
fix: {
|
|
108
|
+
recommendation: finding.recommendation,
|
|
109
|
+
owasp: finding.owasp,
|
|
110
|
+
cwe: finding.cwe,
|
|
111
|
+
deterministicFixAvailable: FixManager_1.FixManager.autoFixable(finding),
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
if (finding.source === 'static' && finding.file) {
|
|
115
|
+
try {
|
|
116
|
+
const content = await new FileEditor_1.FileEditor(entry.target).read(finding.file);
|
|
117
|
+
out.file_content = renderFile(content, finding.line);
|
|
118
|
+
out.file_truncated = Buffer.byteLength(content) > FILE_MAX_BYTES;
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
out.file_error = err.message;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
async applySafeFixes(args = {}) {
|
|
127
|
+
const target = this.resolve(args.path);
|
|
128
|
+
const entry = this.cache.get(target) ?? (await this.runScan(target, false));
|
|
129
|
+
const result = await (0, fixes_1.applySafeFixes)(target, entry.report.findings);
|
|
130
|
+
// The files changed: refresh so score and ids reflect disk.
|
|
131
|
+
const fresh = result.applied.length > 0 ? await this.runScan(target, entry.dynamic) : entry;
|
|
132
|
+
return {
|
|
133
|
+
...result,
|
|
134
|
+
...(0, readiness_1.assess)(fresh.report.findings),
|
|
135
|
+
note: result.applied.length === 0
|
|
136
|
+
? 'No deterministic fix applied. Use get_finding and edit the code yourself.'
|
|
137
|
+
: 'Applied fixes are backed up (see backup paths). Remaining findings need your own edits; use get_finding.',
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
async verify(args) {
|
|
141
|
+
const { entry, finding } = this.find(args.id, args.path);
|
|
142
|
+
const ctx = { target: entry.target };
|
|
143
|
+
if (entry.report.dynamic?.baseUrl) {
|
|
144
|
+
ctx.dynamic = { baseUrl: entry.report.dynamic.baseUrl, routes: entry.report.graph.routes };
|
|
145
|
+
}
|
|
146
|
+
const active = (0, Verifier_1.activeContextFromEnv)(entry.report.dynamic?.baseUrl, entry.report.graph.routes);
|
|
147
|
+
if (active)
|
|
148
|
+
ctx.active = active;
|
|
149
|
+
const res = await Verifier_1.Verifier.verify(finding, ctx);
|
|
150
|
+
return { id: finding.id, status: res.status, detail: res.detail, ...(res.proof ? { proof: res.proof } : {}) };
|
|
151
|
+
}
|
|
152
|
+
async score(args = {}) {
|
|
153
|
+
const target = this.resolve(args.path);
|
|
154
|
+
const entry = await this.runScan(target, this.cache.get(target)?.dynamic ?? false);
|
|
155
|
+
return {
|
|
156
|
+
target,
|
|
157
|
+
...(0, readiness_1.assess)(entry.report.findings),
|
|
158
|
+
openCritical: entry.report.findings.filter((f) => !(0, ScoreCalculator_1.isNonScored)(f) && f.severity === 'critical').map(summarize),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
exports.DeployReadyTools = DeployReadyTools;
|
|
163
|
+
function summarize(f) {
|
|
164
|
+
const ev = f.evidence && f.evidence.length > EVIDENCE_MAX ? f.evidence.slice(0, EVIDENCE_MAX) + '…' : f.evidence;
|
|
165
|
+
return {
|
|
166
|
+
id: f.id,
|
|
167
|
+
rule: f.rule,
|
|
168
|
+
severity: f.severity,
|
|
169
|
+
title: f.title,
|
|
170
|
+
source: f.source,
|
|
171
|
+
file: f.file,
|
|
172
|
+
line: f.line,
|
|
173
|
+
endpoint: f.endpoint,
|
|
174
|
+
evidence: ev,
|
|
175
|
+
proof: f.proof,
|
|
176
|
+
note: f.note ? true : undefined,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
/** Whole file, numbered, with the finding's line marked `>`. */
|
|
180
|
+
function renderFile(content, line) {
|
|
181
|
+
const text = content.length > FILE_MAX_BYTES ? content.slice(0, FILE_MAX_BYTES) : content;
|
|
182
|
+
const lines = text.split(/\r?\n/);
|
|
183
|
+
const width = String(lines.length).length;
|
|
184
|
+
return lines.map((l, i) => `${i + 1 === line ? '>' : ' '} ${String(i + 1).padStart(width)} | ${l}`).join('\n');
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/mcp/tools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CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjH,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MANAGEMENT_ORIGIN = void 0;
|
|
4
|
+
exports.checkOwnership = checkOwnership;
|
|
5
|
+
/**
|
|
6
|
+
* Ownership gate for live Supabase probes. Anon keys are public, so holding one
|
|
7
|
+
* proves nothing: DeployReady must not become a scanner for other people's apps.
|
|
8
|
+
*
|
|
9
|
+
* Live probes are allowed ONLY when:
|
|
10
|
+
* (a) the project URL is loopback (a local `supabase start`), or
|
|
11
|
+
* (b) the user proves ownership of THAT project with
|
|
12
|
+
* - a service_role / sb_secret key that actually works for that URL
|
|
13
|
+
* (an admin-only endpoint answers 200), and whose `ref` claim, when
|
|
14
|
+
* present, matches the URL's project ref; or
|
|
15
|
+
* - a Supabase access token whose Management API project list contains
|
|
16
|
+
* the URL's project ref.
|
|
17
|
+
* Otherwise the caller refuses with `reason`.
|
|
18
|
+
*/
|
|
19
|
+
const http_1 = require("./http");
|
|
20
|
+
const keys_1 = require("./keys");
|
|
21
|
+
exports.MANAGEMENT_ORIGIN = 'https://api.supabase.com';
|
|
22
|
+
const REFUSAL = 'Live Supabase checks only run against a project you prove you own: a local project (loopback URL, e.g. http://127.0.0.1:54321), ' +
|
|
23
|
+
'or a hosted project with SUPABASE_SERVICE_ROLE_KEY (validated against that project) or SUPABASE_ACCESS_TOKEN (its project list must include that project). ' +
|
|
24
|
+
'An anon key is public and is not proof of ownership.';
|
|
25
|
+
async function checkOwnership(input, deps) {
|
|
26
|
+
if ((0, http_1.isLoopbackUrl)(input.url)) {
|
|
27
|
+
return { allowed: true, mode: 'local', reason: 'Local Supabase project (loopback URL).' };
|
|
28
|
+
}
|
|
29
|
+
const ref = (0, keys_1.projectRefFromUrl)(input.url);
|
|
30
|
+
const failures = [];
|
|
31
|
+
if (input.serviceKey) {
|
|
32
|
+
const info = (0, keys_1.classifyKey)(input.serviceKey);
|
|
33
|
+
if (info.kind !== 'service_role') {
|
|
34
|
+
failures.push('the provided service key is not a service_role / sb_secret key');
|
|
35
|
+
}
|
|
36
|
+
else if (info.ref && ref && info.ref !== ref) {
|
|
37
|
+
failures.push('the service key belongs to a different project than the URL');
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Admin-only endpoint: only a working service key for THIS project gets 200.
|
|
41
|
+
// The body (one user record) is discarded unread.
|
|
42
|
+
const res = await deps.project.request({
|
|
43
|
+
method: 'GET',
|
|
44
|
+
path: '/auth/v1/admin/users',
|
|
45
|
+
query: { page: 1, per_page: 1 },
|
|
46
|
+
headers: { apikey: input.serviceKey, Authorization: `Bearer ${input.serviceKey}` },
|
|
47
|
+
});
|
|
48
|
+
if (res.status === 200) {
|
|
49
|
+
return { allowed: true, mode: 'service-role', reason: 'Service key validated against this project.' };
|
|
50
|
+
}
|
|
51
|
+
failures.push(`the service key was rejected by this project (HTTP ${res.status})`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (input.accessToken) {
|
|
55
|
+
if (!ref) {
|
|
56
|
+
failures.push('an access token can only prove ownership of a <ref>.supabase.co URL');
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const mgmt = new http_1.SupabaseHttp({
|
|
60
|
+
origin: exports.MANAGEMENT_ORIGIN,
|
|
61
|
+
transport: deps.managementTransport,
|
|
62
|
+
minIntervalMs: deps.minIntervalMs,
|
|
63
|
+
maxRequests: 5,
|
|
64
|
+
});
|
|
65
|
+
const res = await mgmt.request({
|
|
66
|
+
method: 'GET',
|
|
67
|
+
path: '/v1/projects',
|
|
68
|
+
headers: { Authorization: `Bearer ${input.accessToken}` },
|
|
69
|
+
});
|
|
70
|
+
if (res.status === 200 && projectListIncludes(res.bodyText, ref)) {
|
|
71
|
+
return { allowed: true, mode: 'access-token', reason: 'Access token lists this project.' };
|
|
72
|
+
}
|
|
73
|
+
failures.push(res.status === 200
|
|
74
|
+
? 'the access token does not list this project'
|
|
75
|
+
: `the Management API rejected the access token (HTTP ${res.status})`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const why = failures.length ? ` Not proven: ${failures.join('; ')}.` : '';
|
|
79
|
+
return { allowed: false, reason: `${REFUSAL}${why}` };
|
|
80
|
+
}
|
|
81
|
+
function projectListIncludes(body, ref) {
|
|
82
|
+
try {
|
|
83
|
+
const list = JSON.parse(body);
|
|
84
|
+
if (!Array.isArray(list))
|
|
85
|
+
return false;
|
|
86
|
+
return list.some((p) => {
|
|
87
|
+
const o = p;
|
|
88
|
+
return o && (o.id === ref || o.ref === ref);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=guard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/supabase/guard.ts"],"names":[],"mappings":";;;AA+CA,wCAyDC;AAxGD;;;;;;;;;;;;;GAaG;AACH,iCAAqE;AACrE,iCAAwD;AAyB3C,QAAA,iBAAiB,GAAG,0BAA0B,CAAC;AAE5D,MAAM,OAAO,GACX,kIAAkI;IAClI,6JAA6J;IAC7J,sDAAsD,CAAC;AAElD,KAAK,UAAU,cAAc,CAAC,KAAqB,EAAE,IAAe;IACzE,IAAI,IAAA,oBAAa,EAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QAC7B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,wCAAw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CAAC;QACzC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QACvC,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACrB,MAAM,CAAC,GAAG,CAA4B,CAAC;YACvC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SupabaseHttp = exports.BudgetExceededError = exports.axiosTransport = void 0;
|
|
7
|
+
exports.isLoopbackUrl = isLoopbackUrl;
|
|
8
|
+
/**
|
|
9
|
+
* The ONE network client for the Supabase module. Every live Supabase request
|
|
10
|
+
* goes through `SupabaseHttp`, which carries the safety rails:
|
|
11
|
+
* - fixed origin: a client is bound to one origin (the project URL, or the
|
|
12
|
+
* Management API) and refuses any URL that resolves elsewhere;
|
|
13
|
+
* - https only, except for a loopback (local `supabase start`) origin;
|
|
14
|
+
* - rate limit (minimum spacing between requests) and a hard request budget;
|
|
15
|
+
* - timeout, no redirects, response-size cap (in the default transport).
|
|
16
|
+
*
|
|
17
|
+
* The transport is injected so tests mock it and no real network is touched.
|
|
18
|
+
*/
|
|
19
|
+
const axios_1 = __importDefault(require("axios"));
|
|
20
|
+
const LOOPBACK = new Set(['localhost', '127.0.0.1', '::1', '[::1]']);
|
|
21
|
+
const TIMEOUT_MS = 10_000;
|
|
22
|
+
const MAX_BODY = 5 * 1024 * 1024;
|
|
23
|
+
const USER_AGENT = 'DeployReady-Supabase-Check';
|
|
24
|
+
function isLoopbackUrl(raw) {
|
|
25
|
+
try {
|
|
26
|
+
const host = new URL(raw).hostname;
|
|
27
|
+
return LOOPBACK.has(host) || host.endsWith('.localhost');
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** Real transport: axios, no redirects, bounded time and size, never throws on status. */
|
|
34
|
+
const axiosTransport = async (req) => {
|
|
35
|
+
const res = await axios_1.default.request({
|
|
36
|
+
url: req.url,
|
|
37
|
+
method: req.method,
|
|
38
|
+
headers: { 'User-Agent': USER_AGENT, ...req.headers },
|
|
39
|
+
data: req.body,
|
|
40
|
+
timeout: TIMEOUT_MS,
|
|
41
|
+
maxRedirects: 0,
|
|
42
|
+
validateStatus: () => true,
|
|
43
|
+
maxContentLength: MAX_BODY,
|
|
44
|
+
responseType: 'text',
|
|
45
|
+
transformResponse: (d) => d,
|
|
46
|
+
});
|
|
47
|
+
const headers = {};
|
|
48
|
+
for (const [k, v] of Object.entries(res.headers ?? {})) {
|
|
49
|
+
if (v !== undefined && v !== null)
|
|
50
|
+
headers[k.toLowerCase()] = Array.isArray(v) ? v.join(', ') : String(v);
|
|
51
|
+
}
|
|
52
|
+
return { status: res.status, headers, bodyText: typeof res.data === 'string' ? res.data : '' };
|
|
53
|
+
};
|
|
54
|
+
exports.axiosTransport = axiosTransport;
|
|
55
|
+
class BudgetExceededError extends Error {
|
|
56
|
+
}
|
|
57
|
+
exports.BudgetExceededError = BudgetExceededError;
|
|
58
|
+
class SupabaseHttp {
|
|
59
|
+
origin;
|
|
60
|
+
transport;
|
|
61
|
+
minIntervalMs;
|
|
62
|
+
maxRequests;
|
|
63
|
+
sleep;
|
|
64
|
+
now;
|
|
65
|
+
last = 0;
|
|
66
|
+
chain = Promise.resolve();
|
|
67
|
+
sent = 0;
|
|
68
|
+
constructor(opts) {
|
|
69
|
+
const url = new URL(opts.origin);
|
|
70
|
+
if (url.protocol !== 'https:' && !(url.protocol === 'http:' && isLoopbackUrl(opts.origin))) {
|
|
71
|
+
throw new Error('Supabase checks require an https:// URL (plain http is only allowed for a local, loopback project).');
|
|
72
|
+
}
|
|
73
|
+
this.origin = url.origin;
|
|
74
|
+
this.transport = opts.transport ?? exports.axiosTransport;
|
|
75
|
+
this.minIntervalMs = opts.minIntervalMs ?? 250;
|
|
76
|
+
this.maxRequests = opts.maxRequests ?? 300;
|
|
77
|
+
this.sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
78
|
+
this.now = opts.now ?? Date.now;
|
|
79
|
+
}
|
|
80
|
+
/** Build the absolute URL and refuse anything that leaves this client's origin. */
|
|
81
|
+
buildUrl(path, query) {
|
|
82
|
+
const url = new URL(path, this.origin + '/');
|
|
83
|
+
if (url.origin !== this.origin)
|
|
84
|
+
throw new Error('Refusing a request outside the configured Supabase origin.');
|
|
85
|
+
if (query)
|
|
86
|
+
for (const [k, v] of Object.entries(query))
|
|
87
|
+
url.searchParams.set(k, String(v));
|
|
88
|
+
return url.toString();
|
|
89
|
+
}
|
|
90
|
+
/** Send one request, serialized and rate-limited. */
|
|
91
|
+
request(req) {
|
|
92
|
+
const run = async () => {
|
|
93
|
+
if (this.sent >= this.maxRequests) {
|
|
94
|
+
throw new BudgetExceededError(`Supabase request budget (${this.maxRequests}) reached; stopping.`);
|
|
95
|
+
}
|
|
96
|
+
const url = this.buildUrl(req.path, req.query);
|
|
97
|
+
const wait = this.last + this.minIntervalMs - this.now();
|
|
98
|
+
if (this.sent > 0 && wait > 0)
|
|
99
|
+
await this.sleep(wait);
|
|
100
|
+
this.sent++;
|
|
101
|
+
this.last = this.now();
|
|
102
|
+
const headers = { ...(req.headers ?? {}) };
|
|
103
|
+
if (req.body !== undefined && !headers['Content-Type'])
|
|
104
|
+
headers['Content-Type'] = 'application/json';
|
|
105
|
+
return this.transport({ method: req.method, url, headers, body: req.body });
|
|
106
|
+
};
|
|
107
|
+
const p = this.chain.then(run, run);
|
|
108
|
+
this.chain = p.catch(() => undefined);
|
|
109
|
+
return p;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.SupabaseHttp = SupabaseHttp;
|
|
113
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/supabase/http.ts"],"names":[],"mappings":";;;;;;AAuDA,sCAOC;AA9DD;;;;;;;;;;GAUG;AACH,kDAA0B;AAuC1B,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC;AACrE,MAAM,UAAU,GAAG,MAAM,CAAC;AAC1B,MAAM,QAAQ,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC;AACjC,MAAM,UAAU,GAAG,4BAA4B,CAAC;AAEhD,SAAgB,aAAa,CAAC,GAAW;IACvC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;QACnC,OAAO,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,0FAA0F;AACnF,MAAM,cAAc,GAAc,KAAK,EAAE,GAAG,EAAE,EAAE;IACrD,MAAM,GAAG,GAAG,MAAM,eAAK,CAAC,OAAO,CAAC;QAC9B,GAAG,EAAE,GAAG,CAAC,GAAG;QACZ,MAAM,EAAE,GAAG,CAAC,MAAe;QAC3B,OAAO,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,OAAO,EAAE;QACrD,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,OAAO,EAAE,UAAU;QACnB,YAAY,EAAE,C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AC,SAAS,CAAC,CAAC;QACtC,OAAO,CAAC,CAAC;IACX,CAAC;CACF;AAnDD,oCAmDC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ENV = void 0;
|
|
7
|
+
exports.resolveCredentials = resolveCredentials;
|
|
8
|
+
exports.runSupabase = runSupabase;
|
|
9
|
+
exports.supabaseStep = supabaseStep;
|
|
10
|
+
/**
|
|
11
|
+
* Supabase module entry point: static checks always (no network); live checks
|
|
12
|
+
* only with --supabase, behind the ownership gate (guard.ts) and a consent
|
|
13
|
+
* prompt (skipped by --yes). Credentials come from flags or env vars and are
|
|
14
|
+
* never printed.
|
|
15
|
+
*/
|
|
16
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
17
|
+
const logger_1 = require("../utils/logger");
|
|
18
|
+
const redact_1 = require("../utils/redact");
|
|
19
|
+
const http_1 = require("./http");
|
|
20
|
+
const guard_1 = require("./guard");
|
|
21
|
+
const keys_1 = require("./keys");
|
|
22
|
+
const live_1 = require("./live");
|
|
23
|
+
const static_1 = require("./static");
|
|
24
|
+
exports.ENV = {
|
|
25
|
+
url: 'SUPABASE_URL',
|
|
26
|
+
anonKey: 'SUPABASE_ANON_KEY',
|
|
27
|
+
serviceKey: 'SUPABASE_SERVICE_ROLE_KEY',
|
|
28
|
+
accessToken: 'SUPABASE_ACCESS_TOKEN',
|
|
29
|
+
userAEmail: 'SUPABASE_TEST_USER_A_EMAIL',
|
|
30
|
+
userAPassword: 'SUPABASE_TEST_USER_A_PASSWORD',
|
|
31
|
+
userBEmail: 'SUPABASE_TEST_USER_B_EMAIL',
|
|
32
|
+
userBPassword: 'SUPABASE_TEST_USER_B_PASSWORD',
|
|
33
|
+
};
|
|
34
|
+
/** Flags win over env vars, which win over what the static scan found in the project. */
|
|
35
|
+
function resolveCredentials(opts, env, detected) {
|
|
36
|
+
const pick = (...v) => v.find((x) => x && x.trim())?.trim();
|
|
37
|
+
const creds = {
|
|
38
|
+
url: pick(opts.url, env[exports.ENV.url], detected.url),
|
|
39
|
+
anonKey: pick(opts.anonKey, env[exports.ENV.anonKey], detected.anonKey),
|
|
40
|
+
serviceKey: pick(opts.serviceKey, env[exports.ENV.serviceKey]),
|
|
41
|
+
accessToken: pick(opts.accessToken, env[exports.ENV.accessToken]),
|
|
42
|
+
};
|
|
43
|
+
const ae = env[exports.ENV.userAEmail];
|
|
44
|
+
const ap = env[exports.ENV.userAPassword];
|
|
45
|
+
const be = env[exports.ENV.userBEmail];
|
|
46
|
+
const bp = env[exports.ENV.userBPassword];
|
|
47
|
+
if (ae && ap && be && bp)
|
|
48
|
+
creds.users = { a: { email: ae, password: ap }, b: { email: be, password: bp } };
|
|
49
|
+
return creds;
|
|
50
|
+
}
|
|
51
|
+
async function runSupabase(projectPath, opts, deps = {}) {
|
|
52
|
+
const notes = [];
|
|
53
|
+
const { findings: staticFindings, detected } = await (0, static_1.scanSupabaseStatic)(projectPath);
|
|
54
|
+
const result = { staticFindings, liveFindings: [], notes };
|
|
55
|
+
if (!opts.live) {
|
|
56
|
+
if (detected.url) {
|
|
57
|
+
notes.push(`Supabase project detected (${detected.urlSource}). Run with --supabase to prove what the anon key can read (read-only; needs proof you own the project). See docs/SUPABASE.md.`);
|
|
58
|
+
}
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
const creds = resolveCredentials(opts, deps.env ?? process.env, detected);
|
|
62
|
+
if (!creds.url) {
|
|
63
|
+
notes.push(`Supabase live checks skipped: no project URL (set ${exports.ENV.url} or --supabase-url).`);
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
let origin;
|
|
67
|
+
try {
|
|
68
|
+
origin = (0, keys_1.normalizeProjectUrl)(creds.url);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
notes.push('Supabase live checks skipped: the project URL is not a valid URL.');
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
if (!creds.anonKey) {
|
|
75
|
+
notes.push(`Supabase live checks skipped: no anon key (set ${exports.ENV.anonKey} or --supabase-anon-key).`);
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
const anonInfo = (0, keys_1.classifyKey)(creds.anonKey);
|
|
79
|
+
const ref = (0, keys_1.projectRefFromUrl)(origin);
|
|
80
|
+
if (anonInfo.kind === 'service_role') {
|
|
81
|
+
notes.push('Supabase live checks skipped: the anon key given is actually a service_role key. Pass the public anon key as the anon key.');
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
if (anonInfo.ref && ref && anonInfo.ref !== ref) {
|
|
85
|
+
notes.push('Supabase live checks skipped: the anon key belongs to a different project than the URL.');
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
let http;
|
|
89
|
+
try {
|
|
90
|
+
http = new http_1.SupabaseHttp({ origin, transport: deps.transport, minIntervalMs: opts.delayMs });
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
notes.push(`Supabase live checks skipped: ${err.message}`);
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
const gate = await (0, guard_1.checkOwnership)({ url: origin, serviceKey: creds.serviceKey, accessToken: creds.accessToken }, { project: http, managementTransport: deps.managementTransport, minIntervalMs: opts.delayMs });
|
|
97
|
+
if (!gate.allowed) {
|
|
98
|
+
notes.push(`Supabase live checks refused. ${gate.reason}`);
|
|
99
|
+
result.refused = true;
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
notes.push(`Supabase ownership: ${gate.reason}`);
|
|
103
|
+
if (deps.confirm && !(await deps.confirm(origin, gate.mode ?? ''))) {
|
|
104
|
+
notes.push('Skipping Supabase live checks by your choice.');
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
let crossUser;
|
|
108
|
+
if (opts.crossUser) {
|
|
109
|
+
if (creds.users)
|
|
110
|
+
crossUser = creds.users;
|
|
111
|
+
else
|
|
112
|
+
notes.push(`Cross-user test skipped: set ${exports.ENV.userAEmail}, ${exports.ENV.userAPassword}, ${exports.ENV.userBEmail} and ${exports.ENV.userBPassword} (two test accounts you own).`);
|
|
113
|
+
}
|
|
114
|
+
// A service key is only used once the gate has validated it for this project.
|
|
115
|
+
const serviceKey = gate.mode === 'service-role' || gate.mode === 'local' ? creds.serviceKey : undefined;
|
|
116
|
+
const live = await (0, live_1.runLiveChecks)({
|
|
117
|
+
http,
|
|
118
|
+
anonKey: creds.anonKey,
|
|
119
|
+
serviceKey: serviceKey && (0, keys_1.classifyKey)(serviceKey).kind === 'service_role' ? serviceKey : undefined,
|
|
120
|
+
fallbackTables: detected.migrationTables,
|
|
121
|
+
crossUser,
|
|
122
|
+
});
|
|
123
|
+
result.liveFindings = live.findings;
|
|
124
|
+
notes.push(...live.notes);
|
|
125
|
+
notes.push(`Supabase live checks done: ${live.tablesChecked} table(s), ${http.sent} request(s), ${live.findings.length} finding(s). Read-only; no writes were made.`);
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
/** Orchestrator hook: runs the module with terminal prompts and logging. Never throws. */
|
|
129
|
+
async function supabaseStep(projectPath, opts) {
|
|
130
|
+
const say = (msg) => (opts.json ? logger_1.logger.stderr(msg) : logger_1.logger.info(msg));
|
|
131
|
+
try {
|
|
132
|
+
const res = await runSupabase(projectPath, opts.supabase ?? {}, {
|
|
133
|
+
confirm: opts.yes
|
|
134
|
+
? undefined
|
|
135
|
+
: async (target, mode) => {
|
|
136
|
+
const { ok } = await inquirer_1.default.prompt([
|
|
137
|
+
{
|
|
138
|
+
type: 'confirm',
|
|
139
|
+
name: 'ok',
|
|
140
|
+
message: `Run read-only Supabase checks against ${target} (ownership: ${mode})? Counts rows visible to the anon key; no data is downloaded, nothing is written.`,
|
|
141
|
+
default: true,
|
|
142
|
+
},
|
|
143
|
+
]);
|
|
144
|
+
return ok;
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
for (const n of res.notes)
|
|
148
|
+
(res.refused ? logger_1.logger.warn : say)((0, redact_1.redact)(n));
|
|
149
|
+
return { staticFindings: res.staticFindings, liveFindings: res.liveFindings };
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
logger_1.logger.warn(`Supabase checks failed: ${(0, redact_1.redact)(err.message)}`);
|
|
153
|
+
return { staticFindings: [], liveFindings: [] };
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=index.js.map
|