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,133 @@
|
|
|
1
|
+
import { CATEGORIES } from '../score.js';
|
|
2
|
+
|
|
3
|
+
const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (ch) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[ch]));
|
|
4
|
+
|
|
5
|
+
/** Escapes text, then turns `code` spans into inline code. */
|
|
6
|
+
const rich = (s) => esc(s).replace(/`([^`]+)`/g, '<code class="inline">$1</code>');
|
|
7
|
+
|
|
8
|
+
const GRADE_COLOR = { A: '#34d399', B: '#a3e635', C: '#fbbf24', D: '#fb923c', F: '#f87171' };
|
|
9
|
+
const SEVERITY_COLOR = { critical: '#f87171', warning: '#fbbf24', info: '#94a3b8' };
|
|
10
|
+
const SEVERITY_ORDER = { critical: 0, warning: 1, info: 2 };
|
|
11
|
+
const CATEGORY_LABEL = { security: 'Security', reliability: 'Reliability', launch: 'Launch basics' };
|
|
12
|
+
const VERDICT = {
|
|
13
|
+
A: 'Cleared for takeoff.',
|
|
14
|
+
B: 'Nearly there. A few things to tidy.',
|
|
15
|
+
C: 'Fix the red items before you launch.',
|
|
16
|
+
D: 'Not ready to launch yet.',
|
|
17
|
+
F: 'Grounded. Fix the critical issues first.',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function gauge(score, color) {
|
|
21
|
+
const r = 70;
|
|
22
|
+
const circumference = 2 * Math.PI * r;
|
|
23
|
+
const offset = circumference * (1 - score / 100);
|
|
24
|
+
return `<svg class="gauge" viewBox="0 0 180 180" role="img" aria-label="Score ${score} out of 100">
|
|
25
|
+
<circle cx="90" cy="90" r="${r}" fill="none" stroke="#1f2430" stroke-width="14"/>
|
|
26
|
+
<circle cx="90" cy="90" r="${r}" fill="none" stroke="${color}" stroke-width="14" stroke-linecap="round"
|
|
27
|
+
stroke-dasharray="${circumference.toFixed(2)}" stroke-dashoffset="${offset.toFixed(2)}" transform="rotate(-90 90 90)"/>
|
|
28
|
+
<text x="90" y="92" text-anchor="middle" class="gauge-score" fill="${color}" style="fill:${color}">${score}</text>
|
|
29
|
+
<text x="90" y="118" text-anchor="middle" class="gauge-out">/ 100</text>
|
|
30
|
+
</svg>`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function categoryBars(report) {
|
|
34
|
+
const max = Math.max(1, ...CATEGORIES.map((c) => report.byCategory[c] ?? 0));
|
|
35
|
+
return CATEGORIES.map((c) => {
|
|
36
|
+
const n = report.byCategory[c] ?? 0;
|
|
37
|
+
const width = n === 0 ? 100 : Math.max(8, Math.round((n / max) * 100));
|
|
38
|
+
const color = n === 0 ? '#34d399' : report.results.some((r) => r.category === c && r.severity === 'critical') ? '#f87171' : '#fbbf24';
|
|
39
|
+
return `<div class="bar"><span class="bar-label">${CATEGORY_LABEL[c]}</span><span class="bar-track"><span class="bar-fill" style="width:${width}%;background:${color}"></span></span><span class="bar-count">${n === 0 ? '✓' : n}</span></div>`;
|
|
40
|
+
}).join('\n');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function findingCards(report) {
|
|
44
|
+
if (!report.results.length) return '<div class="clean">No issues found. Ready for takeoff.</div>';
|
|
45
|
+
return CATEGORIES.map((c) => {
|
|
46
|
+
const items = report.results.filter((r) => r.category === c).sort((a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity]);
|
|
47
|
+
if (!items.length) return '';
|
|
48
|
+
return `<h2>${CATEGORY_LABEL[c]}</h2>\n` + items.map((r) => `<article class="finding" style="--sev:${SEVERITY_COLOR[r.severity]}">
|
|
49
|
+
<div class="finding-head"><span class="pill">${esc(r.severity)}</span><h3>${esc(r.title)}</h3></div>
|
|
50
|
+
${r.file ? `<code>${esc(r.line ? `${r.file}:${r.line}` : r.file)}</code>` : ''}
|
|
51
|
+
<p>${rich(r.message)}</p>
|
|
52
|
+
<p class="fix"><span>Fix</span>${rich(r.fix)}</p>
|
|
53
|
+
</article>`).join('\n');
|
|
54
|
+
}).join('\n');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Renders a self-contained, shareable HTML report card.
|
|
59
|
+
* @param {object} report from run()
|
|
60
|
+
*/
|
|
61
|
+
export function renderHtml(report) {
|
|
62
|
+
const color = GRADE_COLOR[report.grade];
|
|
63
|
+
const { critical, warning, info } = report.counts;
|
|
64
|
+
return `<!doctype html>
|
|
65
|
+
<html lang="en">
|
|
66
|
+
<head>
|
|
67
|
+
<meta charset="utf-8">
|
|
68
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
69
|
+
<title>Preflight report: ${report.score}/100 (${report.grade})</title>
|
|
70
|
+
<style>
|
|
71
|
+
:root { color-scheme: dark; }
|
|
72
|
+
* { box-sizing: border-box; }
|
|
73
|
+
body { margin: 0; background: radial-gradient(1200px 600px at 50% -200px, #1a2033, #0b0d12 60%); color: #e5e7eb;
|
|
74
|
+
font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
|
|
75
|
+
main { max-width: 880px; margin: 0 auto; padding: 48px 20px 64px; }
|
|
76
|
+
.brand { display: flex; justify-content: space-between; align-items: center; color: #94a3b8; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; }
|
|
77
|
+
.brand b { color: #e5e7eb; letter-spacing: .2em; }
|
|
78
|
+
.card { margin-top: 18px; background: linear-gradient(180deg, #131722, #0f121a); border: 1px solid #222838; border-radius: 22px; padding: 32px; box-shadow: 0 30px 80px -30px rgba(0,0,0,.7); }
|
|
79
|
+
.hero { display: grid; grid-template-columns: 180px 1fr; gap: 32px; align-items: center; }
|
|
80
|
+
.gauge { width: 180px; height: 180px; }
|
|
81
|
+
.gauge-score { fill: #f8fafc; font-size: 48px; font-weight: 800; }
|
|
82
|
+
.gauge-out { fill: #64748b; font-size: 14px; }
|
|
83
|
+
.grade { display: inline-block; font-weight: 800; font-size: 22px; color: ${color}; }
|
|
84
|
+
.verdict { font-size: 26px; font-weight: 700; margin: 4px 0 10px; color: #f8fafc; }
|
|
85
|
+
.counts { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
|
|
86
|
+
.count { border: 1px solid #262c3b; border-radius: 999px; padding: 4px 12px; font-size: 13px; color: #cbd5e1; }
|
|
87
|
+
.count i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
|
|
88
|
+
.bar { display: grid; grid-template-columns: 110px 1fr 28px; gap: 12px; align-items: center; margin: 7px 0; font-size: 13px; color: #94a3b8; }
|
|
89
|
+
.bar-track { height: 8px; background: #1f2430; border-radius: 999px; overflow: hidden; }
|
|
90
|
+
.bar-fill { display: block; height: 100%; border-radius: 999px; }
|
|
91
|
+
.bar-count { text-align: right; color: #cbd5e1; font-weight: 600; }
|
|
92
|
+
h2 { margin: 36px 0 12px; font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: #94a3b8; }
|
|
93
|
+
.finding { background: #121621; border: 1px solid #222838; border-left: 3px solid var(--sev); border-radius: 14px; padding: 16px 18px; margin: 10px 0; }
|
|
94
|
+
.finding-head { display: flex; gap: 10px; align-items: center; }
|
|
95
|
+
.finding h3 { margin: 0; font-size: 16px; color: #f1f5f9; }
|
|
96
|
+
.pill { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--sev); border: 1px solid var(--sev); border-radius: 999px; padding: 1px 8px; }
|
|
97
|
+
code { display: inline-block; margin-top: 8px; font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; color: #7dd3fc; background: #0b0e15; border: 1px solid #1e2433; border-radius: 8px; padding: 2px 8px; }
|
|
98
|
+
.finding p { margin: 8px 0 0; color: #cbd5e1; }
|
|
99
|
+
.fix { color: #d1fae5 !important; }
|
|
100
|
+
code.inline { display: inline; margin: 0; padding: 1px 6px; font-size: 12.5px; color: #e2e8f0; }
|
|
101
|
+
.fix span { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: #34d399; margin-right: 8px; }
|
|
102
|
+
.clean { margin-top: 28px; padding: 22px; text-align: center; border: 1px dashed #2f3b2f; border-radius: 14px; color: #a7f3d0; font-weight: 600; }
|
|
103
|
+
footer { margin-top: 28px; text-align: center; color: #64748b; font-size: 12.5px; }
|
|
104
|
+
footer a { color: #94a3b8; }
|
|
105
|
+
@media (max-width: 640px) { .hero { grid-template-columns: 1fr; justify-items: center; text-align: center; } .counts { justify-content: center; } .card { padding: 22px; } }
|
|
106
|
+
</style>
|
|
107
|
+
</head>
|
|
108
|
+
<body>
|
|
109
|
+
<main>
|
|
110
|
+
<div class="brand"><b>Preflight</b><span>Launch readiness report</span></div>
|
|
111
|
+
<section class="card">
|
|
112
|
+
<div class="hero">
|
|
113
|
+
${gauge(report.score, color)}
|
|
114
|
+
<div>
|
|
115
|
+
<span class="grade">Grade ${report.grade}</span>
|
|
116
|
+
<div class="verdict">${VERDICT[report.grade]}</div>
|
|
117
|
+
<div class="counts">
|
|
118
|
+
<span class="count"><i style="background:${SEVERITY_COLOR.critical}"></i>${critical} critical</span>
|
|
119
|
+
<span class="count"><i style="background:${SEVERITY_COLOR.warning}"></i>${warning} warning${warning === 1 ? '' : 's'}</span>
|
|
120
|
+
<span class="count"><i style="background:${SEVERITY_COLOR.info}"></i>${info} info</span>
|
|
121
|
+
<span class="count">${report.rulesRun} checks · ${report.filesScanned ?? 0} files</span>
|
|
122
|
+
</div>
|
|
123
|
+
${categoryBars(report)}
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
${findingCards(report)}
|
|
127
|
+
</section>
|
|
128
|
+
<footer>Generated by vibe-preflight · MIT · <a href="https://github.com/erdellll/preflight">github.com/erdellll/preflight</a></footer>
|
|
129
|
+
</main>
|
|
130
|
+
</body>
|
|
131
|
+
</html>
|
|
132
|
+
`;
|
|
133
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { palette, gradeColor, severityColor, stripAnsi } from './colors.js';
|
|
2
|
+
import { CATEGORIES } from '../score.js';
|
|
3
|
+
|
|
4
|
+
const SEVERITY_ORDER = { critical: 0, warning: 1, info: 2 };
|
|
5
|
+
const ICON = { critical: '✖', warning: '▲', info: '●' };
|
|
6
|
+
const BAR_CELLS = 24;
|
|
7
|
+
|
|
8
|
+
const plural = (n, word) => `${n} ${word}${n === 1 || word === 'info' ? '' : 's'}`;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Renders the report card for a terminal.
|
|
12
|
+
* @param {object} report from run()
|
|
13
|
+
* @param {{ color?: boolean, width?: number }} [opts]
|
|
14
|
+
*/
|
|
15
|
+
export function renderTerminal(report, opts = {}) {
|
|
16
|
+
const color = opts.color ?? (Boolean(process.stdout.isTTY) && !process.env.NO_COLOR);
|
|
17
|
+
const c = palette(color);
|
|
18
|
+
const inner = Math.max(40, (opts.width ?? 50) - 2);
|
|
19
|
+
const row = (text = '') => `│${text}${' '.repeat(Math.max(0, inner - [...stripAnsi(text)].length))}│`;
|
|
20
|
+
const gc = c[gradeColor(report.grade)];
|
|
21
|
+
const filled = Math.round((report.score / 100) * BAR_CELLS);
|
|
22
|
+
const { critical, warning, info } = report.counts;
|
|
23
|
+
|
|
24
|
+
const head = ` ${c.bold('PREFLIGHT')}`;
|
|
25
|
+
const tag = c.dim('vibe-preflight');
|
|
26
|
+
const lines = [
|
|
27
|
+
`╭${'─'.repeat(inner)}╮`,
|
|
28
|
+
row(head + ' '.repeat(Math.max(1, inner - [...stripAnsi(head)].length - [...stripAnsi(tag)].length - 2)) + tag + ' '),
|
|
29
|
+
row(),
|
|
30
|
+
row(` ${gc(c.bold(`${report.score} / 100`))} ${gc(c.bold(`Grade ${report.grade}`))}`),
|
|
31
|
+
row(` ${gc('█'.repeat(filled))}${c.dim('░'.repeat(BAR_CELLS - filled))}`),
|
|
32
|
+
row(` ${c.red(`${critical} critical`)} · ${c.yellow(plural(warning, 'warning'))} · ${c.gray(`${info} info`)} · ${c.dim(`${report.rulesRun} checks`)}`),
|
|
33
|
+
`╰${'─'.repeat(inner)}╯`,
|
|
34
|
+
'',
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
if (!report.results.length) {
|
|
38
|
+
lines.push(` ${c.green('✔')} No issues found. Ready for takeoff.`, '');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
for (const category of CATEGORIES) {
|
|
42
|
+
const items = report.results
|
|
43
|
+
.filter((r) => r.category === category)
|
|
44
|
+
.sort((a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity]);
|
|
45
|
+
if (!items.length) continue;
|
|
46
|
+
lines.push(c.bold(category.toUpperCase()));
|
|
47
|
+
for (const r of items) {
|
|
48
|
+
const sc = c[severityColor(r.severity)];
|
|
49
|
+
lines.push(` ${sc(`${ICON[r.severity]} ${r.severity.toUpperCase().padEnd(8)}`)} ${c.bold(r.title)}`);
|
|
50
|
+
if (r.file) lines.push(` ${c.cyan(r.line ? `${r.file}:${r.line}` : r.file)}`);
|
|
51
|
+
lines.push(` ${r.message}`);
|
|
52
|
+
lines.push(` ${c.green('→')} ${r.fix}`);
|
|
53
|
+
lines.push('');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
lines.push(c.dim('Run with --html for a shareable report card.'));
|
|
58
|
+
return lines.join('\n') + '\n';
|
|
59
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const CLIENT_EXT = /\.(?:js|jsx|mjs|ts|tsx|vue|svelte|html|astro)$/;
|
|
2
|
+
const SERVER_PATH = new RegExp([
|
|
3
|
+
'(?:^|/)(?:api|server|servers|scripts|functions|edge-functions|backend|migrations|cron|workers)/',
|
|
4
|
+
'\\.server\\.', '(?:^|/)\\+server\\.', '(?:^|/)\\+page\\.server\\.', '(?:^|/)route\\.(?:js|ts|mjs)$',
|
|
5
|
+
'(?:^|/)middleware\\.', '(?:^|/)(?:next|nuxt|vite|astro|svelte|tailwind|postcss|webpack|babel|metro|jest|vitest|eslint)\\.config\\.',
|
|
6
|
+
'(?:^|/)server\\.(?:js|ts|mjs|cjs)$', '(?:^|/)(?:actions|instrumentation)\\.(?:js|ts)$',
|
|
7
|
+
].join('|'));
|
|
8
|
+
const CLIENT_DIR = /(?:^|\/)(?:src|app|pages|components|public|lib|static|assets|web|frontend|client|screens|hooks|services|utils|views|features|store|context|navigation)\//;
|
|
9
|
+
const ROOT_CLIENT = /^(?:App|main|index)\.(?:jsx|tsx|ts|js|vue|svelte)$|\.html$/;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* True for code that ends up in the browser or the app bundle. Pass the file's
|
|
13
|
+
* text to also honour a 'use server' directive.
|
|
14
|
+
*/
|
|
15
|
+
export function isClientFile(path, text = '') {
|
|
16
|
+
if (!CLIENT_EXT.test(path) || SERVER_PATH.test(path)) return false;
|
|
17
|
+
if (/^\s*['"]use server['"]/.test(text)) return false;
|
|
18
|
+
return path.includes('/') ? CLIENT_DIR.test(path) : ROOT_CLIENT.test(path);
|
|
19
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function toRegex(pattern) {
|
|
2
|
+
let p = pattern;
|
|
3
|
+
const anchored = p.startsWith('/') || (p.slice(0, -1).includes('/') && !p.startsWith('**/'));
|
|
4
|
+
p = p.replace(/^\//, '').replace(/\/$/, '').replace(/^\*\*\//, '');
|
|
5
|
+
const body = p
|
|
6
|
+
.split('**').map((part) => part.replace(/[.+^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '[^/]*').replace(/\?/g, '[^/]'))
|
|
7
|
+
.join('.*');
|
|
8
|
+
return new RegExp(anchored ? `^${body}(/.*)?$` : `(^|/)${body}(/.*)?$`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Applies .gitignore lines to `file` (a POSIX path relative to that .gitignore's
|
|
13
|
+
* folder). Supports *, **, ?, leading / and ! negation; the last match wins.
|
|
14
|
+
* Returns true/false, or `fallback` when no line matches.
|
|
15
|
+
*/
|
|
16
|
+
export function isGitignored(file, patterns, fallback = false) {
|
|
17
|
+
let ignored = fallback;
|
|
18
|
+
for (const raw of patterns) {
|
|
19
|
+
const negate = raw.startsWith('!');
|
|
20
|
+
const pattern = negate ? raw.slice(1) : raw;
|
|
21
|
+
if (pattern && toRegex(pattern).test(file)) ignored = !negate;
|
|
22
|
+
}
|
|
23
|
+
return ignored;
|
|
24
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Template for a new Preflight check. Copy this file to
|
|
3
|
+
* src/rules/<your-rule-id>.js, then add tests/fixtures/<your-rule-id>/bad
|
|
4
|
+
* (must be flagged) and tests/fixtures/<your-rule-id>/good (must stay quiet).
|
|
5
|
+
*
|
|
6
|
+
* project.files every scanned file, as POSIX paths relative to the root
|
|
7
|
+
* project.read(f) file contents ('' if unreadable)
|
|
8
|
+
* project.lines(f) file contents split into lines
|
|
9
|
+
* project.has(re) true if any file path matches the regex
|
|
10
|
+
* project.gitignore the root .gitignore lines
|
|
11
|
+
*/
|
|
12
|
+
export default {
|
|
13
|
+
id: 'example-rule',
|
|
14
|
+
title: 'Short, human title of the problem',
|
|
15
|
+
category: 'security', // security | reliability | launch
|
|
16
|
+
severity: 'warning', // critical | warning | info
|
|
17
|
+
check(project) {
|
|
18
|
+
const findings = [];
|
|
19
|
+
for (const file of project.files) {
|
|
20
|
+
project.lines(file).forEach((line, i) => {
|
|
21
|
+
if (line.includes('SOMETHING_RISKY')) {
|
|
22
|
+
findings.push({
|
|
23
|
+
file,
|
|
24
|
+
line: i + 1,
|
|
25
|
+
message: 'What is wrong, in one sentence.',
|
|
26
|
+
fix: 'What to do about it, in one sentence.',
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return findings;
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const CODE = /\.(?:js|jsx|mjs|cjs|ts|tsx|py|rb|go|php|json|toml|ya?ml)$/;
|
|
2
|
+
const PATTERNS = [
|
|
3
|
+
/\bcors\(\s*\)/,
|
|
4
|
+
/Access-Control-Allow-Origin['"]?\s*[:,=]\s*['"]\*['"]/i,
|
|
5
|
+
/\borigin\s*:\s*['"]\*['"]/,
|
|
6
|
+
/allow_origins\s*=\s*\[\s*['"]\*['"]\s*\]/,
|
|
7
|
+
];
|
|
8
|
+
|
|
9
|
+
/** Supabase ships this template with every edge function, so its fix has to name the file's own object. */
|
|
10
|
+
const SUPABASE_FUNCTION = /(?:^|\/)supabase\/functions\//;
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
id: 'cors-wildcard',
|
|
14
|
+
title: 'CORS allows every website',
|
|
15
|
+
category: 'security',
|
|
16
|
+
severity: 'warning',
|
|
17
|
+
check(project) {
|
|
18
|
+
const findings = [];
|
|
19
|
+
for (const file of project.files.filter((f) => CODE.test(f) && f !== 'package.json')) {
|
|
20
|
+
project.lines(file).forEach((line, i) => {
|
|
21
|
+
if (PATTERNS.some((re) => re.test(line))) {
|
|
22
|
+
findings.push({
|
|
23
|
+
file,
|
|
24
|
+
line: i + 1,
|
|
25
|
+
message: 'CORS is open to every origin, so any website can call this API from a visitor\'s browser.',
|
|
26
|
+
fix: SUPABASE_FUNCTION.test(file)
|
|
27
|
+
// Naming the object the template already has is easier to act on than generic middleware
|
|
28
|
+
// advice, and the finding itself is just as real (#22).
|
|
29
|
+
? "Replace `'*'` in the function's `corsHeaders` with your app's origin, for example `'Access-Control-Allow-Origin': 'https://yourapp.com'`."
|
|
30
|
+
: "List the origins you trust, for example `cors({ origin: ['https://yourapp.com'] })`.",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return findings;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const ENV_FILE = /(?:^|\/)\.env(?:\.[\w.-]+)?$/;
|
|
2
|
+
const SAFE = /\.?(?:example|sample|template|defaults|dist)$/;
|
|
3
|
+
const PUBLIC_PREFIX = /^(?:VITE_|NEXT_PUBLIC_)/;
|
|
4
|
+
|
|
5
|
+
function isPublicOnly(content) {
|
|
6
|
+
const keys = content
|
|
7
|
+
.split(/\r?\n/)
|
|
8
|
+
.map((line) => line.trim())
|
|
9
|
+
.filter((line) => line && !line.startsWith('#'))
|
|
10
|
+
.map((line) => line.match(/^(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/)?.[1])
|
|
11
|
+
.filter(Boolean);
|
|
12
|
+
|
|
13
|
+
return keys.length > 0 && keys.every((key) => PUBLIC_PREFIX.test(key));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
id: 'env-file-committed',
|
|
18
|
+
title: '.env file is not git-ignored',
|
|
19
|
+
category: 'security',
|
|
20
|
+
severity: 'critical',
|
|
21
|
+
check(project) {
|
|
22
|
+
return project.files
|
|
23
|
+
.filter((file) => {
|
|
24
|
+
if (!ENV_FILE.test(file) || SAFE.test(file)) return false;
|
|
25
|
+
|
|
26
|
+
// Encrypted dotenv-vault files are intended to be committed.
|
|
27
|
+
if (/(?:^|\/)\.env\.vault$/.test(file)) return false;
|
|
28
|
+
|
|
29
|
+
// Only flag files that are not ignored by Git.
|
|
30
|
+
if (project.isIgnored(file)) return false;
|
|
31
|
+
|
|
32
|
+
// Public-only environment files do not contain private secrets.
|
|
33
|
+
if (isPublicOnly(project.read(file))) return false;
|
|
34
|
+
|
|
35
|
+
return true;
|
|
36
|
+
})
|
|
37
|
+
.map((file) => ({
|
|
38
|
+
file,
|
|
39
|
+
message: `${file} holds secrets but .gitignore does not cover it, so it can be committed and pushed.`,
|
|
40
|
+
fix: 'Add `.env*` (and `!.env.example`) to .gitignore, run `git rm --cached ' + file + '`, and rotate any keys that were pushed.',
|
|
41
|
+
}));
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { readdir } from 'node:fs/promises';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Loads every rule in this folder. Files named index.js or starting with
|
|
5
|
+
* "_" (helpers and the template) are not rules.
|
|
6
|
+
*/
|
|
7
|
+
export async function loadRules() {
|
|
8
|
+
const dir = new URL('.', import.meta.url);
|
|
9
|
+
const names = (await readdir(dir)).filter((n) => n.endsWith('.js') && n !== 'index.js' && !n.startsWith('_'));
|
|
10
|
+
const rules = await Promise.all(names.map(async (n) => (await import(new URL(n, dir))).default));
|
|
11
|
+
return rules.filter((r) => r && typeof r.check === 'function').sort((a, b) => a.id.localeCompare(b.id));
|
|
12
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const HTML_ENTRY = /(?:^|\/)index\.html$/;
|
|
5
|
+
const LAYOUT = /^((?:.*\/)?)((?:src\/)?app)\/layout\.(?:tsx|jsx|js|ts)$/;
|
|
6
|
+
const ICON_LINK = /<link[^>]+rel=["'](?:shortcut )?icon["']/i;
|
|
7
|
+
const NEXT_ICON_EXT = ['ico', 'png', 'jpg', 'jpeg', 'svg', 'js', 'ts', 'tsx', 'jsx'];
|
|
8
|
+
|
|
9
|
+
// Image files are not in project.files (the walker skips binaries), so check the disk.
|
|
10
|
+
const anyExists = (root, paths) => paths.some((p) => existsSync(path.join(root, p)));
|
|
11
|
+
|
|
12
|
+
const rootIcons = (dir) => ['', 'public/'].flatMap((d) => [`${dir}${d}favicon.ico`, `${dir}${d}icon.png`]);
|
|
13
|
+
|
|
14
|
+
export default {
|
|
15
|
+
id: 'missing-favicon',
|
|
16
|
+
title: 'No favicon',
|
|
17
|
+
category: 'launch',
|
|
18
|
+
severity: 'info',
|
|
19
|
+
check(project) {
|
|
20
|
+
const findings = [];
|
|
21
|
+
for (const file of project.files) {
|
|
22
|
+
let hasIcon;
|
|
23
|
+
if (HTML_ENTRY.test(file) && !file.includes('/dist/')) {
|
|
24
|
+
const dir = file.slice(0, -'index.html'.length);
|
|
25
|
+
hasIcon = ICON_LINK.test(project.read(file)) || anyExists(project.root, rootIcons(dir));
|
|
26
|
+
} else {
|
|
27
|
+
const m = LAYOUT.exec(file);
|
|
28
|
+
if (!m) continue;
|
|
29
|
+
const [, dir, appDir] = m;
|
|
30
|
+
const appIcons = ['favicon', 'icon'].flatMap((n) => NEXT_ICON_EXT.map((ext) => `${dir}${appDir}/${n}.${ext}`));
|
|
31
|
+
hasIcon = /\bicons\s*:/.test(project.read(file)) || anyExists(project.root, [...appIcons, ...rootIcons(dir)]);
|
|
32
|
+
}
|
|
33
|
+
if (!hasIcon) {
|
|
34
|
+
findings.push({
|
|
35
|
+
file,
|
|
36
|
+
message: 'No favicon: browser tabs and bookmarks will show a blank or default icon.',
|
|
37
|
+
fix: 'Add public/favicon.ico (or app/icon.png in Next.js), or a <link rel="icon"> in your HTML.',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return findings;
|
|
42
|
+
},
|
|
43
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Only a page a visitor can land on: the root index.html, or one directly under public/ or src/.
|
|
3
|
+
* `supabase/templates/index.html` is the body of a confirmation email and `public/docs/index.html`
|
|
4
|
+
* is generated documentation, so neither is the entry page any of this advice is about (#21).
|
|
5
|
+
*/
|
|
6
|
+
const HTML_ENTRY = /^(?:index\.html|(?:public|src)\/index\.html)$/;
|
|
7
|
+
const LAYOUT = /^(?:src\/)?app\/layout\.(?:tsx|jsx|js|ts)$/;
|
|
8
|
+
/** Next.js generates the share image from this file rather than from an `openGraph` block. */
|
|
9
|
+
const OPENGRAPH_FILE = /(?:^|\/)app\/opengraph-image\.(?:png|jpe?g|gif|webp|avif|svg|tsx?|jsx?)$/;
|
|
10
|
+
|
|
11
|
+
function missingInHtml(text) {
|
|
12
|
+
const missing = [];
|
|
13
|
+
if (!/<title>[^<]+<\/title>/i.test(text)) missing.push('<title>');
|
|
14
|
+
if (!/<meta[^>]+name=["']description["']/i.test(text)) missing.push('meta description');
|
|
15
|
+
if (!/<meta[^>]+property=["']og:image["']/i.test(text)) missing.push('og:image');
|
|
16
|
+
return missing;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function missingInLayout(text) {
|
|
20
|
+
if (!/export\s+(?:const\s+metadata|(?:async\s+)?function\s+generateMetadata)/.test(text)) return ['metadata export'];
|
|
21
|
+
const missing = [];
|
|
22
|
+
if (!/\btitle\s*:/.test(text)) missing.push('title');
|
|
23
|
+
if (!/\bdescription\s*:/.test(text)) missing.push('description');
|
|
24
|
+
if (!/\bopenGraph\s*:/.test(text)) missing.push('openGraph image');
|
|
25
|
+
return missing;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export default {
|
|
29
|
+
id: 'missing-meta-tags',
|
|
30
|
+
title: 'Missing title, description or share image',
|
|
31
|
+
category: 'launch',
|
|
32
|
+
severity: 'warning',
|
|
33
|
+
check(project) {
|
|
34
|
+
const findings = [];
|
|
35
|
+
// A Next.js app can satisfy the share image with a file next to the layout, which the layout's
|
|
36
|
+
// own text cannot show.
|
|
37
|
+
const hasOpengraphFile = project.files.some((f) => OPENGRAPH_FILE.test(f));
|
|
38
|
+
for (const file of project.files) {
|
|
39
|
+
const isHtml = HTML_ENTRY.test(file) && !file.includes('/dist/');
|
|
40
|
+
const isLayout = LAYOUT.test(file);
|
|
41
|
+
if (!isHtml && !isLayout) continue;
|
|
42
|
+
const missing = isHtml
|
|
43
|
+
? missingInHtml(project.read(file))
|
|
44
|
+
: missingInLayout(project.read(file)).filter((m) => !(m === 'openGraph image' && hasOpengraphFile));
|
|
45
|
+
if (missing.length) {
|
|
46
|
+
findings.push({
|
|
47
|
+
file,
|
|
48
|
+
message: `Missing ${missing.join(', ')}: search results and link previews will look empty or broken.`,
|
|
49
|
+
fix: 'Add a page title, a one-sentence meta description and an og:image (1200x630) so shared links get a proper preview.',
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return findings;
|
|
54
|
+
},
|
|
55
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
const HTML_ENTRY = /(?:^|\/)index\.html$/;
|
|
5
|
+
const NEXT_ENTRY = /^((?:.*\/)?)((?:src\/)?)(app\/layout|pages\/_app)\.(?:tsx|jsx|js|ts)$/;
|
|
6
|
+
|
|
7
|
+
const anyExists = (root, paths) => paths.some((p) => existsSync(path.join(root, p)));
|
|
8
|
+
|
|
9
|
+
const staticRobots = (dir) => [`${dir}robots.txt`, `${dir}public/robots.txt`];
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
id: 'missing-robots-txt',
|
|
13
|
+
title: 'No robots.txt',
|
|
14
|
+
category: 'launch',
|
|
15
|
+
severity: 'info',
|
|
16
|
+
check(project) {
|
|
17
|
+
const findings = [];
|
|
18
|
+
for (const file of project.files) {
|
|
19
|
+
let candidates;
|
|
20
|
+
if (HTML_ENTRY.test(file) && !file.includes('/dist/')) {
|
|
21
|
+
candidates = staticRobots(file.slice(0, -'index.html'.length));
|
|
22
|
+
} else {
|
|
23
|
+
const m = NEXT_ENTRY.exec(file);
|
|
24
|
+
if (!m) continue;
|
|
25
|
+
const [, dir, src] = m;
|
|
26
|
+
const routes = ['txt', 'ts', 'js', 'tsx', 'jsx'].map((ext) => `${dir}${src}app/robots.${ext}`);
|
|
27
|
+
candidates = [...routes, ...staticRobots(dir)];
|
|
28
|
+
}
|
|
29
|
+
if (!anyExists(project.root, candidates)) {
|
|
30
|
+
findings.push({
|
|
31
|
+
file,
|
|
32
|
+
message: 'No robots.txt: crawlers get a 404 and have no pointer to your sitemap.',
|
|
33
|
+
fix: 'Add public/robots.txt (or app/robots.ts in Next.js) that allows crawling and links your sitemap.',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return findings;
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const MONITORING = /"(?:@sentry\/[\w-]+|sentry-[\w-]+|posthog-js|posthog-node|posthog-react-native|@bugsnag\/[\w-]+|rollbar|logrocket|@datadog\/browser-rum|@highlight-run\/[\w-]+|@honeybadger-io\/[\w-]+|@appsignal\/[\w-]+|newrelic|@newrelic\/[\w-]+)"\s*:/;
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
id: 'no-error-monitoring',
|
|
5
|
+
title: 'No error monitoring',
|
|
6
|
+
category: 'reliability',
|
|
7
|
+
severity: 'info',
|
|
8
|
+
check(project) {
|
|
9
|
+
if (!project.files.includes('package.json')) return [];
|
|
10
|
+
if (MONITORING.test(project.read('package.json'))) return [];
|
|
11
|
+
return [{
|
|
12
|
+
file: 'package.json',
|
|
13
|
+
message: 'No error-monitoring tool is installed, so you will not hear about crashes your users hit.',
|
|
14
|
+
fix: 'Add a free tier of Sentry (`npx @sentry/wizard`) or PostHog so errors reach you before users complain.',
|
|
15
|
+
}];
|
|
16
|
+
},
|
|
17
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const CODE = /\.(?:js|jsx|mjs|ts|tsx|vue|svelte|html|astro|dart|swift|kt|py)$/;
|
|
2
|
+
const COLLECTS_DATA = /supabase\.auth\.|\bsignUp\(|createUserWithEmailAndPassword|signInWithPassword|<input[^>]{0,1000}type=["']email|next-auth|@clerk\/|@auth0\/|firebase\/auth|useSignUp\(/;
|
|
3
|
+
const PRIVACY = /privacy/i;
|
|
4
|
+
/**
|
|
5
|
+
* A privacy policy can also be a page the app links to rather than one it ships, which is how an
|
|
6
|
+
* Expo or React Native app does it. The URL has to lead somewhere policy-like, so a bare mention of
|
|
7
|
+
* the word in a sentence does not silence the check.
|
|
8
|
+
*/
|
|
9
|
+
const POLICY_URL = /https?:\/\/[^\s"'`<>]*privacy[^\s"'`<>]*/i;
|
|
10
|
+
/** Apple's privacy manifest states what the app collects; it is not a policy a user can read. */
|
|
11
|
+
const APPLE_MANIFEST = /\.xcprivacy$/i;
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
id: 'no-privacy-policy',
|
|
15
|
+
title: 'No privacy policy',
|
|
16
|
+
category: 'launch',
|
|
17
|
+
severity: 'warning',
|
|
18
|
+
check(project) {
|
|
19
|
+
// A policy the app ships silences the check, unless the only matching path is Apple's manifest:
|
|
20
|
+
// `ios/PrivacyInfo.xcprivacy` says what the app collects, not what a user may read (#20).
|
|
21
|
+
if (project.files.some((f) => PRIVACY.test(f) && !APPLE_MANIFEST.test(f))) return [];
|
|
22
|
+
const collector = project.files.find((f) => CODE.test(f) && COLLECTS_DATA.test(project.read(f)));
|
|
23
|
+
if (!collector) return [];
|
|
24
|
+
if (project.files.some((f) => CODE.test(f) && POLICY_URL.test(project.read(f)))) return [];
|
|
25
|
+
return [{
|
|
26
|
+
file: collector,
|
|
27
|
+
message: 'The app signs users up or collects emails but has no privacy policy page. App stores, payment providers and privacy laws require one.',
|
|
28
|
+
fix: 'Add a /privacy page that says what you collect, why, who processes it (for example Supabase, Stripe) and how users delete their data.',
|
|
29
|
+
}];
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { isClientFile } from './_client-paths.js';
|
|
2
|
+
|
|
3
|
+
const SECRETS = [
|
|
4
|
+
{ name: 'Stripe secret key', re: /\b[sr]k_live_[0-9A-Za-z]{10,}/ },
|
|
5
|
+
{ name: 'Anthropic API key', re: /\bsk-ant-[0-9A-Za-z_-]{20,}/ },
|
|
6
|
+
{ name: 'OpenAI API key', re: /\bsk-proj-[0-9A-Za-z_-]{20,}/ },
|
|
7
|
+
{ name: 'AWS access key', re: /\bAKIA[0-9A-Z]{16}\b/ },
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
const JWT = /\beyJ[\w-]+\.([\w-]+)\.[\w-]+/g;
|
|
11
|
+
|
|
12
|
+
/** True if a JWT on this line carries the Supabase service_role claim. */
|
|
13
|
+
function hasServiceRoleJwt(line) {
|
|
14
|
+
for (const m of line.matchAll(JWT)) {
|
|
15
|
+
try {
|
|
16
|
+
if (/"role"\s*:\s*"service_role"/.test(Buffer.from(m[1], 'base64url').toString('utf8'))) return true;
|
|
17
|
+
} catch { /* not a JWT */ }
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
id: 'secret-in-client',
|
|
24
|
+
title: 'Live secret in client-side code',
|
|
25
|
+
category: 'security',
|
|
26
|
+
severity: 'critical',
|
|
27
|
+
check(project) {
|
|
28
|
+
const findings = [];
|
|
29
|
+
for (const file of project.files.filter((f) => isClientFile(f, project.read(f)))) {
|
|
30
|
+
project.lines(file).forEach((line, i) => {
|
|
31
|
+
const hit = SECRETS.find((s) => s.re.test(line)) ?? (hasServiceRoleJwt(line) ? { name: 'Supabase service_role key' } : null);
|
|
32
|
+
if (hit) {
|
|
33
|
+
findings.push({
|
|
34
|
+
file,
|
|
35
|
+
line: i + 1,
|
|
36
|
+
message: `A ${hit.name} is in code that ships to the browser or app, where anyone can read it.`,
|
|
37
|
+
fix: 'Move the key to a server-side environment variable used only by an API route, then rotate it: treat it as leaked.',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return findings;
|
|
43
|
+
},
|
|
44
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const CODE = /\.(?:js|jsx|mjs|cjs|ts|tsx|py|rb|go|php)$/;
|
|
2
|
+
const STRIPE_EVENT = /checkout\.session\.completed|invoice\.(?:paid|payment_succeeded)|customer\.subscription\.|payment_intent\.succeeded/;
|
|
3
|
+
const HANDLER = /export\s+(?:async\s+)?(?:function\s+POST|const\s+POST)|\b(?:app|router|server)\.post\(|@app\.(?:post|route)\(|stripe-signature|def\s+\w*webhook/i;
|
|
4
|
+
const VERIFIED = /construct_?event/i;
|
|
5
|
+
|
|
6
|
+
export default {
|
|
7
|
+
id: 'stripe-webhook-unverified',
|
|
8
|
+
title: 'Stripe webhook without signature check',
|
|
9
|
+
category: 'security',
|
|
10
|
+
severity: 'critical',
|
|
11
|
+
check(project) {
|
|
12
|
+
const code = project.files.filter((f) => CODE.test(f));
|
|
13
|
+
// A project that verifies anywhere (often in a shared helper) is treated as verified.
|
|
14
|
+
if (code.some((f) => VERIFIED.test(project.read(f)))) return [];
|
|
15
|
+
return code
|
|
16
|
+
.filter((f) => {
|
|
17
|
+
const text = project.read(f);
|
|
18
|
+
return HANDLER.test(text) && STRIPE_EVENT.test(text);
|
|
19
|
+
})
|
|
20
|
+
.map((file) => ({
|
|
21
|
+
file,
|
|
22
|
+
message: 'This Stripe webhook handler never verifies the signature, so anyone can POST a fake "payment succeeded" event.',
|
|
23
|
+
fix: 'Read the raw body and call `stripe.webhooks.constructEvent(body, signature, STRIPE_WEBHOOK_SECRET)` before trusting the event.',
|
|
24
|
+
}));
|
|
25
|
+
},
|
|
26
|
+
};
|