@heyramzi/lint 2.12.0 → 2.13.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 +7 -3
- package/package.json +1 -1
- package/repo-rules/blueprints.js +75 -0
- package/repo-rules/npx.js +48 -0
- package/repo-rules.js +4 -0
package/README.md
CHANGED
|
@@ -298,7 +298,9 @@ failure says what to do instead. It reads the staged blob, so it judges what the
|
|
|
298
298
|
- **Import maps:** a published `@heyramzi/*` package with `#src` imports maps `"#src/*.js"` to
|
|
299
299
|
`./src/*.ts` when it ships src, or `"#src/*"` to `{ types, default }` when it ships dist.
|
|
300
300
|
- **Credentials:** an `_authToken` line in a committed `.npmrc`, and the dead
|
|
301
|
-
`GITHUB_PRIVATE_PACKAGES_TOKEN` name in an install file.
|
|
301
|
+
`GITHUB_PRIVATE_PACKAGES_TOKEN` name in an install file. A Make blueprint (a JSON file with a
|
|
302
|
+
`flow`) fails on a literal in a header or field named like a secret, key, token, password or
|
|
303
|
+
client id, or inside a body or query string. A `{{mapping}}` or `<PLACEHOLDER>` passes.
|
|
302
304
|
- **Workflows:** a hosted runner, a write to `~/.npmrc`, a `pull_request` trigger, and any Node
|
|
303
305
|
that isn't 24.
|
|
304
306
|
- **Toolchain:** ESLint, knip, Prettier, Biome and Husky (dependency, script or config file),
|
|
@@ -319,8 +321,10 @@ No allowlist, no config.
|
|
|
319
321
|
`heyramzi-slop <file|dir|->` runs the exact patterns, and `--register=<name>` adds the rates of a
|
|
320
322
|
voice. By default each check reports its first hit per file, which settles pass or fail. `--all`
|
|
321
323
|
lists every hit of every check with its line (`line` in `--json`), and the exit code doesn't
|
|
322
|
-
change. A refused push prints that command with this checkout's path: inside a repo, `npx
|
|
323
|
-
heyramzi-slop` runs the repo's installed copy, which can be older than the gate's.
|
|
324
|
+
change. A refused push prints that command with this checkout's path: inside a repo, `npx -y -p
|
|
325
|
+
@heyramzi/lint heyramzi-slop` runs the repo's installed copy, which can be older than the gate's.
|
|
326
|
+
Always name the package with `-p`: the bare npm name `heyramzi-slop` belongs to nobody, and the
|
|
327
|
+
`npx-bare-bin` repo rule refuses a file that calls it.
|
|
324
328
|
|
|
325
329
|
`--jev` also asks TypeSafe Jev (`jev.js`) to score each sentence and paragraph against the
|
|
326
330
|
humanizer shapes. Those scores are a report unless `--shape-block=<0.6-1>` names a bar. Jev reads
|
package/package.json
CHANGED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** Literal credentials in a committed Make blueprint. */
|
|
2
|
+
|
|
3
|
+
// WHY client id: a Royal Mail export held X-IBM-Client-Id beside its secret, and the pair is the login.
|
|
4
|
+
const SECRET_NAME =
|
|
5
|
+
/secret|token|passw(or)?d|api[-_]?key|apikey|authorization|client[-_]?id|private[-_]?key|access[-_]?key/i;
|
|
6
|
+
const INLINE_FIELD =
|
|
7
|
+
"(password|passwd|secret|client[_-]?secret|api[_-]?key|apikey|access[_-]?token)";
|
|
8
|
+
const INLINE = [
|
|
9
|
+
new RegExp(`<${INLINE_FIELD}>\\s*([^<\\s][^<]*)</`, "i"),
|
|
10
|
+
new RegExp(`"${INLINE_FIELD}"\\s*:\\s*"([^"]+)"`, "i"),
|
|
11
|
+
new RegExp(`[?&]${INLINE_FIELD}=([^&\\s"]+)`, "i"),
|
|
12
|
+
/\b(bearer|basic)\s+([A-Za-z0-9._~+/=-]{16,})/i,
|
|
13
|
+
];
|
|
14
|
+
const PLACEHOLDER = /^<[A-Z][A-Z0-9_]*>$/;
|
|
15
|
+
|
|
16
|
+
/** A value a person typed, as opposed to a Make mapping or a <PLACEHOLDER>. */
|
|
17
|
+
function isLiteral(value) {
|
|
18
|
+
const trimmed = value.trim();
|
|
19
|
+
return trimmed.length >= 8 && !trimmed.includes("{{") && !PLACEHOLDER.test(trimmed);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The scenario object in an export, a `blueprint` wrapper or an API response, or null. */
|
|
23
|
+
function scenarioOf(json) {
|
|
24
|
+
for (const candidate of [json, json?.blueprint, json?.response?.blueprint]) {
|
|
25
|
+
if (candidate && Array.isArray(candidate.flow)) return candidate;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Every literal credential under node, as a JSON path and the field it sits in. */
|
|
31
|
+
function literals(node, trail, found) {
|
|
32
|
+
if (Array.isArray(node)) {
|
|
33
|
+
node.forEach((child, index) => literals(child, `${trail}[${index}]`, found));
|
|
34
|
+
return found;
|
|
35
|
+
}
|
|
36
|
+
if (node === null || typeof node !== "object") return found;
|
|
37
|
+
const name = typeof node.name === "string" ? node.name : node.key;
|
|
38
|
+
const pairLeaks =
|
|
39
|
+
typeof name === "string" &&
|
|
40
|
+
typeof node.value === "string" &&
|
|
41
|
+
SECRET_NAME.test(name) &&
|
|
42
|
+
isLiteral(node.value);
|
|
43
|
+
if (pairLeaks) found.push({ trail, field: name });
|
|
44
|
+
for (const [key, child] of Object.entries(node)) {
|
|
45
|
+
// WHY: samples are a run's output (mail DKIM headers), while designer orphans are full modules.
|
|
46
|
+
if (key === "samples" || (pairLeaks && key === "value")) continue;
|
|
47
|
+
const at = `${trail}.${key}`;
|
|
48
|
+
if (typeof child === "string") {
|
|
49
|
+
if (SECRET_NAME.test(key) && isLiteral(child)) found.push({ trail: at, field: key });
|
|
50
|
+
for (const pattern of INLINE) {
|
|
51
|
+
const match = pattern.exec(child);
|
|
52
|
+
if (match && isLiteral(match[2])) found.push({ trail: at, field: match[1] });
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
literals(child, at, found);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return found;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function blueprintSecrets(tree) {
|
|
62
|
+
const found = [];
|
|
63
|
+
for (const file of tree.touchedMatching(/\.json$/)) {
|
|
64
|
+
const scenario = scenarioOf(tree.json(file));
|
|
65
|
+
if (!scenario) continue;
|
|
66
|
+
for (const { trail, field } of literals(scenario, "blueprint", [])) {
|
|
67
|
+
found.push({
|
|
68
|
+
file,
|
|
69
|
+
rule: "blueprint-secret",
|
|
70
|
+
message: `${trail} holds a literal ${field}. A committed blueprint keeps no credential: put a placeholder such as <${field.replace(/[^A-Za-z0-9]+/g, "_").toUpperCase()}> there, or map it from a Make connection or variable. The key was written down, so have its owner rotate it.`,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return found;
|
|
75
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/** A registry runner (npx, dlx, bunx) fetching a bare `heyramzi-*` name, which nobody owns on npm. */
|
|
2
|
+
|
|
3
|
+
const RUNNER = /(?<![\w-])(?:npx|pnpx|bunx|(?:pnpm|yarn)\s+dlx|npm\s+exec)(?![\w-])/g;
|
|
4
|
+
const BARE = /^heyramzi-[\w.-]+(@\S*)?$/;
|
|
5
|
+
const BINARY =
|
|
6
|
+
/\.(png|jpe?g|gif|webp|avif|heic|ico|icns|psd|pdf|zip|gz|tgz|mp3|mp4|m4a|mov|wav|webm|woff2?|ttf|otf|sqlite|db|wasm|bin|car)$/i;
|
|
7
|
+
const EDGE = /^[`'"([{,;]+|[`'")\]},;:.]+$/g;
|
|
8
|
+
|
|
9
|
+
/** The package a runner fetches: the `-p` value when there is one, else the command it runs. */
|
|
10
|
+
function fetched(words) {
|
|
11
|
+
const packages = [];
|
|
12
|
+
for (let index = 0; index < words.length; index += 1) {
|
|
13
|
+
const word = words[index].replace(EDGE, "");
|
|
14
|
+
if (word === "-p" || word === "--package") {
|
|
15
|
+
packages.push(words[index + 1]?.replace(EDGE, "") ?? "");
|
|
16
|
+
index += 1;
|
|
17
|
+
} else if (/^(-p|--package)=/.test(word)) {
|
|
18
|
+
packages.push(word.slice(word.indexOf("=") + 1));
|
|
19
|
+
} else if (word === "" || word === "--" || word.startsWith("-")) {
|
|
20
|
+
continue;
|
|
21
|
+
} else {
|
|
22
|
+
return packages.length ? packages : [word];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return packages;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function npxBareBins(tree) {
|
|
29
|
+
const found = [];
|
|
30
|
+
for (const file of tree.touched) {
|
|
31
|
+
if (BINARY.test(file)) continue;
|
|
32
|
+
const text = tree.text(file);
|
|
33
|
+
if (text.includes("\0")) continue;
|
|
34
|
+
for (const match of text.matchAll(RUNNER)) {
|
|
35
|
+
const after = text.slice(match.index + match[0].length, match.index + match[0].length + 240);
|
|
36
|
+
const name = fetched(after.trim().split(/\s+/).slice(0, 8)).find((word) => BARE.test(word));
|
|
37
|
+
if (!name) continue;
|
|
38
|
+
const line = text.slice(0, match.index).split("\n").length;
|
|
39
|
+
const bin = name.replace(/@.*$/, "");
|
|
40
|
+
found.push({
|
|
41
|
+
file,
|
|
42
|
+
rule: "npx-bare-bin",
|
|
43
|
+
message: `line ${line} has ${match[0]} fetch the bare npm name ${bin}. Nobody owns that name, so whoever registers it runs code on every machine that follows the line. The bin ships in @heyramzi/lint: write \`npx -y -p @heyramzi/lint ${bin}\`.`,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return found;
|
|
48
|
+
}
|
package/repo-rules.js
CHANGED
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* to live in Markdown. Pure here, git and process in `bin/heyramzi-repo-rules.js`.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { blueprintSecrets } from "#lint/repo-rules/blueprints.js";
|
|
6
7
|
import { untrackedImports } from "#lint/repo-rules/imports.js";
|
|
8
|
+
import { npxBareBins } from "#lint/repo-rules/npx.js";
|
|
7
9
|
import { composeImages, fossilNames } from "#lint/repo-rules/paths.js";
|
|
8
10
|
import {
|
|
9
11
|
heyramziLinks,
|
|
@@ -38,6 +40,8 @@ export const RULES = [
|
|
|
38
40
|
composeImages,
|
|
39
41
|
fossilNames,
|
|
40
42
|
untrackedImports,
|
|
43
|
+
blueprintSecrets,
|
|
44
|
+
npxBareBins,
|
|
41
45
|
];
|
|
42
46
|
|
|
43
47
|
/** Every violation in the files the tree says were touched. */
|