@lintsure/core 0.3.14 → 0.3.15
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/dist/src/index.d.ts +18 -1
- package/dist/src/index.js +160 -16
- package/dist/src/knowledge/cra.js +2 -2
- package/dist/src/knowledge/gdpr.js +3 -3
- package/dist/src/knowledge/more.js +2 -2
- package/dist/src/knowledge/owasp-top10.js +1 -1
- package/dist/src/rules/cra.d.ts +4 -0
- package/dist/src/rules/cra.js +72 -2
- package/dist/src/rules/index.d.ts +1 -0
- package/dist/src/rules/index.js +37 -10
- package/dist/src/rules/more.d.ts +25 -0
- package/dist/src/rules/more.js +266 -4
- package/dist/src/rules/owasp.d.ts +5 -1
- package/dist/src/rules/owasp.js +67 -26
- package/dist/src/rules/stack.js +2 -1
- package/dist/src/rules/standards.js +11 -6
- package/docs/README.md +1 -1
- package/docs/agents.md +1 -1
- package/docs/frameworks.md +9 -9
- package/docs/rules.md +144 -3
- package/package.json +42 -42
package/dist/src/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { toAssessmentHtml } from "./assessment.js";
|
|
|
13
13
|
export * from "./knowledge/index.js";
|
|
14
14
|
export { loadPacks, registerPack, type Pack } from "./packs.js";
|
|
15
15
|
export { checksFor } from "./plan.js";
|
|
16
|
-
export declare const RULES_VERSION = "0.3.
|
|
16
|
+
export declare const RULES_VERSION = "0.3.15";
|
|
17
17
|
/** Shown with every result, in every interface. Lintsure prepares; people decide. */
|
|
18
18
|
export declare const DISCLAIMER: string;
|
|
19
19
|
/** What a report must never be read as. Used in the report and by the MCP server. */
|
|
@@ -56,6 +56,20 @@ export declare const NON_SHIPPING: RegExp;
|
|
|
56
56
|
* when it comes before any app or route root in the path: examples/site/app/page.tsx is an example, while
|
|
57
57
|
* app/api/demo/route.ts and src/samples/handler.ts are live code. Pure. */
|
|
58
58
|
export declare function isNonShipping(file: string): boolean;
|
|
59
|
+
/** True when line i sits inside a branch taken only outside production. Reads indentation, up to 30 lines back. Pure. */
|
|
60
|
+
export declare function inDevBranch(lines: string[], i: number): boolean;
|
|
61
|
+
/** Names of functions in this file that wrap a masking call: `def _refusal(email): return pseudonym(email)`. A value logged
|
|
62
|
+
* through one is masked too (0.3.14 review). Pure.
|
|
63
|
+
* shortcut: reads the 12 lines after the definition, not the real function body; parse the body if that misleads. */
|
|
64
|
+
export declare function localMaskers(lines: string[]): string[];
|
|
65
|
+
/** The names a file imports, with the project file each comes from: JS/TS `import { a as b } from "./x"` and
|
|
66
|
+
* `const { a } = require("./x")`, Python `from pkg.mod import a as b`. Packages and unresolved paths are left out. Pure.
|
|
67
|
+
* shortcut: relative paths, "@/" as src/ or the root, and Python modules by path ending; tsconfig aliases are not read here. */
|
|
68
|
+
export declare function importedNames(file: string, text: string, files: Set<string>, byEnding?: (ending: string) => string | undefined): {
|
|
69
|
+
local: string;
|
|
70
|
+
name: string;
|
|
71
|
+
from: string;
|
|
72
|
+
}[];
|
|
59
73
|
/** The JSON object key that opens the block a line sits in, e.g. "peerDependencies". Pure. */
|
|
60
74
|
export declare function enclosingKey(lines: string[], i: number): string;
|
|
61
75
|
/** enclosingKey for every line in one pass (calling it per line was quadratic: minutes on a large JSON file). Pure. */
|
|
@@ -115,4 +129,7 @@ export declare function policyFingerprint(p: {
|
|
|
115
129
|
workspaceRules: boolean;
|
|
116
130
|
};
|
|
117
131
|
export declare function scan(root: string, frameworks?: FrameworkId[], opts?: ScanOptions): Promise<Report>;
|
|
132
|
+
export declare const isHygiene: (f: {
|
|
133
|
+
ruleId: string;
|
|
134
|
+
}) => boolean;
|
|
118
135
|
export declare function toMarkdown(r: Report): string;
|
package/dist/src/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createHash } from "node:crypto";
|
|
|
4
4
|
import { readdir, readFile, stat } from "node:fs/promises";
|
|
5
5
|
import { basename, extname, join, relative, sep } from "node:path";
|
|
6
6
|
import { outsideFor } from "./knowledge/index.js";
|
|
7
|
-
import { rules } from "./rules/index.js";
|
|
7
|
+
import { MASKED, rules } from "./rules/index.js";
|
|
8
8
|
import { proposalFor } from "./guidance.js";
|
|
9
9
|
import { applyReview, fingerprint, isOpen } from "./review.js";
|
|
10
10
|
export * from "./review.js";
|
|
@@ -22,7 +22,7 @@ export { loadPacks, registerPack } from "./packs.js";
|
|
|
22
22
|
export { checksFor } from "./plan.js";
|
|
23
23
|
import { configPacks, loadPacks, packFrameworks, packsLoaded } from "./packs.js";
|
|
24
24
|
import { buildGraph, declaredEntries, reachOf } from "./reach.js";
|
|
25
|
-
export const RULES_VERSION = "0.3.
|
|
25
|
+
export const RULES_VERSION = "0.3.15";
|
|
26
26
|
/** Shown with every result, in every interface. Lintsure prepares; people decide. */
|
|
27
27
|
export const DISCLAIMER = "Lintsure is a readiness tool, not an audit, a certification or legal advice. " +
|
|
28
28
|
"Its rules reflect our reading of the publicly available text of each framework, and they check code only. " +
|
|
@@ -147,8 +147,8 @@ export function extOf(abs) {
|
|
|
147
147
|
const name = basename(abs);
|
|
148
148
|
if (/^\.env(\.[\w.-]+)?$/.test(name))
|
|
149
149
|
return ".env";
|
|
150
|
-
if (/^Dockerfile\b
|
|
151
|
-
return ""; // Dockerfile.prod
|
|
150
|
+
if (/^(Dockerfile|Containerfile)\b|\.Dockerfile$/i.test(name))
|
|
151
|
+
return ""; // Dockerfile.prod, api.Dockerfile and Containerfile are Dockerfiles too
|
|
152
152
|
const e = extname(abs);
|
|
153
153
|
return e === ".mts" || e === ".cts" ? ".ts" : e;
|
|
154
154
|
}
|
|
@@ -185,6 +185,11 @@ const NS_FOLDER = /(^|\/)(tests?|__tests__|__mocks__|mocks?|spec|fixtures?|__fix
|
|
|
185
185
|
// Dev scripts at the top of a repo (scripts/test-*.mjs, build and seed helpers) and agent tooling (.agents/, .claude/)
|
|
186
186
|
// don't ship: they were the largest single source of false alarms in the 0.3.9 labelled sample (44 of 242).
|
|
187
187
|
const TEST_FILE = /(^|\/)__tests__\/|(^|\/)test[-_]?(utils?|helpers?|rig)\/|(^|\/)test-[^/]+\.[cm]?[jt]s$|[._-]tests?\/|\.(test|spec|stories)\.[cm]?[jt]sx?$|(^|\/)test_[^/]+\.py$|_test\.(py|go)$|(^|\/)(conftest\.py|pytest\.ini|tox\.ini)$/i;
|
|
188
|
+
// Files named for what they hold: seed.js, seed-users.ts, demo.ts, mock-data.ts, orders.mock.ts, user.fixture.ts.
|
|
189
|
+
const DEV_FILE = /(^|\/)(seeds?|demo|mocks?)([-_.][\w.-]*)?\.([cm]?[jt]sx?|py)$|\.(mock|fixtures?)\.[cm]?[jt]sx?$/i;
|
|
190
|
+
// Test and fixture folders. Agent-tooling rules read .claude/ and .agents/ on purpose, but a hostile SKILL.md kept as a
|
|
191
|
+
// test fixture is a test input, not an instruction anyone's agent loads.
|
|
192
|
+
const TEST_PATH = /(^|\/)(tests?|__tests__|fixtures?|__fixtures__|e2e|testdata|test-data)\//i;
|
|
188
193
|
/** True for code that doesn't ship: tests, fixtures, examples, docs, stories and seed data. A folder name only counts
|
|
189
194
|
* when it comes before any app or route root in the path: examples/site/app/page.tsx is an example, while
|
|
190
195
|
* app/api/demo/route.ts and src/samples/handler.ts are live code. Pure. */
|
|
@@ -192,8 +197,10 @@ export function isNonShipping(file) {
|
|
|
192
197
|
if (TEST_FILE.test(file))
|
|
193
198
|
return true;
|
|
194
199
|
// Shell scripts in scripts/ are often the installer people run (curl ... | sh): those still count.
|
|
195
|
-
if (/\.(sh|bash|zsh|ps1)$/i.test(file) && !/(^|\/)(tests?|__tests__|e2e|fixtures?|examples?|demos
|
|
200
|
+
if (/\.(sh|bash|zsh|ps1)$/i.test(file) && !/(^|\/)(tests?|__tests__|e2e|fixtures?|examples?|demos?|\.devcontainer)\//i.test(file))
|
|
196
201
|
return false;
|
|
202
|
+
// In a monorepo, apps/api/ or packages/app/ is a package that happens to share a route folder's name, not a route root.
|
|
203
|
+
file = file.replace(/(^|\/)(apps|packages|services)\/(app|api|pages|routes)\//g, "$1$2/_/");
|
|
197
204
|
const live = LIVE_ROOT.exec(file), ns = NS_FOLDER.exec(file);
|
|
198
205
|
if (!live || (ns && ns.index < live.index))
|
|
199
206
|
return NON_SHIPPING.test(file);
|
|
@@ -201,16 +208,98 @@ export function isNonShipping(file) {
|
|
|
201
208
|
if (/^(app|pages|api|routes|supabase\/functions)$/.test(live[2]))
|
|
202
209
|
return false;
|
|
203
210
|
// Under src/, lib/ or server/, test folders are still tests; example, demo, docs and sample folders are app code.
|
|
204
|
-
|
|
211
|
+
// Dev scripts kept inside the app folder (server/scripts/reset_admin_password.py) and files named for seed, demo
|
|
212
|
+
// or mock data don't ship either (0.3.14 review: 3 false alarms, no real finding in such a file).
|
|
213
|
+
const rest = file.slice(live.index);
|
|
214
|
+
return /(^|\/)(tests?|__tests__|__mocks__|mocks?|spec|fixtures?|__fixtures__|e2e|seeds?|seeders|factories|stories|storybook|scripts?)\//i.test(rest) || DEV_FILE.test(rest);
|
|
205
215
|
}
|
|
206
216
|
// Rules that also read test files. Not auth.hardcoded-password: test logins are fake by design (field test, 50 repos).
|
|
207
217
|
const SECRET_RULES = new Set(["secret.in-source"]); // not config.default-secret-key: a test secret is a test value (review P19)
|
|
208
218
|
// Rules that read agent tooling folders on purpose: an agent hook in .claude/ runs on real machines.
|
|
219
|
+
// Settings that sit in the branch that only runs outside production (`if IS_PRODUCTION: ... else:`, `if (!isProduction) {`)
|
|
220
|
+
// are dev settings (0.3.14 review: 2 of 2). Only for rules about a setting, where the branch decides what ships.
|
|
221
|
+
const DEV_BRANCH_RULES = new Set(["config.allowed-hosts-any", "cors.any-origin"]);
|
|
222
|
+
/** True when line i sits inside a branch taken only outside production. Reads indentation, up to 30 lines back. Pure. */
|
|
223
|
+
export function inDevBranch(lines, i) {
|
|
224
|
+
const indent = (l) => l.search(/\S/);
|
|
225
|
+
const opens = /^\s*(\}\s*else\s+)?(if|elif)\b/;
|
|
226
|
+
const negated = (l) => /!\s*[\w.]*prod|\bnot\s+[\w.]*prod|!==?\s*["']production["']/i.test(l);
|
|
227
|
+
let level = indent(lines[i]);
|
|
228
|
+
for (let k = i - 1; k >= Math.max(0, i - 30) && level > 0; k--) {
|
|
229
|
+
const at = indent(lines[k]);
|
|
230
|
+
if (at < 0 || at >= level)
|
|
231
|
+
continue;
|
|
232
|
+
level = at;
|
|
233
|
+
if (/^\s*(\}\s*)?else\s*[:{]?\s*$/.test(lines[k])) { // a plain else: its `if` is the nearest opener above at the same indent
|
|
234
|
+
const open = lines.slice(Math.max(0, k - 30), k).reverse().find((x) => indent(x) === at && opens.test(x));
|
|
235
|
+
if (open && /\b(is_?prod(uction)?|production)\b/i.test(open) && !negated(open))
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
else if (opens.test(lines[k]) && (negated(lines[k]) || /(?<!!\s*)(?<!\bnot\s)\b(is_?dev\w*|DEBUG)\b|===?\s*["']development["']/.test(lines[k])))
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
/** Names of functions in this file that wrap a masking call: `def _refusal(email): return pseudonym(email)`. A value logged
|
|
244
|
+
* through one is masked too (0.3.14 review). Pure.
|
|
245
|
+
* shortcut: reads the 12 lines after the definition, not the real function body; parse the body if that misleads. */
|
|
246
|
+
export function localMaskers(lines) {
|
|
247
|
+
return lines.flatMap((l, i) => {
|
|
248
|
+
const m = /^\s*(?:export\s+)?(?:async\s+)?(?:def|function)\s+(\w+)\s*\(|^\s*(?:export\s+)?const\s+(\w+)\s*=\s*(?:async\s*)?\(/.exec(l);
|
|
249
|
+
return m && lines.slice(i + 1, i + 13).some((x) => MASKED.test(x)) ? [m[1] ?? m[2]] : [];
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
/** The names a file imports, with the project file each comes from: JS/TS `import { a as b } from "./x"` and
|
|
253
|
+
* `const { a } = require("./x")`, Python `from pkg.mod import a as b`. Packages and unresolved paths are left out. Pure.
|
|
254
|
+
* shortcut: relative paths, "@/" as src/ or the root, and Python modules by path ending; tsconfig aliases are not read here. */
|
|
255
|
+
export function importedNames(file, text, files, byEnding) {
|
|
256
|
+
const dir = file.includes("/") ? file.slice(0, file.lastIndexOf("/")) : "";
|
|
257
|
+
const norm = (p) => { const out = []; for (const s of p.split("/")) {
|
|
258
|
+
if (s === "..")
|
|
259
|
+
out.pop();
|
|
260
|
+
else if (s && s !== ".")
|
|
261
|
+
out.push(s);
|
|
262
|
+
} return out.join("/"); };
|
|
263
|
+
const names = (list, sep) => list.split(",").map((x) => x.trim().replace(/^type\s+/, "")).filter(Boolean).map((x) => { const [name, local] = x.split(sep).map((y) => y.trim()); return { name, local: local ?? name }; });
|
|
264
|
+
const out = [];
|
|
265
|
+
if (/\.py$/.test(file)) {
|
|
266
|
+
for (const m of text.matchAll(/^[ \t]*from[ \t]+(\.*)([\w.]*)[ \t]+import[ \t]+(?:\(([^)]*)\)|([^#\n]+))/gm)) {
|
|
267
|
+
const mod = m[2].split(".").filter(Boolean).join("/");
|
|
268
|
+
const base = m[1] ? norm(`${dir}/${"../".repeat(m[1].length - 1)}${mod}`) : mod;
|
|
269
|
+
if (!base)
|
|
270
|
+
continue;
|
|
271
|
+
const ends = [`${base}.py`, `${base}/__init__.py`];
|
|
272
|
+
const find = byEnding ?? ((e) => { for (const f of files)
|
|
273
|
+
if (f === e || f.endsWith("/" + e))
|
|
274
|
+
return f; return undefined; });
|
|
275
|
+
const from = m[1] ? ends.find((e) => files.has(e)) : ends.map(find).find(Boolean);
|
|
276
|
+
if (from)
|
|
277
|
+
for (const n of names(m[3] ?? m[4], /\s+as\s+/))
|
|
278
|
+
out.push({ ...n, from });
|
|
279
|
+
}
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
const resolve = (spec) => {
|
|
283
|
+
const bases = spec.startsWith(".") ? [norm(`${dir}/${spec}`)] : spec.startsWith("@/") ? [`src/${spec.slice(2)}`, spec.slice(2)] : [];
|
|
284
|
+
for (const b of bases)
|
|
285
|
+
for (const c of [b, b.replace(/\.js$/, ".ts"), ...[".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"].flatMap((e) => [b + e, `${b}/index${e}`])])
|
|
286
|
+
if (files.has(c))
|
|
287
|
+
return c;
|
|
288
|
+
return null;
|
|
289
|
+
};
|
|
290
|
+
for (const m of text.matchAll(/\bimport\s*(?:type\s*)?\{([^}]*)\}\s*from\s*["']([^"'\n]+)["']|\b(?:const|let|var)\s*\{([^}]*)\}\s*=\s*require\(\s*["']([^"'\n]+)["']\s*\)/g)) {
|
|
291
|
+
const from = resolve(m[2] ?? m[4]);
|
|
292
|
+
if (from)
|
|
293
|
+
for (const n of names(m[1] ?? m[3], m[1] != null ? /\s+as\s+/ : /\s*:\s*/))
|
|
294
|
+
out.push({ ...n, from });
|
|
295
|
+
}
|
|
296
|
+
return out;
|
|
297
|
+
}
|
|
209
298
|
const TOOLING_RULES = new Set(["agent.config-runs-remote-code", "agent.instructions-unsafe", "agent.permissions-allow-all"]);
|
|
210
299
|
// Lines a person already reviewed. lintsure-ignore and the secret allowlist pragma count only in a comment and apply
|
|
211
300
|
// to every rule. Other linters' markers (noqa, nosec, NOSONAR) don't hide secrets: `# noqa: E501` is about line length.
|
|
212
301
|
const REVIEWED = /(#|\/\/|\/\*|--)\s*(lintsure-ignore|pragma:\s*allowlist secret)\b/;
|
|
213
|
-
const OTHER_LINTER = /#\s*(noqa|nosec)\b|\/\/\s*NOSONAR\b
|
|
302
|
+
const OTHER_LINTER = /#\s*(noqa|nosec|nosemgrep|NOSONAR)\b|\/\/\s*(NOSONAR|nosemgrep)\b/i;
|
|
214
303
|
// Also hand-typed fake keys: alphabet or number runs, words where random text should be, a whole key block on one line.
|
|
215
304
|
const PLACEHOLDER = /test|fake|dummy|example|sample|placeholder|sanitized|mock|xxx|changeme|localhost|["'](password|pass|secret|elastic|admin)["']|abcdef|123456|\b(xox[baprs]|gh[pousr])[-_][a-z]+(-[a-z]+)*\b|PRIVATE KEY-----.*-----END/i;
|
|
216
305
|
/** The JSON object key that opens the block a line sits in, e.g. "peerDependencies". Pure. */
|
|
@@ -579,6 +668,40 @@ export async function scan(root, frameworks = ALL_FRAMEWORKS, opts = {}) {
|
|
|
579
668
|
});
|
|
580
669
|
for (let i = 0; i < needed.length; i += 32)
|
|
581
670
|
await Promise.all(needed.slice(i, i + 32).map(textOf));
|
|
671
|
+
// One hop across files for masking helpers: a helper imported from another project file masks if it does so where it
|
|
672
|
+
// is defined (0.3.14 review: logs through an imported pseudonym helper were false alarms).
|
|
673
|
+
const absOf = new Map(paths.map((p, k) => [p, all[k]])), pathSet = new Set(paths);
|
|
674
|
+
const maskersIn = new Map();
|
|
675
|
+
// Every path ending of every Python file, built on first use, so `from a.b import c` is one lookup, not a search.
|
|
676
|
+
let endings;
|
|
677
|
+
const byEnding = (e) => {
|
|
678
|
+
if (!endings) {
|
|
679
|
+
endings = new Map();
|
|
680
|
+
for (const p of paths)
|
|
681
|
+
if (p.endsWith(".py")) {
|
|
682
|
+
const s = p.split("/");
|
|
683
|
+
for (let i = 0; i < s.length; i++) {
|
|
684
|
+
const k = s.slice(i).join("/");
|
|
685
|
+
if (!endings.has(k))
|
|
686
|
+
endings.set(k, p);
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
return endings.get(e);
|
|
691
|
+
};
|
|
692
|
+
const importedMaskers = async (file, text) => {
|
|
693
|
+
const got = [];
|
|
694
|
+
for (const im of importedNames(file, text, pathSet, byEnding)) {
|
|
695
|
+
let m = maskersIn.get(im.from);
|
|
696
|
+
if (!m) {
|
|
697
|
+
m = textOf(absOf.get(im.from)).then((t) => (t ? localMaskers(t.split(/\r?\n/)) : []));
|
|
698
|
+
maskersIn.set(im.from, m);
|
|
699
|
+
}
|
|
700
|
+
if ((await m).includes(im.name))
|
|
701
|
+
got.push(im.local);
|
|
702
|
+
}
|
|
703
|
+
return got;
|
|
704
|
+
};
|
|
582
705
|
// Say what was not read, so "no findings" is never read as "checked everything".
|
|
583
706
|
let filesSkipped = 0;
|
|
584
707
|
for (const abs of needed)
|
|
@@ -641,6 +764,9 @@ export async function scan(root, frameworks = ALL_FRAMEWORKS, opts = {}) {
|
|
|
641
764
|
nonShipping++;
|
|
642
765
|
const comment = commentLines(lines, ext), example = exampleLines(lines, ext);
|
|
643
766
|
let tainted;
|
|
767
|
+
let maskers;
|
|
768
|
+
const fromOtherFiles = relevant.some((r) => r.id === "pii.logged") && /e-?mail|phone|passw|\bssn\b|birth|\bdob\b|card|iban|passport/i.test(whole) && /\b(import|require)\b/.test(whole) ? await importedMaskers(file, whole) : [];
|
|
769
|
+
const viaMasker = (text) => (maskers ??= [...localMaskers(lines), ...fromOtherFiles]).some((n) => text.includes(n + "("));
|
|
644
770
|
// Statements are worked out once per file, on lines with comments blanked.
|
|
645
771
|
const stmts = JOINABLE.has(ext) ? statements(lines.map((l, i) => (comment[i] ? "" : l)), ext === ".py") : [];
|
|
646
772
|
const multi = stmts.filter((s) => s.end > s.start);
|
|
@@ -654,7 +780,7 @@ export async function scan(root, frameworks = ALL_FRAMEWORKS, opts = {}) {
|
|
|
654
780
|
if (r.id === "ai.hides-being-ai" && (ext === ".md" || ext === ".mdx") && !PROMPT_DOC.test(file))
|
|
655
781
|
continue;
|
|
656
782
|
const secret = SECRET_RULES.has(r.id);
|
|
657
|
-
if (inTests && !secret && !TOOLING_RULES.has(r.id))
|
|
783
|
+
if (inTests && !secret && !(TOOLING_RULES.has(r.id) && !TEST_PATH.test(file) && !TEST_FILE.test(file)))
|
|
658
784
|
continue;
|
|
659
785
|
// Count only what actually ran: a file skipped as a test is not a check point (review P1).
|
|
660
786
|
ran++;
|
|
@@ -686,6 +812,10 @@ export async function scan(root, frameworks = ALL_FRAMEWORKS, opts = {}) {
|
|
|
686
812
|
return;
|
|
687
813
|
if (r.unlessInKey && r.unlessInKey.test(enclosingKey(lines, i)))
|
|
688
814
|
return;
|
|
815
|
+
if (DEV_BRANCH_RULES.has(r.id) && inDevBranch(lines, i))
|
|
816
|
+
return;
|
|
817
|
+
if (r.id === "pii.logged" && viaMasker(probe))
|
|
818
|
+
return;
|
|
689
819
|
if (inTests && secret && PLACEHOLDER.test(text))
|
|
690
820
|
return; // password="test_password", token="xoxb-test-..."
|
|
691
821
|
if (inTests && /PRIVATE KEY/.test(text))
|
|
@@ -710,6 +840,8 @@ export async function scan(root, frameworks = ALL_FRAMEWORKS, opts = {}) {
|
|
|
710
840
|
if (already)
|
|
711
841
|
continue;
|
|
712
842
|
const hit = r.test(s.text);
|
|
843
|
+
if (hit && r.id === "pii.logged" && viaMasker(s.text))
|
|
844
|
+
continue;
|
|
713
845
|
if (!hit || (r.unlessNear && lines.slice(Math.max(0, s.start - 8), s.end + 4).some((l) => r.unlessNear.test(l))))
|
|
714
846
|
continue;
|
|
715
847
|
if (r.unlessInKey && r.unlessInKey.test(enclosingKey(lines, s.start)))
|
|
@@ -719,9 +851,11 @@ export async function scan(root, frameworks = ALL_FRAMEWORKS, opts = {}) {
|
|
|
719
851
|
add(r, s.start + 1, hit === "partial" || (inTests && !TOOLING_RULES.has(r.id)) ? "partial" : r.status);
|
|
720
852
|
}
|
|
721
853
|
// File rules see comment lines as blank, so "<img> in a comment" or a commented-out call doesn't count (field test).
|
|
854
|
+
// A Python MCP tool's description is its docstring, so this rule reads docstrings too (it drops # and // lines itself).
|
|
722
855
|
if (r.fileTest)
|
|
723
|
-
for (const n of r.fileTest(skip ? lines.map((l, i) => (skip[i] ? "" : l)) : lines, shared.get(r.id), sharedFiles.get(r.id)))
|
|
724
|
-
typeof n === "number" ?
|
|
856
|
+
for (const n of r.fileTest(skip && r.id !== "mcp.tool-description-poisoned" ? lines.map((l, i) => (skip[i] ? "" : l)) : lines, shared.get(r.id), sharedFiles.get(r.id)))
|
|
857
|
+
if (!(DEV_BRANCH_RULES.has(r.id) && inDevBranch(lines, (typeof n === "number" ? n : n.line) - 1)))
|
|
858
|
+
typeof n === "number" ? add(r, n) : add(r, n.line, n.status);
|
|
725
859
|
}
|
|
726
860
|
if (ran)
|
|
727
861
|
filesChecked++;
|
|
@@ -846,22 +980,32 @@ function recordLines(r) {
|
|
|
846
980
|
...c.byControl.map((b) => `| ${b.framework} | ${b.control} ${b.title} | ${b.rules.join(", ")} | ${b.checkPoints} | ${RESULT[b.result]} | ${b.findingIds.join(", ") || "-"} |`), "",
|
|
847
981
|
];
|
|
848
982
|
}
|
|
983
|
+
// Housekeeping for the repo, not a flaw in the code. These four were 74% of what the 0.3.14 field test showed, so every
|
|
984
|
+
// output lists them after the findings in the code. Presentation only: the report data, SARIF and exit code don't change.
|
|
985
|
+
// The two Dockerfile hardening basics joined the group after their first field scan: 138 findings in 304 projects, true
|
|
986
|
+
// but routine, and they would bury findings in the code.
|
|
987
|
+
const HYGIENE_RULES = new Set(["ci.action-unpinned", "repo.no-sbom", "repo.no-security-policy", "repo.no-dependency-updates", "docker.runs-as-root", "docker.image-unpinned"]);
|
|
988
|
+
export const isHygiene = (f) => HYGIENE_RULES.has(f.ruleId);
|
|
849
989
|
export function toMarkdown(r) {
|
|
990
|
+
const hygiene = r.findings.filter(isHygiene);
|
|
850
991
|
const lines = [
|
|
851
992
|
"# Lintsure report", "",
|
|
852
993
|
`Frameworks: ${r.frameworks.join(", ")} · Rules v${r.rulesVersion}${r.policy ? ` · Policy #${r.policy.fingerprint} (${r.policy.rulesActive} rules active${r.policy.repoRules ? " + .lintsure/rules.yml" : ""}${r.policy.workspaceRules ? " + workspace rules" : ""})` : ""}`, "",
|
|
853
994
|
`> ${DISCLAIMER}`, "",
|
|
854
995
|
...recordLines(r),
|
|
855
|
-
`## Findings (${r.findings.length})`, "",
|
|
996
|
+
`## Findings (${r.findings.length - hygiene.length})`, "",
|
|
856
997
|
];
|
|
857
998
|
if (r.baseline)
|
|
858
999
|
lines.splice(lines.length - 2, 0, `Since the baseline of ${r.baseline.created}: ${r.baseline.newCount} new, ${r.baseline.fixed.length} fixed, ${r.baseline.unchangedCount} unchanged.`, "");
|
|
859
|
-
if (
|
|
860
|
-
lines.push("No issues found by the current rules.", "");
|
|
1000
|
+
if (r.findings.length === hygiene.length)
|
|
1001
|
+
lines.push(hygiene.length ? "No findings in the code from the current rules. Repo hygiene items follow." : "No issues found by the current rules.", "");
|
|
861
1002
|
// Fix first: Gaps before Partials, then by severity; file order within each group.
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
1003
|
+
// Within the same status and risk level, code that no route, handler or entry point reaches comes after code that is
|
|
1004
|
+
// reached. A tie-break only: reachability misses dynamic imports, so it never hides or demotes a finding across levels.
|
|
1005
|
+
const rank = (f) => (isHygiene(f) ? 6 : 0) + (f.status === "gap" ? 0 : 3) + { high: 0, medium: 1, low: 2 }[f.severity] + (f.reach?.status === "unreachable" ? 0.5 : 0);
|
|
1006
|
+
const sorted = [...r.findings].sort((a, b) => rank(a) - rank(b));
|
|
1007
|
+
for (const f of sorted)
|
|
1008
|
+
lines.push(...(f === sorted[r.findings.length - hygiene.length] ? [`## Repo hygiene (${hygiene.length})`, "", "Housekeeping for the repo, not flaws in the code. Findings in the code come first.", ""] : []), `### ${f.id} · ${f.status === "gap" ? "Finding" : "Observation"} (${LABEL[f.status]}) · \`${f.file}:${f.line}\`${f.change === "new" ? " · New since baseline" : ""}`, `**${f.title}** · Risk level: ${f.severity}`, "", ...(f.accepted ? [acceptedLine(f.accepted), ""] : []), `- Rules: ${ctl(f.controls)}`, `- Auditor note: ${f.note}`, ...(f.unseen ? [`- What Lintsure couldn't see: ${f.unseen}`] : []), ...(rules.find((x) => x.id === f.ruleId)?.seenIn ?? []).map((s) => `- Seen in a real incident: ${s.title} (${s.url})`), ...(f.reach ? [`- Reached from: ${f.reach.status === "entry" ? "this file is an entry point (route, handler or function)" : f.reach.status === "reachable" ? f.reach.via.join(" → ") : f.reach.status === "unknown" ? "unknown (an import Lintsure couldn't resolve may lead here)" : "not reached from any entry point Lintsure recognises (it may be loaded some other way, or be unused)"}`] : []), "", `**${PROPOSAL_HEADING}**`, "", `- Where: \`${f.proposal.where}\``, `- What: ${f.proposal.what}`, `- Why: ${f.proposal.why}`, `- Benefit: ${f.proposal.benefit}`, "", ...(f.patch ? [`Exact change (still needs your approval), line ${f.patch.line}:`, "", "```diff",
|
|
865
1009
|
...(f.patch.old != null ? [`- ${f.patch.old}`] : []), ...f.patch.text.replace(/\n$/, "").split("\n").map((t) => `+ ${t}`), "```", ""] : []));
|
|
866
1010
|
if (r.baseline?.fixed.length)
|
|
867
1011
|
lines.push(`## Fixed since baseline (${r.baseline.fixed.length})`, "", ...r.baseline.fixed.map((x) => `- ${x.ruleId} in \`${x.file}\``), "");
|
|
@@ -48,7 +48,7 @@ export const cra = {
|
|
|
48
48
|
plain: "Nothing ships with a vulnerability that's already public and exploitable, including in dependencies. This needs advisory data, which Lintsure doesn't download, so use a dependency scanner alongside it.",
|
|
49
49
|
evidence: "Dependency scanner results at release and how alerts are handled." },
|
|
50
50
|
{ ref: "Annex I Part II (1)", title: "Components identified, including an SBOM", inCode: "partly",
|
|
51
|
-
rules: ["repo.no-sbom", "repo.binary-committed", "deps.unpinned-version", "deps.install-script"],
|
|
51
|
+
rules: ["repo.no-sbom", "repo.binary-committed", "deps.unpinned-version", "deps.install-script", "deps.unsafe-source"],
|
|
52
52
|
plain: "You know what's in your product: pinned dependencies, no unexplained compiled files, and a machine-readable software bill of materials (SBOM) covering at least the top-level components.",
|
|
53
53
|
evidence: "An SBOM per release in CycloneDX or SPDX format." },
|
|
54
54
|
{ ref: "Annex I Part II (5)", title: "Coordinated vulnerability disclosure policy", inCode: "partly",
|
|
@@ -56,7 +56,7 @@ export const cra = {
|
|
|
56
56
|
plain: "A published way for anyone to report a vulnerability to you, and a process for handling reports.",
|
|
57
57
|
evidence: "SECURITY.md or a security page, and records of reports received and handled." },
|
|
58
58
|
{ ref: "Annex I Part II (7)", title: "Updates distributed securely", inCode: "partly",
|
|
59
|
-
rules: ["update.unverified-download", "ci.action-unpinned", "ci.prt-checkout-head", "ci.write-all-permissions", "ci.script-injection"],
|
|
59
|
+
rules: ["update.unverified-download", "ci.action-unpinned", "ci.prt-checkout-head", "ci.write-all-permissions", "ci.script-injection", "ci.scan-cannot-fail"],
|
|
60
60
|
plain: "Builds and updates can't be swapped or tampered with: pinned CI steps, workflow tokens limited to what they need, untrusted pull requests and issue text kept away from secrets and commands, and nothing run straight from a download without a check.",
|
|
61
61
|
evidence: "Release signing, CI configuration and how users receive updates." },
|
|
62
62
|
{ ref: "Annex I Part II (2)", title: "Vulnerabilities fixed without delay", inCode: "partly",
|
|
@@ -25,10 +25,10 @@ export const gdpr = {
|
|
|
25
25
|
{ ref: "Art. 6", title: "A lawful reason", inCode: "no",
|
|
26
26
|
plain: "Every use of personal data needs one of six legal bases, such as consent, a contract, or legitimate interests weighed against people's rights.",
|
|
27
27
|
evidence: "The legal basis recorded for each processing purpose." },
|
|
28
|
-
{ ref: "Art. 7", title: "Consent done right", inCode: "partly",
|
|
28
|
+
{ ref: "Art. 7", title: "Consent done right", inCode: "partly", rules: ["privacy.consent-preticked"],
|
|
29
29
|
plain: "If you rely on consent, it must be freely given, specific, informed and as easy to withdraw as to give. No pre-ticked boxes.",
|
|
30
30
|
evidence: "Consent records and the wording users saw." },
|
|
31
|
-
{ ref: "Art. 9", title: "Sensitive data", inCode: "partly", rules: ["ai.emotion-or-biometric"],
|
|
31
|
+
{ ref: "Art. 9", title: "Sensitive data", inCode: "partly", rules: ["ai.emotion-or-biometric", "privacy.special-category-field"],
|
|
32
32
|
plain: "Health, biometric, ethnic, religious, political, sexual and union data is off-limits unless a specific exception applies.",
|
|
33
33
|
evidence: "The exception you rely on." },
|
|
34
34
|
{ ref: "Art. 12–15", title: "Transparency and access", inCode: "no",
|
|
@@ -50,7 +50,7 @@ export const gdpr = {
|
|
|
50
50
|
plain: "Keep a list of what personal data you process, why, with whom you share it and how long you keep it.",
|
|
51
51
|
evidence: "The register of processing activities." },
|
|
52
52
|
{ ref: "Art. 32", title: "Security of processing", inCode: "yes",
|
|
53
|
-
rules: ["pii.logged", "secret.in-source", "transport.plain-http", "transport.tls-verify-off", "crypto.weak-password-hash", "sql.string-built", "pii.in-url", "supabase.rls-disabled", "supabase.policy-allows-all", "supabase.service-key-in-client", "supabase.function-no-auth", "secret.public-env", "mobile.token-in-plain-storage", "mobile.cleartext-traffic", "mobile.backup-allowed"],
|
|
53
|
+
rules: ["crypto.static-iv", "crypto.weak-parameters", "mobile.debuggable-build", "payment.card-code-stored", "pii.logged", "secret.in-source", "transport.plain-http", "transport.tls-verify-off", "crypto.weak-password-hash", "sql.string-built", "pii.in-url", "supabase.rls-disabled", "supabase.policy-allows-all", "supabase.service-key-in-client", "supabase.function-no-auth", "secret.public-env", "mobile.token-in-plain-storage", "mobile.cleartext-traffic", "mobile.backup-allowed"],
|
|
54
54
|
plain: "Protect personal data with security that fits the risk: encryption, access control, testing and the ability to recover.",
|
|
55
55
|
evidence: "Security measures and when they were last tested." },
|
|
56
56
|
{ ref: "Art. 33–34", title: "Breach notification", inCode: "no",
|
|
@@ -10,7 +10,7 @@ export const owaspLlm = {
|
|
|
10
10
|
return null;
|
|
11
11
|
},
|
|
12
12
|
obligations: [
|
|
13
|
-
{ ref: "LLM01:2026", title: "Prompt Injection", inCode: "partly", rules: ["llm.user-input-in-system-prompt", "agent.instructions-unsafe", "llm.client-controls-system"],
|
|
13
|
+
{ ref: "LLM01:2026", title: "Prompt Injection", inCode: "partly", rules: ["llm.user-input-in-system-prompt", "agent.instructions-unsafe", "llm.client-controls-system", "mcp.tool-description-poisoned"],
|
|
14
14
|
plain: "User text, web pages or files can carry instructions that change what the model does. Keep instructions and user content apart, and limit what the model can do.",
|
|
15
15
|
evidence: "How prompts are built, and tests with hostile input." },
|
|
16
16
|
{ ref: "LLM02:2026", title: "Sensitive Information Disclosure", inCode: "partly", rules: ["secret.in-source", "secret.public-env", "pii.logged", "log.secret"],
|
|
@@ -19,7 +19,7 @@ export const owaspLlm = {
|
|
|
19
19
|
{ ref: "LLM03:2026", title: "Excessive Agency", inCode: "partly", rules: ["agent.permissions-allow-all", "mcp.tool-runs-shell", "mcp.tool-uses-secret"],
|
|
20
20
|
plain: "Tools and permissions given to an agent should be the minimum it needs, with a person approving anything risky.",
|
|
21
21
|
evidence: "A list of the tools each agent can call and which need approval." },
|
|
22
|
-
{ ref: "LLM04:2026", title: "Supply Chain", inCode: "partly", rules: ["deps.unpinned-version", "deps.install-script", "agent.config-runs-remote-code", "ml.unsafe-model-load"],
|
|
22
|
+
{ ref: "LLM04:2026", title: "Supply Chain", inCode: "partly", rules: ["deps.unpinned-version", "deps.install-script", "agent.config-runs-remote-code", "ml.unsafe-model-load", "mcp.config-unsafe-server"],
|
|
23
23
|
plain: "Models, datasets, plugins and packages come from others. Pin and check them like any dependency.",
|
|
24
24
|
evidence: "Where each model and dataset comes from, and its licence." },
|
|
25
25
|
{ ref: "LLM05:2026", title: "Data and Model Poisoning", inCode: "no",
|
|
@@ -23,7 +23,7 @@ export const owaspTop10 = {
|
|
|
23
23
|
plain: "Whether each endpoint checks that the record belongs to the person asking (often called IDOR). A line-by-line code check can't tell; it needs design review and testing with two accounts.",
|
|
24
24
|
evidence: "Access control tests per role, or a penetration test report." },
|
|
25
25
|
{ ref: "A02:2025", title: "Security Misconfiguration", inCode: "partly",
|
|
26
|
-
rules: ["config.debug-on", "agent.permissions-allow-all", "config.allowed-hosts-any", "config.default-secret-key", "xml.external-entities", "cors.any-origin", "session.cookie-insecure", "error.stack-to-client", "build.sourcemaps-public", "release.env-not-ignored", "k8s.privileged", "docker.socket-mounted", "graphql.introspection"],
|
|
26
|
+
rules: ["cloud.database-public", "cloud.network-open", "cloud.iam-allow-all", "cloud.function-url-no-auth", "docker.runs-as-root", "docker.image-unpinned", "docker.secret-in-build", "config.debug-on", "agent.permissions-allow-all", "config.allowed-hosts-any", "config.default-secret-key", "xml.external-entities", "cors.any-origin", "session.cookie-insecure", "error.stack-to-client", "build.sourcemaps-public", "release.env-not-ignored", "k8s.privileged", "docker.socket-mounted", "graphql.introspection"],
|
|
27
27
|
plain: "Safe settings by default: debug off, real host names, strong secret keys, cookies marked secure, XML parsers that don't load outside files, and errors that don't reveal internals.",
|
|
28
28
|
evidence: "Production configuration and a hardening checklist." },
|
|
29
29
|
{ ref: "A02:2025 (deployed settings)", title: "Server, cloud and header configuration in production", inCode: "no",
|
package/dist/src/rules/cra.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { Control, Rule } from "../types.js";
|
|
2
2
|
/** CRA controls for rules that already exist. Merged by id in rules/index.ts. */
|
|
3
3
|
export declare const craForExisting: Record<string, Control[]>;
|
|
4
|
+
/** CI lines where a security scan can't fail the build: `|| true`, a soft-fail flag, or continue-on-error on the scan's step. Pure. */
|
|
5
|
+
export declare function scanCannotFail(lines: string[]): number[];
|
|
6
|
+
/** A package source that can be swapped under you. Gap for plain HTTP or TLS checks off; Partial for a second index. Pure. */
|
|
7
|
+
export declare function unsafeSource(l: string): boolean | "partial";
|
|
4
8
|
export declare const craRules: Rule[];
|
|
5
9
|
/** Lines in a GitHub Actions `run:` step that paste text an outsider controls. Pure. */
|
|
6
10
|
export declare function untrustedInRun(lines: string[]): number[];
|
package/dist/src/rules/cra.js
CHANGED
|
@@ -25,7 +25,57 @@ const UNTRUSTED = /\$\{\{\s*github\.(head_ref|event\.(issue|pull_request|comment
|
|
|
25
25
|
const BINARY = /\.(exe|dll|so|dylib|jar|class|pyc|o|a|bin|msi|apk)$/i;
|
|
26
26
|
const UPDATER = /^\.github\/dependabot\.ya?ml$|(^|\/)(renovate\.json5?|\.renovaterc(\.json)?)$|^\.github\/renovate\.json5?$/;
|
|
27
27
|
const FIXES = P2("2", "Vulnerabilities fixed without delay");
|
|
28
|
+
// Security scanners people wire into CI. A scan whose failure is thrown away gates nothing.
|
|
29
|
+
// A scanner's name inside a path (/opt/hostedtoolcache/CodeQL) is not a scan.
|
|
30
|
+
const SCANNER = /(?<![\/.\w-])(trivy|semgrep|gitleaks|trufflehog|snyk|grype|checkov|tfsec|bandit|osv-scanner|pip-audit|codeql|dependency-check|zap-baseline|(npm|yarn|pnpm)\s+audit|safety\s+check)\b/i;
|
|
31
|
+
const CI_FILES = /(^|\/)(\.github\/workflows\/|\.gitlab-ci|\.circleci\/|azure-pipelines|bitbucket-pipelines|\.buildkite\/)/;
|
|
32
|
+
/** CI lines where a security scan can't fail the build: `|| true`, a soft-fail flag, or continue-on-error on the scan's step. Pure. */
|
|
33
|
+
export function scanCannotFail(lines) {
|
|
34
|
+
return lines.flatMap((l, i) => {
|
|
35
|
+
if (/^\s*#/.test(l))
|
|
36
|
+
return [];
|
|
37
|
+
// Output written to a file is a report collected for a later step, not a result thrown away (review: 4 of 4).
|
|
38
|
+
if (SCANNER.test(l) && /\|\|\s*(true\b|exit\s+0\b|:\s*$|echo\b)|--exit-code[= ]0\b|--soft-fail\b|--no-fail\b/.test(l))
|
|
39
|
+
return /\s>\s*\S/.test(l.replace(/[12]?>\s*(&1|\/dev\/null)/g, "")) ? [] : [i + 1];
|
|
40
|
+
// continue-on-error belongs to a step: look a few lines either side, stopping at the next step.
|
|
41
|
+
if (!/^\s*(continue-on-error|allow_failure)\s*:\s*true\b/.test(l))
|
|
42
|
+
return [];
|
|
43
|
+
const from = lines.slice(Math.max(0, i - 6), i).reverse(), to = lines.slice(i + 1, i + 7);
|
|
44
|
+
const cut = (xs) => { const k = xs.findIndex((x) => /^\s*-\s+(name|uses|run)\s*:/.test(x)); return k < 0 ? xs : xs.slice(0, k + 1); };
|
|
45
|
+
const before = cut(from), after = to.slice(0, Math.max(0, to.findIndex((x) => /^\s*-\s+(name|uses|run)\s*:/.test(x)) < 0 ? to.length : to.findIndex((x) => /^\s*-\s+(name|uses|run)\s*:/.test(x))));
|
|
46
|
+
// In a `uses:` line the scanner's name is part of the action's path (aquasecurity/trivy-action).
|
|
47
|
+
// Uploading a report, or a step named for installing the tool, is not the scan.
|
|
48
|
+
if ([...before, ...after].some((x) => /upload-sarif|^\s*-?\s*name\s*:.*\binstall/i.test(x)))
|
|
49
|
+
return [];
|
|
50
|
+
return [...before, ...after].some((x) => SCANNER.test(x) || /\buses:.*(trivy|semgrep|gitleaks|trufflehog|snyk|codeql|checkov|grype)/i.test(x)) ? [i + 1] : [];
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// Public indexes people add on purpose and that hold their own package names (GPU builds of PyTorch and friends).
|
|
54
|
+
const KNOWN_INDEX = /download\.pytorch\.org|pypi\.org|pypi\.nvidia\.com|test\.pypi\.org/;
|
|
55
|
+
/** A package source that can be swapped under you. Gap for plain HTTP or TLS checks off; Partial for a second index. Pure. */
|
|
56
|
+
export function unsafeSource(l) {
|
|
57
|
+
if (/^\s*(#|\/\/)/.test(l))
|
|
58
|
+
return false;
|
|
59
|
+
if (/(^|\s)(--index-url|-i|--extra-index-url)[= ]\s*http:\/\/(?!localhost|127\.0\.0\.1)|^\s*(@[\w-]+:)?registry\s*=\s*http:\/\/(?!localhost|127\.0\.0\.1)|^\s*(extra-)?index-url\s*=\s*http:\/\/(?!localhost|127\.0\.0\.1)/.test(l))
|
|
60
|
+
return true;
|
|
61
|
+
if (/^\s*strict-ssl\s*=\s*false\b|\bnpm\s+config\s+set\s+strict-ssl\s+false\b/.test(l))
|
|
62
|
+
return true;
|
|
63
|
+
if (/(^|\s)--trusted-host[= ]\s*(?!localhost|127\.0\.0\.1)\S|^\s*trusted-host\s*=\s*(?!localhost|127\.0\.0\.1)\S/.test(l))
|
|
64
|
+
return "partial";
|
|
65
|
+
// pip takes the highest version from any index, so a public package with an internal name wins (dependency confusion).
|
|
66
|
+
return /(^|\s)--extra-index-url[= ]\s*\S|^\s*extra-index-url\s*=\s*\S/.test(l) && !KNOWN_INDEX.test(l) ? "partial" : false;
|
|
67
|
+
}
|
|
28
68
|
export const craRules = [
|
|
69
|
+
{ id: "ci.scan-cannot-fail", title: "Security scan in CI that can never fail the build", status: "partial", severity: "low", controls: [UPDATES, A03],
|
|
70
|
+
fix: "Let the scan fail the job. If it is too noisy, limit it to high severity or to new findings instead of ignoring its result.",
|
|
71
|
+
note: "With `|| true`, a soft-fail flag or continue-on-error, the scan runs and reports but nothing stops a build that has findings, so it gives a sense of safety it doesn't deliver. Marked Partial: some teams read the report by hand on purpose.",
|
|
72
|
+
extensions: [".yml", ".yaml"], pathMatch: CI_FILES, fileTest: scanCannotFail, ...DRAFT },
|
|
73
|
+
{ id: "deps.unsafe-source", title: "Packages fetched from a source that can be swapped", status: "gap", severity: "medium", controls: [COMPONENTS, A03, A08],
|
|
74
|
+
fix: "Use one index or registry over https. For private packages, point only their scope or name at the private registry (npm: @scope:registry=..., pip: --index-url with a proxy that serves both) instead of adding a second index.",
|
|
75
|
+
note: "Over plain HTTP, or with certificate checks off, anyone on the network path can serve a different package. With a second pip index, a public package that takes an internal name with a higher version is installed instead (dependency confusion, CWE-829). Partial for the second-index case: your internal names may already be reserved.",
|
|
76
|
+
extensions: [".txt", ".conf", ".cfg", ".ini", ".toml", ".sh", ".bash", ".yml", ".yaml", ""],
|
|
77
|
+
fileName: /^(requirements[\w.-]*\.txt|constraints[\w.-]*\.txt|pip\.(conf|ini)|\.npmrc|\.yarnrc|pyproject\.toml|setup\.cfg)$|\.(sh|bash|ya?ml)$|^(Dockerfile|Containerfile)|\.Dockerfile$/i,
|
|
78
|
+
test: unsafeSource, ...DRAFT },
|
|
29
79
|
{ id: "repo.no-security-policy", title: "No way for people to report a vulnerability", status: "partial", severity: "medium", controls: [DISCLOSURE],
|
|
30
80
|
fix: "Add a SECURITY.md to the repository root (or .github/) saying where to report a vulnerability, what to include and how soon you'll reply.",
|
|
31
81
|
note: "The Cyber Resilience Act expects a policy for coordinated vulnerability disclosure and a contact address for reports. Marked Partial: the policy may live on your website, or you scanned a subfolder of a larger repo.",
|
|
@@ -37,18 +87,23 @@ export const craRules = [
|
|
|
37
87
|
{ id: "update.unverified-download", title: "Downloaded script run without a check", status: "partial", severity: "medium", controls: [UPDATES, A03, A08],
|
|
38
88
|
fix: "Download the file first, check it against a published checksum or signature, then run it. Or install from a package manager that verifies packages.",
|
|
39
89
|
note: "Piping `curl` or `wget` straight into a shell runs whatever the server sends at that moment, with no check that it is the file you expect. Marked Partial: well-known installers over HTTPS are a common, accepted risk.",
|
|
40
|
-
extensions: [".sh", ".bash", ".yml", ".yaml", ""], fileName: /\.(sh|bash|ya?ml)$|^Dockerfile
|
|
90
|
+
extensions: [".sh", ".bash", ".yml", ".yaml", ""], fileName: /\.(sh|bash|ya?ml)$|^(Dockerfile|Containerfile)|\.Dockerfile$/i,
|
|
41
91
|
// Quoted text is dropped first: `echo "Install via: curl ... | bash"` tells a person what to run, it runs nothing (field test).
|
|
42
92
|
// A script served from this machine (a CI test of the project's own installer) or an installer pinned to a version
|
|
43
93
|
// in its URL is not a moving download (0.3.9 review: 8 of 10 sampled findings were these, or prose).
|
|
44
94
|
test: (l) => /\b(curl|wget)\b[^|#\n]*\|\s*(sudo\s+)?(-\S+\s+)*(ba|z|da)?sh\b/.test(l.replace(/"(?:\\.|[^"\\])*"|'[^']*'/g, '""'))
|
|
45
95
|
&& !/\b(localhost|127\.0\.0\.1|0\.0\.0\.0)\b/.test(l) && !/https?:\/\/\S*\/v?\d+\.\d+(\.\d+)?\/\S*install/.test(l),
|
|
96
|
+
// The URL is a variable set to this machine a few lines up: BASE_URL=http://127.0.0.1:8765, then curl "$BASE_URL/get.sh" | bash.
|
|
97
|
+
// shortcut: any such assignment within 8 lines counts, tie it to the variable the curl uses if that ever hides a real one.
|
|
98
|
+
unlessNear: /^\s*(export\s+)?[A-Za-z_]\w*=["']?https?:\/\/(localhost|127\.0\.0\.1)\b/,
|
|
46
99
|
// YAML is only run as a script in CI and compose files; elsewhere (manifests, risk registers) it is prose.
|
|
47
100
|
unlessPath: /^(?!.*(\.github\/workflows|\.gitlab-ci|\.circleci|bitbucket-pipelines|azure-pipelines|\.buildkite|docker-compose|(^|\/)compose\.)).*\.ya?ml$/i, ...DRAFT },
|
|
48
101
|
{ id: "ci.write-all-permissions", title: "Workflow gives its token write access to everything", status: "gap", severity: "medium", controls: [UPDATES, A03],
|
|
49
102
|
fix: "Replace `permissions: write-all` with only what the job needs, for example `permissions: contents: read`, and grant write access per job where it's really used.",
|
|
50
103
|
note: "With write-all, any step that is compromised, including a third-party action, can push code, change releases or edit issues with the workflow's token.",
|
|
51
|
-
extensions: [".yml", ".yaml"], pathMatch: WORKFLOWS, test: (l) => /^\s*permissions:\s*["']?write-all\b/.test(l),
|
|
104
|
+
extensions: [".yml", ".yaml"], pathMatch: WORKFLOWS, test: (l) => /^\s*permissions:\s*["']?write-all\b/.test(l),
|
|
105
|
+
// A pull_request_target workflow with no permissions block at all gets the repository default, which is often write.
|
|
106
|
+
fileTest: (lines) => (lines.some((l) => /^\s*permissions\s*:/.test(l)) ? [] : lines.flatMap((l, i) => (/^\s*(-\s*)?pull_request_target\b|^\s*on\s*:.*\bpull_request_target\b/.test(l) ? [{ line: i + 1, status: "partial" }] : []))), ...DRAFT },
|
|
52
107
|
{ id: "ci.script-injection", title: "Text from a pull request or issue pasted into a workflow command", status: "gap", severity: "high", controls: [UPDATES, A03, A08],
|
|
53
108
|
fix: "Pass the value through an environment variable instead, for example `env: TITLE: ${{ github.event.issue.title }}` and then use \"$TITLE\" in the script.",
|
|
54
109
|
note: "Anyone who opens an issue or pull request controls its title, body and branch name. Pasted into a `run:` step, that text becomes part of the shell command and can run anything with the workflow's secrets.",
|
|
@@ -66,8 +121,23 @@ export const craRules = [
|
|
|
66
121
|
export function untrustedInRun(lines) {
|
|
67
122
|
const out = [];
|
|
68
123
|
let runIndent = -1; // indent of the `run: |` key while inside its block
|
|
124
|
+
// A job that only runs for people with write access gets its PR fields from trusted authors (0.3.14 review).
|
|
125
|
+
// shortcut: a step-level `if` counts for the rest of its job too, read job and step conditions apart if that misleads.
|
|
126
|
+
let trusted = false;
|
|
69
127
|
lines.forEach((l, i) => {
|
|
70
128
|
const indent = l.search(/\S/);
|
|
129
|
+
if (/^ {2}[\w-]+:\s*(#.*)?$/.test(l))
|
|
130
|
+
trusted = false; // next job
|
|
131
|
+
if (runIndent < 0 && /author_association\s*==\s*["'](OWNER|MEMBER|COLLABORATOR)["']/.test(l))
|
|
132
|
+
trusted = true;
|
|
133
|
+
if (trusted) {
|
|
134
|
+
if (runIndent >= 0 && indent >= 0 && indent <= runIndent)
|
|
135
|
+
runIndent = -1;
|
|
136
|
+
const r = /^(\s*-?\s*)(?:run|script):\s*[|>][-+]?\s*$/.exec(l);
|
|
137
|
+
if (r)
|
|
138
|
+
runIndent = r[1].length;
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
71
141
|
if (runIndent >= 0 && indent >= 0 && indent <= runIndent)
|
|
72
142
|
runIndent = -1;
|
|
73
143
|
// Also `script:` in actions/github-script, where the text becomes JavaScript instead of shell (review P17).
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Rule } from "../types.js";
|
|
2
|
+
export declare const MASKED: RegExp;
|
|
2
3
|
/** Shannon entropy in bits per character. Real keys are random (about 4 and up); aaaa... or xxxx... is near 0. Pure. */
|
|
3
4
|
export declare function entropy(s: string): number;
|
|
4
5
|
/** A Supabase (or any) JWT whose payload says role: service_role. Decoded exactly, so near-zero false alarms. Pure. */
|