vibe-preflight 0.0.0-stage → 0.2.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/.claude-plugin/marketplace.json +11 -0
- package/.claude-plugin/plugin.json +9 -0
- package/LICENSE +21 -0
- package/README.md +124 -2
- package/bin/preflight.js +4 -0
- package/commands/preflight.md +13 -0
- package/examples/vibe-app/.env +2 -0
- package/examples/vibe-app/README.md +3 -0
- package/examples/vibe-app/app/api/stripe/webhook/route.ts +7 -0
- package/examples/vibe-app/index.html +7 -0
- package/examples/vibe-app/package.json +6 -0
- package/examples/vibe-app/server.js +5 -0
- package/examples/vibe-app/src/lib/stripe.ts +3 -0
- package/examples/vibe-app/src/lib/supabase.ts +4 -0
- package/examples/vibe-app/supabase/migrations/001_init.sql +11 -0
- package/package.json +52 -4
- package/src/cli.js +157 -0
- package/src/demo.js +43 -0
- package/src/project.js +116 -0
- package/src/report/colors.js +12 -0
- package/src/report/html.js +133 -0
- package/src/report/terminal.js +59 -0
- package/src/rules/_client-paths.js +19 -0
- package/src/rules/_gitignore.js +24 -0
- package/src/rules/_template.js +33 -0
- package/src/rules/cors-wildcard.js +37 -0
- package/src/rules/env-file-committed.js +43 -0
- package/src/rules/index.js +12 -0
- package/src/rules/missing-favicon.js +43 -0
- package/src/rules/missing-meta-tags.js +55 -0
- package/src/rules/missing-robots-txt.js +39 -0
- package/src/rules/no-error-monitoring.js +17 -0
- package/src/rules/no-privacy-policy.js +31 -0
- package/src/rules/secret-in-client.js +44 -0
- package/src/rules/stripe-webhook-unverified.js +26 -0
- package/src/rules/supabase-rls-disabled.js +36 -0
- package/src/run.js +47 -0
- package/src/score.js +30 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const CREATE = /create\s+table\s+(?:if\s+not\s+exists\s+)?((?:"?\w+"?\.)?"?\w+"?)/i;
|
|
2
|
+
const ENABLE = /alter\s+table\s+(?:if\s+exists\s+)?(?:only\s+)?((?:"?\w+"?\.)?"?\w+"?)\s+enable\s+row\s+level\s+security/gi;
|
|
3
|
+
const bare = (name) => name.replace(/"/g, '').split('.').pop().toLowerCase();
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
id: 'supabase-rls-disabled',
|
|
7
|
+
title: 'Supabase table without row-level security',
|
|
8
|
+
category: 'security',
|
|
9
|
+
severity: 'critical',
|
|
10
|
+
check(project) {
|
|
11
|
+
// Row-level security only protects data exposed through Supabase's public API.
|
|
12
|
+
const usesSupabase = project.has(/(?:^|\/)supabase\//) || /"@supabase\//.test(project.read('package.json'));
|
|
13
|
+
if (!usesSupabase) return [];
|
|
14
|
+
const sqlFiles = project.files.filter((f) => f.endsWith('.sql'));
|
|
15
|
+
if (!sqlFiles.length) return [];
|
|
16
|
+
const enabled = new Set();
|
|
17
|
+
for (const f of sqlFiles) for (const m of project.read(f).matchAll(ENABLE)) enabled.add(bare(m[1]));
|
|
18
|
+
const findings = [];
|
|
19
|
+
for (const file of sqlFiles) {
|
|
20
|
+
project.lines(file).forEach((line, i) => {
|
|
21
|
+
if (/^\s*--/.test(line)) return;
|
|
22
|
+
const m = line.match(CREATE);
|
|
23
|
+
if (m && !enabled.has(bare(m[1]))) {
|
|
24
|
+
const table = bare(m[1]);
|
|
25
|
+
findings.push({
|
|
26
|
+
file,
|
|
27
|
+
line: i + 1,
|
|
28
|
+
message: `Table "${table}" is created without row-level security, so anyone with your public anon key can read and change every row.`,
|
|
29
|
+
fix: `Add \`alter table ${table} enable row level security;\` and write policies for who may select, insert, update and delete.`,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return findings;
|
|
35
|
+
},
|
|
36
|
+
};
|
package/src/run.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { loadProject } from './project.js';
|
|
2
|
+
import { loadRules } from './rules/index.js';
|
|
3
|
+
import { score } from './score.js';
|
|
4
|
+
|
|
5
|
+
function ignoredInline(project, finding, ruleId) {
|
|
6
|
+
if (!finding.file) return false;
|
|
7
|
+
const lines = project.lines(finding.file);
|
|
8
|
+
const token = `preflight-ignore ${ruleId}`;
|
|
9
|
+
// A finding with no line is about the file as a whole (a committed .env, an unverified webhook),
|
|
10
|
+
// so the comment silences it from the head of the file rather than from one line (#16).
|
|
11
|
+
if (!finding.line) return lines.slice(0, FILE_LEVEL_IGNORE_LINES).some((l) => l?.includes(token));
|
|
12
|
+
return [lines[finding.line - 1], lines[finding.line - 2]].some((l) => l?.includes(token));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** How far into a file a `preflight-ignore` is still read for a finding that has no line. */
|
|
16
|
+
const FILE_LEVEL_IGNORE_LINES = 5;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Scans a project and returns the full report.
|
|
20
|
+
* @param {string} root
|
|
21
|
+
* @param {{ ignore?: string[], rules?: object[] }} [opts]
|
|
22
|
+
*/
|
|
23
|
+
export async function run(root, opts = {}) {
|
|
24
|
+
const project = await loadProject(root);
|
|
25
|
+
const rules = opts.rules ?? (await loadRules());
|
|
26
|
+
const ignore = new Set(opts.ignore ?? []);
|
|
27
|
+
// An id that matches no rule is almost always a typo, and today it silently ignores nothing (#19).
|
|
28
|
+
// Reported rather than thrown: the rest of the scan is still useful.
|
|
29
|
+
const known = new Set(rules.map((r) => r.id));
|
|
30
|
+
const unknownIgnore = [...ignore].filter((id) => !known.has(id));
|
|
31
|
+
const results = [];
|
|
32
|
+
for (const rule of rules) {
|
|
33
|
+
if (ignore.has(rule.id)) continue;
|
|
34
|
+
for (const finding of rule.check(project)) {
|
|
35
|
+
if (ignoredInline(project, finding, rule.id)) continue;
|
|
36
|
+
results.push({ ruleId: rule.id, title: rule.title, category: rule.category, severity: rule.severity, ...finding });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
root,
|
|
41
|
+
results,
|
|
42
|
+
...score(results),
|
|
43
|
+
rulesRun: rules.length,
|
|
44
|
+
filesScanned: project.files.length,
|
|
45
|
+
...(unknownIgnore.length ? { unknownIgnore } : {}),
|
|
46
|
+
};
|
|
47
|
+
}
|
package/src/score.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** Points lost per finding, by severity. */
|
|
2
|
+
export const WEIGHTS = { critical: 15, warning: 5, info: 1 };
|
|
3
|
+
|
|
4
|
+
export const CATEGORIES = ['security', 'reliability', 'launch'];
|
|
5
|
+
|
|
6
|
+
/** @param {number} n score from 0 to 100 */
|
|
7
|
+
export function gradeFor(n) {
|
|
8
|
+
if (n >= 90) return 'A';
|
|
9
|
+
if (n >= 80) return 'B';
|
|
10
|
+
if (n >= 70) return 'C';
|
|
11
|
+
if (n >= 50) return 'D';
|
|
12
|
+
return 'F';
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Turns findings into a score, grade and counts.
|
|
17
|
+
* @param {Array<{severity: 'critical'|'warning'|'info', category: string}>} results
|
|
18
|
+
*/
|
|
19
|
+
export function score(results) {
|
|
20
|
+
const counts = { critical: 0, warning: 0, info: 0 };
|
|
21
|
+
const byCategory = Object.fromEntries(CATEGORIES.map((c) => [c, 0]));
|
|
22
|
+
let lost = 0;
|
|
23
|
+
for (const r of results) {
|
|
24
|
+
counts[r.severity] += 1;
|
|
25
|
+
byCategory[r.category] = (byCategory[r.category] ?? 0) + 1;
|
|
26
|
+
lost += WEIGHTS[r.severity] ?? 0;
|
|
27
|
+
}
|
|
28
|
+
const value = Math.max(0, Math.min(100, 100 - lost));
|
|
29
|
+
return { score: value, grade: gradeFor(value), counts, byCategory };
|
|
30
|
+
}
|