vibe-preflight 0.1.0 → 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/plugin.json +1 -1
- package/README.md +39 -3
- package/package.json +35 -5
- package/src/cli.js +76 -12
- package/src/project.js +4 -0
- package/src/rules/cors-wildcard.js +8 -1
- package/src/rules/env-file-committed.js +27 -2
- package/src/rules/missing-favicon.js +43 -0
- package/src/rules/missing-meta-tags.js +14 -2
- package/src/rules/missing-robots-txt.js +39 -0
- package/src/rules/no-privacy-policy.js +13 -2
- package/src/run.js +19 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "preflight",
|
|
3
3
|
"description": "Check whether your vibe-coded app is ready to launch: leaked keys, open databases, unverified payments and missing launch basics, with a fix for every finding.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"author": { "name": "erdellll" },
|
|
6
6
|
"homepage": "https://github.com/erdellll/preflight",
|
|
7
7
|
"license": "MIT",
|
package/README.md
CHANGED
|
@@ -9,6 +9,11 @@ Preflight scans your project for leaked keys, open databases, unverified payment
|
|
|
9
9
|
[](LICENSE)
|
|
10
10
|
[](package.json)
|
|
11
11
|
[](CONTRIBUTING.md)
|
|
12
|
+
[](https://www.npmjs.com/package/vibe-preflight)
|
|
13
|
+
[](https://www.npmjs.com/package/vibe-preflight)
|
|
14
|
+
[](https://github.com/erdellll/preflight/actions/workflows/ci.yml)
|
|
15
|
+
|
|
16
|
+
**English** · [हिन्दी](docs/README.hi.md)
|
|
12
17
|
|
|
13
18
|

|
|
14
19
|
|
|
@@ -34,7 +39,7 @@ Scans a deliberately broken demo app (every secret is fake) so you can see what
|
|
|
34
39
|
|
|
35
40
|
## What it checks
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
10 checks today, across security, reliability and launch basics. See [all checks](docs/rules.md).
|
|
38
43
|
|
|
39
44
|
| | |
|
|
40
45
|
|---|---|
|
|
@@ -48,12 +53,13 @@ Scans a deliberately broken demo app (every secret is fake) so you can see what
|
|
|
48
53
|
```bash
|
|
49
54
|
npx vibe-preflight [path] # scan a folder (default: current folder)
|
|
50
55
|
npx vibe-preflight --html # also write a shareable preflight-report.html
|
|
51
|
-
npx vibe-preflight --json # machine-readable output
|
|
56
|
+
npx vibe-preflight --json # machine-readable output ([JSON format](docs/json.md))
|
|
52
57
|
npx vibe-preflight --ignore a,b # skip checks by id
|
|
53
58
|
npx vibe-preflight --fail-on warning # exit code policy: critical (default) | warning | never
|
|
54
59
|
```
|
|
60
|
+
Set NO_COLOR=1 to turn off coloured output.
|
|
55
61
|
|
|
56
|
-
Silence a finding that points at a line with `// preflight-ignore <check-id>` on that line or the line above.
|
|
62
|
+
Silence a finding that points at a line with `// preflight-ignore <check-id>` on that line or the line above. A finding about a whole file (a committed `.env`, an unverified webhook) takes the same comment in the file's first five lines. Anything you want gone project-wide, including findings with no file at all, uses `--ignore <check-id>`.
|
|
57
63
|
|
|
58
64
|
## Use it in CI
|
|
59
65
|
|
|
@@ -84,6 +90,36 @@ Every check is one small file plus two example folders, one it must flag and one
|
|
|
84
90
|
|
|
85
91
|
Preflight catches common, high-impact mistakes with fast pattern checks. A clean report means none of its checks fired, not that your app is secure. Use it as a seatbelt, not a substitute for a review.
|
|
86
92
|
|
|
93
|
+
## FAQ
|
|
94
|
+
|
|
95
|
+
**Does Preflight send my code anywhere?**
|
|
96
|
+
|
|
97
|
+
No. Preflight runs entirely on your local machine, makes no network calls and does not collect telemetry. Your code never leaves your computer.
|
|
98
|
+
|
|
99
|
+
**Does a 100/100 score mean my app is secure?**
|
|
100
|
+
|
|
101
|
+
No. It only means that none of Preflight's checks detected an issue. See the [Not a security audit](#not-a-security-audit) section for more details.
|
|
102
|
+
|
|
103
|
+
**How do I silence a false positive?**
|
|
104
|
+
|
|
105
|
+
Use `// preflight-ignore <check-id>` on the affected line or `--ignore <check-id>` when running Preflight. Please also open a GitHub issue labelled or titled "False positive" so the check can be improved.
|
|
106
|
+
|
|
107
|
+
**Which stacks does it understand?**
|
|
108
|
+
|
|
109
|
+
Preflight can scan any project's files, but its checks work best with Next.js, Vite, Supabase, Stripe, Express and plain HTML.
|
|
110
|
+
|
|
111
|
+
**Why is a symlinked file not checked?**
|
|
112
|
+
|
|
113
|
+
Symbolic links are skipped on purpose, both files and folders. Following them can loop — a folder linked into itself never ends — and can read files outside the project you asked Preflight to scan. A `.env` that is a symlink to a file elsewhere is therefore not reported; copy it in, or point the check at the folder that really holds it. The comment on `walk` in `src/project.js` says the same thing next to the code.
|
|
114
|
+
|
|
87
115
|
## License
|
|
88
116
|
|
|
89
117
|
[MIT](LICENSE). Free for any use.
|
|
118
|
+
|
|
119
|
+
## Contributors
|
|
120
|
+
|
|
121
|
+
Thanks to everyone who has made Preflight better! 💛
|
|
122
|
+
|
|
123
|
+
<a href="https://github.com/erdellll/preflight/graphs/contributors">
|
|
124
|
+
<img src="https://contrib.rocks/image?repo=erdellll/preflight" alt="Preflight contributors" />
|
|
125
|
+
</a>
|
package/package.json
CHANGED
|
@@ -1,24 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vibe-preflight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Is your vibe-coded app ready to launch? One command checks for leaked keys, open databases and missing launch basics, then gives you a report card.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"vibe-preflight": "bin/preflight.js",
|
|
8
8
|
"preflight": "bin/preflight.js"
|
|
9
9
|
},
|
|
10
|
-
"files": [
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"src",
|
|
13
|
+
"examples",
|
|
14
|
+
".claude-plugin",
|
|
15
|
+
"commands"
|
|
16
|
+
],
|
|
11
17
|
"scripts": {
|
|
12
|
-
"test": "node --test"
|
|
18
|
+
"test": "node --test",
|
|
19
|
+
"demo": "node bin/preflight.js --demo --fail-on never"
|
|
13
20
|
},
|
|
14
21
|
"engines": {
|
|
15
22
|
"node": ">=20"
|
|
16
23
|
},
|
|
17
|
-
"keywords": [
|
|
24
|
+
"keywords": [
|
|
25
|
+
"vibe-coding",
|
|
26
|
+
"launch",
|
|
27
|
+
"checklist",
|
|
28
|
+
"security",
|
|
29
|
+
"supabase",
|
|
30
|
+
"stripe",
|
|
31
|
+
"cli",
|
|
32
|
+
"claude-code",
|
|
33
|
+
"nextjs",
|
|
34
|
+
"vite",
|
|
35
|
+
"expo",
|
|
36
|
+
"react-native",
|
|
37
|
+
"firebase",
|
|
38
|
+
"lovable",
|
|
39
|
+
"bolt",
|
|
40
|
+
"cursor",
|
|
41
|
+
"secrets",
|
|
42
|
+
"pre-launch"
|
|
43
|
+
],
|
|
18
44
|
"author": "erdellll",
|
|
19
45
|
"license": "MIT",
|
|
20
46
|
"repository": {
|
|
21
47
|
"type": "git",
|
|
22
48
|
"url": "git+https://github.com/erdellll/preflight.git"
|
|
23
|
-
}
|
|
49
|
+
},
|
|
50
|
+
"bugs": {
|
|
51
|
+
"url": "https://github.com/erdellll/preflight/issues"
|
|
52
|
+
},
|
|
53
|
+
"homepage": "https://github.com/erdellll/preflight#readme"
|
|
24
54
|
}
|
package/src/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseArgs } from 'node:util';
|
|
2
|
-
import { existsSync, statSync, writeFileSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { existsSync, statSync, writeFileSync, readFileSync, rmSync } from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { run } from './run.js';
|
|
5
5
|
import { renderTerminal } from './report/terminal.js';
|
|
@@ -8,6 +8,41 @@ import { buildDemo } from './demo.js';
|
|
|
8
8
|
|
|
9
9
|
const LEVELS = { critical: ['critical'], warning: ['critical', 'warning'], never: [] };
|
|
10
10
|
|
|
11
|
+
/** Levenshtein distance, for "did you mean" on a mistyped check id. */
|
|
12
|
+
const distance = (a, b) => {
|
|
13
|
+
let previous = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
14
|
+
for (let i = 1; i <= a.length; i++) {
|
|
15
|
+
const current = [i];
|
|
16
|
+
for (let j = 1; j <= b.length; j++) {
|
|
17
|
+
current[j] = Math.min(
|
|
18
|
+
previous[j] + 1,
|
|
19
|
+
current[j - 1] + 1,
|
|
20
|
+
previous[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1),
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
previous = current;
|
|
24
|
+
}
|
|
25
|
+
return previous[b.length];
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The id closest to `typed`, or null when nothing is close enough to be worth suggesting.
|
|
30
|
+
* Half the longer id's length keeps a wildly different id from producing a silly guess.
|
|
31
|
+
*/
|
|
32
|
+
const closestId = (typed, ids) => {
|
|
33
|
+
let best = null;
|
|
34
|
+
let bestDistance = Infinity;
|
|
35
|
+
for (const id of ids) {
|
|
36
|
+
const d = distance(typed, id);
|
|
37
|
+
if (d < bestDistance) {
|
|
38
|
+
bestDistance = d;
|
|
39
|
+
best = id;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const limit = Math.max(2, Math.floor(Math.max(typed.length, (best ?? '').length) / 2));
|
|
43
|
+
return bestDistance <= limit ? best : null;
|
|
44
|
+
};
|
|
45
|
+
|
|
11
46
|
const HELP = `vibe-preflight: is your vibe-coded app ready to launch?
|
|
12
47
|
|
|
13
48
|
Usage
|
|
@@ -43,7 +78,7 @@ export async function main(argv, io) {
|
|
|
43
78
|
for (let i = 0; i < argv.length; i++) {
|
|
44
79
|
if (argv[i] === '--html') {
|
|
45
80
|
const next = argv[i + 1];
|
|
46
|
-
norm.push('--html', next && !next.startsWith('-') &&
|
|
81
|
+
norm.push('--html', next && !next.startsWith('-') && /\.html?$/i.test(next) ? argv[++i] : 'preflight-report.html');
|
|
47
82
|
} else norm.push(argv[i]);
|
|
48
83
|
}
|
|
49
84
|
args = parseArgs({
|
|
@@ -78,16 +113,45 @@ export async function main(argv, io) {
|
|
|
78
113
|
|
|
79
114
|
const report = await run(root, { ignore: values.ignore ? values.ignore.split(',').map((s) => s.trim()).filter(Boolean) : [] });
|
|
80
115
|
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
116
|
+
// A mistyped --ignore switches off nothing, which looks exactly like the check passing (#19).
|
|
117
|
+
if (report.unknownIgnore?.length) {
|
|
118
|
+
const { loadRules } = await import('./rules/index.js');
|
|
119
|
+
const ids = (await loadRules()).map((r) => r.id);
|
|
120
|
+
for (const id of report.unknownIgnore) {
|
|
121
|
+
const near = closestId(id, ids);
|
|
122
|
+
io.stderr.write(
|
|
123
|
+
`--ignore: no check has the id "${id}"${near ? ` (did you mean "${near}"?)` : ''}. ` +
|
|
124
|
+
`It ignored nothing; run --help or see docs/rules.md for the ids.\n`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
89
127
|
}
|
|
90
128
|
|
|
91
|
-
|
|
92
|
-
|
|
129
|
+
// A --demo run copied the sample app into a temp folder; it is this run's to remove, and a throw
|
|
130
|
+
// in rendering or --html must not leave it behind (#25).
|
|
131
|
+
try {
|
|
132
|
+
// Checked before anything is printed: a report card that cannot be written is a usage error, and
|
|
133
|
+
// printing the whole report first then crashing with ENOENT buries the reason (#17).
|
|
134
|
+
if (values.html) {
|
|
135
|
+
const file = path.resolve(io.cwd, values.html);
|
|
136
|
+
if (!existsSync(path.dirname(file))) {
|
|
137
|
+
io.stderr.write(`Can't write ${values.html}: folder does not exist (${path.dirname(file)})\n`);
|
|
138
|
+
return 2;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (values.demo && !values.json) io.stdout.write('Scanning the Preflight demo app (deliberately broken, every secret is fake)...\n\n');
|
|
143
|
+
if (values.json) io.stdout.write(JSON.stringify(report, null, 2) + '\n');
|
|
144
|
+
else io.stdout.write(renderTerminal(report));
|
|
145
|
+
|
|
146
|
+
if (values.html) {
|
|
147
|
+
const file = path.resolve(io.cwd, values.html);
|
|
148
|
+
writeFileSync(file, renderHtml(report));
|
|
149
|
+
if (!values.json) io.stdout.write(`Report card written to ${path.relative(io.cwd, file) || file}\n`);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const failing = LEVELS[values['fail-on']];
|
|
153
|
+
return report.results.some((r) => failing.includes(r.severity)) ? 1 : 0;
|
|
154
|
+
} finally {
|
|
155
|
+
if (values.demo) rmSync(root, { recursive: true, force: true });
|
|
156
|
+
}
|
|
93
157
|
}
|
package/src/project.js
CHANGED
|
@@ -31,6 +31,10 @@ async function walk(root, dir, out) {
|
|
|
31
31
|
}
|
|
32
32
|
for (const entry of entries) {
|
|
33
33
|
const full = path.join(dir, entry.name);
|
|
34
|
+
// readdir reports a symlink as neither a file nor a directory unless it is dereferenced, so
|
|
35
|
+
// both branches below skip one on purpose: following links can loop (a folder linked into
|
|
36
|
+
// itself) and can read outside the project, and a scan is meant to report on the tree it was
|
|
37
|
+
// given. A symlinked `.env` is therefore not checked (#24).
|
|
34
38
|
if (entry.isDirectory()) {
|
|
35
39
|
if (!SKIP_DIRS.has(entry.name)) await walk(root, full, out);
|
|
36
40
|
} else if (entry.isFile()) {
|
|
@@ -6,6 +6,9 @@ const PATTERNS = [
|
|
|
6
6
|
/allow_origins\s*=\s*\[\s*['"]\*['"]\s*\]/,
|
|
7
7
|
];
|
|
8
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
|
+
|
|
9
12
|
export default {
|
|
10
13
|
id: 'cors-wildcard',
|
|
11
14
|
title: 'CORS allows every website',
|
|
@@ -20,7 +23,11 @@ export default {
|
|
|
20
23
|
file,
|
|
21
24
|
line: i + 1,
|
|
22
25
|
message: 'CORS is open to every origin, so any website can call this API from a visitor\'s browser.',
|
|
23
|
-
fix:
|
|
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'] })`.",
|
|
24
31
|
});
|
|
25
32
|
}
|
|
26
33
|
});
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
const ENV_FILE = /(?:^|\/)\.env(?:\.[\w.-]+)?$/;
|
|
2
|
-
const SAFE =
|
|
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
|
+
}
|
|
3
15
|
|
|
4
16
|
export default {
|
|
5
17
|
id: 'env-file-committed',
|
|
@@ -8,7 +20,20 @@ export default {
|
|
|
8
20
|
severity: 'critical',
|
|
9
21
|
check(project) {
|
|
10
22
|
return project.files
|
|
11
|
-
.filter((
|
|
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
|
+
})
|
|
12
37
|
.map((file) => ({
|
|
13
38
|
file,
|
|
14
39
|
message: `${file} holds secrets but .gitignore does not cover it, so it can be committed and pushed.`,
|
|
@@ -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
|
+
};
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
|
|
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)$/;
|
|
2
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?)$/;
|
|
3
10
|
|
|
4
11
|
function missingInHtml(text) {
|
|
5
12
|
const missing = [];
|
|
@@ -25,11 +32,16 @@ export default {
|
|
|
25
32
|
severity: 'warning',
|
|
26
33
|
check(project) {
|
|
27
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));
|
|
28
38
|
for (const file of project.files) {
|
|
29
39
|
const isHtml = HTML_ENTRY.test(file) && !file.includes('/dist/');
|
|
30
40
|
const isLayout = LAYOUT.test(file);
|
|
31
41
|
if (!isHtml && !isLayout) continue;
|
|
32
|
-
const missing = isHtml
|
|
42
|
+
const missing = isHtml
|
|
43
|
+
? missingInHtml(project.read(file))
|
|
44
|
+
: missingInLayout(project.read(file)).filter((m) => !(m === 'openGraph image' && hasOpengraphFile));
|
|
33
45
|
if (missing.length) {
|
|
34
46
|
findings.push({
|
|
35
47
|
file,
|
|
@@ -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
|
+
};
|
|
@@ -1,6 +1,14 @@
|
|
|
1
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[^>]
|
|
2
|
+
const COLLECTS_DATA = /supabase\.auth\.|\bsignUp\(|createUserWithEmailAndPassword|signInWithPassword|<input[^>]{0,1000}type=["']email|next-auth|@clerk\/|@auth0\/|firebase\/auth|useSignUp\(/;
|
|
3
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;
|
|
4
12
|
|
|
5
13
|
export default {
|
|
6
14
|
id: 'no-privacy-policy',
|
|
@@ -8,9 +16,12 @@ export default {
|
|
|
8
16
|
category: 'launch',
|
|
9
17
|
severity: 'warning',
|
|
10
18
|
check(project) {
|
|
11
|
-
|
|
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 [];
|
|
12
22
|
const collector = project.files.find((f) => CODE.test(f) && COLLECTS_DATA.test(project.read(f)));
|
|
13
23
|
if (!collector) return [];
|
|
24
|
+
if (project.files.some((f) => CODE.test(f) && POLICY_URL.test(project.read(f)))) return [];
|
|
14
25
|
return [{
|
|
15
26
|
file: collector,
|
|
16
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.',
|
package/src/run.js
CHANGED
|
@@ -3,12 +3,18 @@ import { loadRules } from './rules/index.js';
|
|
|
3
3
|
import { score } from './score.js';
|
|
4
4
|
|
|
5
5
|
function ignoredInline(project, finding, ruleId) {
|
|
6
|
-
if (!finding.file
|
|
6
|
+
if (!finding.file) return false;
|
|
7
7
|
const lines = project.lines(finding.file);
|
|
8
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));
|
|
9
12
|
return [lines[finding.line - 1], lines[finding.line - 2]].some((l) => l?.includes(token));
|
|
10
13
|
}
|
|
11
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
|
+
|
|
12
18
|
/**
|
|
13
19
|
* Scans a project and returns the full report.
|
|
14
20
|
* @param {string} root
|
|
@@ -18,6 +24,10 @@ export async function run(root, opts = {}) {
|
|
|
18
24
|
const project = await loadProject(root);
|
|
19
25
|
const rules = opts.rules ?? (await loadRules());
|
|
20
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));
|
|
21
31
|
const results = [];
|
|
22
32
|
for (const rule of rules) {
|
|
23
33
|
if (ignore.has(rule.id)) continue;
|
|
@@ -26,5 +36,12 @@ export async function run(root, opts = {}) {
|
|
|
26
36
|
results.push({ ruleId: rule.id, title: rule.title, category: rule.category, severity: rule.severity, ...finding });
|
|
27
37
|
}
|
|
28
38
|
}
|
|
29
|
-
return {
|
|
39
|
+
return {
|
|
40
|
+
root,
|
|
41
|
+
results,
|
|
42
|
+
...score(results),
|
|
43
|
+
rulesRun: rules.length,
|
|
44
|
+
filesScanned: project.files.length,
|
|
45
|
+
...(unknownIgnore.length ? { unknownIgnore } : {}),
|
|
46
|
+
};
|
|
30
47
|
}
|