@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/rules/index.js
CHANGED
|
@@ -12,7 +12,9 @@ const LOG_CALL = /\b(console\.(log|info|warn|error|debug)|logger\.\w+|log\.(info
|
|
|
12
12
|
// exponentially on text such as an array of regular expressions (found when statements were joined).
|
|
13
13
|
const codeOnly = (l) => l.replace(/(["'`])(?:\\.|(?!\1)[^\\])*\1/g, (s) => (s.match(/\{[^}]*\}/g) ?? []).join(" "));
|
|
14
14
|
// Helpers that hide the raw value before it is logged.
|
|
15
|
-
|
|
15
|
+
// Certificate or host-name checks switched off in Java, Kotlin, Dart and Python.
|
|
16
|
+
const NATIVE_TLS_OFF = /\bALLOW_ALL_HOSTNAME_VERIFIER\b|\b(setHostnameVerifier|hostnameVerifier)\s*[({]\s*\{?\s*\(?\s*\w+\s*,\s*\w+\s*\)?\s*->\s*true\b|\bHostnameVerifier\s*\{\s*\w+\s*,\s*\w+\s*->\s*true\s*\}|\bbadCertificateCallback\s*=\s*\([^)]*\)\s*=>\s*true|\bonReceivedSslError\b[^\n]*\.proceed\(\)|\b_create_unverified_context\(/;
|
|
17
|
+
export const MASKED = /\b\w*(mask|hash|pseudonym|redact|anonymi[sz]e|obfuscate|scrub)\w*\s*\(/i;
|
|
16
18
|
const PII = /\b(e-?mail|phone|ssn|social_?security|passport|date_?of_?birth|dob|password|passwd|credit_?card|card_?number|iban)\b/i;
|
|
17
19
|
// The arguments of the first log call on a line, up to its matching ")". Other code on the same line is ignored.
|
|
18
20
|
function logArgs(l) {
|
|
@@ -48,7 +50,7 @@ const KEY_FORMATS = new RegExp([
|
|
|
48
50
|
"-----BEGIN (RSA |EC |DSA |OPENSSH |ENCRYPTED )?PRIVATE KEY-----", "-----BEGIN PGP PRIVATE KEY BLOCK-----",
|
|
49
51
|
].join("|"));
|
|
50
52
|
// Example values from provider docs (AKIAIOSFODNN7EXAMPLE and the like) and obvious fill-ins.
|
|
51
|
-
const DOC_EXAMPLE = /EXAMPLE|X{6,}|x{6,}|0{12,}|1234567890abcdef/;
|
|
53
|
+
const DOC_EXAMPLE = /EXAMPLE|X{6,}|x{6,}|0{12,}|1234567890abcdef|abc123/;
|
|
52
54
|
/** Shannon entropy in bits per character. Real keys are random (about 4 and up); aaaa... or xxxx... is near 0. Pure. */
|
|
53
55
|
export function entropy(s) {
|
|
54
56
|
const n = {};
|
|
@@ -58,6 +60,15 @@ export function entropy(s) {
|
|
|
58
60
|
}
|
|
59
61
|
// A PEM header with no key body after it: in a comment, or text a program builds a key around at runtime (field-test review).
|
|
60
62
|
const PEM_NO_BODY = /^\s*(#|\/\/|\*|<!--|--\s)|PRIVATE KEY( BLOCK)?-----(\\n)?["'`]\s*(\+|\.join|,|\))/;
|
|
63
|
+
// A key written inside one string that ends on the same line, with a body too short or too regular to be a key: a redaction
|
|
64
|
+
// test's "CanaryLineOne", a cut-off sample. The shortest real key (Ed25519) has 64 base64 characters (0.3.14 review: 17 of 17).
|
|
65
|
+
const pemInlineFake = (l) => {
|
|
66
|
+
const after = l.slice(l.indexOf("PRIVATE KEY")).replace(/^PRIVATE KEY( BLOCK)?-----/, "");
|
|
67
|
+
const body = after.split("-----END")[0].replace(/\\+[nr]|[^A-Za-z0-9+/=]/g, "");
|
|
68
|
+
return /-----END|["'`]\s*[,;)\]}]*\s*$/.test(after) && (body.length < 64 || /abcdefghijklmnop/.test(body));
|
|
69
|
+
};
|
|
70
|
+
// A "secret" whose base64 reads as a sentence is documentation ("This is an example of a shorter Base64 string").
|
|
71
|
+
const readsAsText = (key) => /^(?=.* )[\x20-\x7e]{12,}$/.test(Buffer.from(key.slice(key.lastIndexOf("_") + 1), "base64").toString("latin1"));
|
|
61
72
|
// More fixed-prefix secrets this audience leaks: Stripe webhook secrets, Supabase secret keys, Resend keys (review P13).
|
|
62
73
|
const MORE_KEYS = /\bwhsec_[0-9A-Za-z]{24,}|\bsb_secret_[0-9A-Za-z_-]{20,}|\bre_[0-9A-Za-z]{8,}_[0-9A-Za-z]{16,}/;
|
|
63
74
|
/** A Supabase (or any) JWT whose payload says role: service_role. Decoded exactly, so near-zero false alarms. Pure. */
|
|
@@ -102,6 +113,9 @@ export const rules = [
|
|
|
102
113
|
// A value passed through a masking or hashing helper first (maskEmail(), pseudonym(), hash()) is not the raw value:
|
|
103
114
|
// every false alarm on 56 new repos in the 0.3.9 review was masked this way (12 of 12).
|
|
104
115
|
test: (l) => { const a = logArgs(l); return a !== null && !l.includes("::add-mask::") && PII.test(codeOnly(a)) && !MASKED.test(a); },
|
|
116
|
+
// A command-line tool prints to the terminal of the person running it, not to a log store: "Logged in as <email>"
|
|
117
|
+
// after a login is the point of the command (5 of the 12 false alarms still shown in 0.3.14; no real one was in a CLI).
|
|
118
|
+
unlessPath: /(^|\/)cli\/|(^|\/)(packages|apps)\/[^/]*cli[^/]*\//i,
|
|
105
119
|
...DRAFT,
|
|
106
120
|
},
|
|
107
121
|
{
|
|
@@ -126,14 +140,14 @@ export const rules = [
|
|
|
126
140
|
const pem = !!m && /-----BEGIN/.test(m[0]);
|
|
127
141
|
// The part after a fixed prefix must look random: ghp_aaaaaaaa... is a fill-in, not a token.
|
|
128
142
|
const tooRegular = !!m && !pem && entropy(m[0].replace(/^[A-Za-z]+[_-]+(?:[a-z]+[_-]+)?/, "")) < 3;
|
|
129
|
-
if (pem && PEM_NO_BODY.test(l))
|
|
143
|
+
if (pem && (PEM_NO_BODY.test(l) || pemInlineFake(l)))
|
|
130
144
|
return serviceRoleJwt(l) || dbUrlWithPassword(l);
|
|
131
|
-
return (!!m && !tooRegular && !DOC_EXAMPLE.test(m[0]) && !/your[-_]|fake|dummy|placeholder|changeme|sample/.test(m[0]) /* lowercase words: real keys are random */
|
|
145
|
+
return (!!m && !tooRegular && !DOC_EXAMPLE.test(m[0]) && (pem || !readsAsText(m[0])) && !/your[-_]|fake|dummy|placeholder|changeme|sample/.test(m[0]) /* lowercase words: real keys are random */
|
|
132
146
|
&& !/PRIVATE KEY( BLOCK)?-----(["'`]|\.\.\.|\\n\s*\.\.\.|\s+[a-zA-Z])/.test(l)) || serviceRoleJwt(l) || dbUrlWithPassword(l);
|
|
133
147
|
},
|
|
134
148
|
// Translation files mention "API key" and "secret" in every language, never a real key. Type definition files
|
|
135
149
|
// carry documentation examples, and secret-scanner configs list known test keys on purpose (0.3.9 review).
|
|
136
|
-
unlessPath: /(^|\/)(locales?|i18n|translations?|lang)\/|\.d\.ts$|(^|\/)(\.gitleaks\.toml|\.secrets\.baseline|\.trufflehog\.ya?ml)$/i,
|
|
150
|
+
unlessPath: /(^|\/)(locales?|i18n|translations?|lang)\/|\.d\.ts$|(^|\/)(\.gitleaks\.toml|\.gitleaksignore|\.secrets\.baseline|\.trufflehog\.ya?ml)$/i,
|
|
137
151
|
...DRAFT,
|
|
138
152
|
},
|
|
139
153
|
{
|
|
@@ -147,7 +161,7 @@ export const rules = [
|
|
|
147
161
|
note: "Marked Partial: the call may carry no sensitive data. Confirm, then switch to HTTPS anyway.",
|
|
148
162
|
extensions: CODE,
|
|
149
163
|
// Loopback, private ranges and single-label service names (http://redis:6379) stay on the machine or network (field test).
|
|
150
|
-
test: (l) => /\b(fetch|axios\.\w+|requests\.\w+|http\.(get|request))\s*\(\s*["'`]http:\/\/(?!localhost|127\.|0\.0\.0\.0|10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.|\[::1\]|host\.docker\.internal)[\w-]+\.[\w.-]+/.test(l),
|
|
164
|
+
test: (l) => /\b(fetch|axios\.\w+|requests\.\w+|http\.(get|request))\s*\(\s*["'`]http:\/\/(?!localhost|127\.|0\.0\.0\.0|10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.|\[::1\]|host\.docker\.internal|[\w.-]+\.(test|example|invalid|localhost)(?![\w.-]))[\w-]+\.[\w.-]+/.test(l),
|
|
151
165
|
...DRAFT,
|
|
152
166
|
},
|
|
153
167
|
{
|
|
@@ -162,7 +176,9 @@ export const rules = [
|
|
|
162
176
|
extensions: CODE,
|
|
163
177
|
// Also a bare track("event", { ... }), the way @vercel/analytics and similar SDKs are imported and called.
|
|
164
178
|
test: (l) => (/\b(posthog|analytics|mixpanel|amplitude|segment|heap|gtag|ga|intercom|hotjar|sentry)\.(identify|track|capture|people\.set|setUser|setUserProperties|register)\s*\(/i.test(l)
|
|
165
|
-
|| /(^|[^.\w])track\s*\(\s*["'`][^"'`]+["'`]\s*,\s*\{/.test(l)) && PII.test(l),
|
|
179
|
+
|| /(^|[^.\w])track\s*\(\s*["'`][^"'`]+["'`]\s*,\s*\{/.test(l)) && PII.test(l.replace(/:\s*["'][\w -]*["']/g, ": 0")),
|
|
180
|
+
// Sent only inside a branch that checks the person opted in (0.3.14 review).
|
|
181
|
+
unlessNear: /\bif\b.*\b(opted_?[iI]n|has_?[cC]onsent|consent(Given|ed)?)\b/,
|
|
166
182
|
...DRAFT,
|
|
167
183
|
},
|
|
168
184
|
{
|
|
@@ -208,8 +224,11 @@ export const rules = [
|
|
|
208
224
|
],
|
|
209
225
|
fix: "Remove the override and trust a proper certificate. For self-signed certs in tests, scope it to the test only.",
|
|
210
226
|
note: "With checks off, anyone on the network path can read or change the traffic.",
|
|
211
|
-
|
|
212
|
-
|
|
227
|
+
// Scripts and Dockerfiles switch the check off too: curl -k, curl --insecure, wget --no-check-certificate.
|
|
228
|
+
extensions: [...CODE, ".env", ".sh", ".bash", "", ".java", ".kt", ".swift", ".go", ".dart"],
|
|
229
|
+
test: (l) => (/\bcurl\b[^|;&\n]*\s(-[sSfLIvO#]*k[sSfLIvO#]*|--insecure)(\s|$)|\bwget\b[^|;&\n]*--no-check-certificate\b/.test(l) && !/^\s*#|localhost|127\.0\.0\.1/.test(l)) || NATIVE_TLS_OFF.test(l) || /rejectUnauthorized\s*:\s*false|NODE_TLS_REJECT_UNAUTHORIZED\s*[=:]\s*["']?0|\b(requests|httpx|session|client|Client|AsyncClient|urlopen)\b.*\bverify\s*=\s*False|InsecureSkipVerify\s*:\s*true|verify_mode\s*=\s*ssl\.CERT_NONE|cert_reqs\s*=\s*ssl\.CERT_NONE/.test(l), // naming CERT_NONE in a settings map isn't switching it on
|
|
230
|
+
// A host-name check switched off on its own. Next to CERT_NONE the neighbouring line already reports it (review: 8 of 8 were doubles).
|
|
231
|
+
fileTest: (lines) => lines.flatMap((l, i) => (/\bcheck_hostname\s*=\s*False\b/.test(l) && !/CERT_NONE/.test([lines[i - 1], lines[i + 1], lines[i + 2]].join(" ")) ? [i + 1] : [])),
|
|
213
232
|
// Only the switches with one safe opposite; env vars and ssl modes need a person.
|
|
214
233
|
patch: (l) => l.replace(/rejectUnauthorized(\s*):(\s*)false/, "rejectUnauthorized$1:$2true").replace(/\bverify(\s*)=(\s*)False\b/, "verify$1=$2True").replace(/InsecureSkipVerify(\s*):(\s*)true/, "InsecureSkipVerify$1:$2false"),
|
|
215
234
|
...DRAFT,
|
|
@@ -261,6 +280,8 @@ export const rules = [
|
|
|
261
280
|
fileTest: (lines) => lines.flatMap((l, i) => {
|
|
262
281
|
if (!/Access-Control-Allow-Origin["']?\s*[,:]\s*(["']\*["']|[\w.]*(req|request)\.headers?(\.get\(|\[|\.)\s*["']?origin)|origin\s*:\s*(["']\*["']|true\b|[\w.]*(req|request)\.headers?\.origin)|CORS_ALLOW_ALL_ORIGINS\s*=\s*True|CORS_ORIGIN_ALLOW_ALL\s*=\s*True|allow_origins\s*=\s*\[\s*["']\*["']|allow_origin_regex\s*=\s*["']\.\*/.test(l))
|
|
263
282
|
return [];
|
|
283
|
+
if (/credentials["']?\s*[:=]\s*["']?false|allow_credentials\s*=\s*False|CORS_ALLOW_CREDENTIALS\s*=\s*False/i.test(lines.slice(Math.max(0, i - 3), i + 9).join("\n")))
|
|
284
|
+
return [];
|
|
264
285
|
const near = lines.slice(Math.max(0, i - 12), i + 13).join("\n");
|
|
265
286
|
return /credentials["']?\s*[:=,]\s*["']?true|Allow-Credentials["']?\s*[,:]\s*["']?true|CORS_ALLOW_CREDENTIALS\s*=\s*True|allow_credentials\s*=\s*True|supports_credentials\s*=\s*True/i.test(near) ? [i + 1] : [];
|
|
266
287
|
}),
|
|
@@ -278,6 +299,9 @@ export const rules = [
|
|
|
278
299
|
// A bare `secure: false` is usually a client, proxy or database option: it counts only near a cookie being set
|
|
279
300
|
// (0.3.9 labels: 9 of 14 false alarms had no cookie in sight). CSRF cookies are meant to be readable by scripts.
|
|
280
301
|
fileTest: (lines) => lines.flatMap((l, i) => {
|
|
302
|
+
// A session cookie set with no options at all gets neither flag.
|
|
303
|
+
if (/\bres\.cookie\(\s*["'`][\w.-]*(session|sess|sid|token|auth|jwt)[\w.-]*["'`]\s*,\s*[^,()]+\)/i.test(l) && !/csrf|xsrf/i.test(l))
|
|
304
|
+
return [i + 1];
|
|
281
305
|
if (!/\b(httpOnly|secure)\s*:\s*false\b|SESSION_COOKIE_(SECURE|HTTPONLY)\s*=\s*False/.test(l))
|
|
282
306
|
return [];
|
|
283
307
|
const near = lines.slice(Math.max(0, i - 6), i + 4).join("\n");
|
|
@@ -348,7 +372,10 @@ rules.push({
|
|
|
348
372
|
extensions: CODE,
|
|
349
373
|
// A model's output and a decision word on the same line, e.g. status = model.predict(x) > 0.5 ? "approved" : "rejected".
|
|
350
374
|
// score() and invoke() are too generic: a music score, a memory ranking (field test).
|
|
351
|
-
test: (l) => /\b(predict|predict_proba|classify|generateText|generateObject)\w*\s*\(|\.chat\.completions\.create\s*\(/.test(l) && DECISION.test(l)
|
|
375
|
+
test: (l) => /\b(predict|predict_proba|classify|generateText|generateObject)\w*\s*\(|\.chat\.completions\.create\s*\(/.test(l) && DECISION.test(l)
|
|
376
|
+
// A function being defined decides nothing yet, and allow/deny for a tool, a permission or access is an agent's
|
|
377
|
+
// permission system, not a decision about a person (0.3.14 review: 0 of 4 shown findings were about people).
|
|
378
|
+
&& !/^\s*(export\s+)?(async\s+)?(def|function)\s/.test(l) && !/\b(tool|permissions?|access)\b/.test(l),
|
|
352
379
|
...DRAFT,
|
|
353
380
|
}, {
|
|
354
381
|
id: "ai.call-not-logged",
|
package/dist/src/rules/more.d.ts
CHANGED
|
@@ -3,6 +3,31 @@ import type { Rule } from "../types.js";
|
|
|
3
3
|
export declare function wsNoOrigin(lines: string[]): number[];
|
|
4
4
|
/** Lines matching re in a file that registers MCP tools; nothing in other files. Pure. */
|
|
5
5
|
export declare function inMcpServer(lines: string[], re: RegExp): number[];
|
|
6
|
+
/** MCP config: a server run from a version that can change after you approved it (Partial), or reached over plain HTTP (Gap). Pure.
|
|
7
|
+
* shortcut: reads npx-style args only ("-y", "pkg"); add uvx and docker image tags when a field test shows them. */
|
|
8
|
+
export declare function mcpConfigUnsafe(lines: string[]): Array<{
|
|
9
|
+
line: number;
|
|
10
|
+
status: "gap" | "partial";
|
|
11
|
+
}>;
|
|
12
|
+
/** Key sizes and work factors below what current guidance accepts. Pure. */
|
|
13
|
+
export declare function weakCryptoParameter(l: string): boolean | "partial";
|
|
14
|
+
/** Android release build that can be debugged: the manifest flag, or `debuggable true` inside the release block of build.gradle. Pure. */
|
|
15
|
+
export declare function debuggableBuild(lines: string[]): number[];
|
|
16
|
+
/** A line that declares a stored field with one of these names: SQL column, Prisma, Mongoose, Sequelize, TypeORM, Django,
|
|
17
|
+
* SQLAlchemy. A TypeScript type (`cvv: string`) describes a form value, not storage, so it doesn't count. Pure. */
|
|
18
|
+
export declare function storedField(names: string): (l: string) => boolean;
|
|
19
|
+
/** A consent or marketing checkbox that starts ticked, or its state that starts as true. Pure. */
|
|
20
|
+
export declare function consentPreticked(lines: string[]): number[];
|
|
21
|
+
/** A firewall rule that lets the whole internet reach an admin or database port. Reads the block around the open range:
|
|
22
|
+
* inbound only, and only when the ports are written there. Pure.
|
|
23
|
+
* shortcut: reads up to 10 lines either side of the range, not the parsed block; parse HCL if rules get longer. */
|
|
24
|
+
export declare function networkOpen(lines: string[]): number[];
|
|
25
|
+
/** A policy statement that allows every action on every resource. A Deny statement with the same wildcards is a guard. Pure. */
|
|
26
|
+
export declare function iamAllowAll(lines: string[]): number[];
|
|
27
|
+
/** Dockerfile whose last stage never switches away from root: the last FROM line, or its `USER root` line. Pure. */
|
|
28
|
+
export declare function dockerRunsAsRoot(lines: string[]): number[];
|
|
29
|
+
/** FROM lines with no tag or the `latest` tag. A stage name, a digest, a build argument and `scratch` are not images to pin. Pure. */
|
|
30
|
+
export declare function dockerImageUnpinned(lines: string[]): number[];
|
|
6
31
|
export declare const moreRules: Rule[];
|
|
7
32
|
/** The service password variable on this line when it's set to a well-known default, else null. Pure. */
|
|
8
33
|
export declare function defaultPasswordKey(l: string): string | null;
|
package/dist/src/rules/more.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AGENT_CONFIG, poisonedDescription } from "./owasp.js";
|
|
1
2
|
const CODE = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs", ".py"];
|
|
2
3
|
const JS = [".ts", ".tsx", ".js", ".jsx", ".mjs", ".cjs"];
|
|
3
4
|
const MARKUP = [...CODE, ".html", ".vue", ".svelte", ".astro"];
|
|
@@ -13,7 +14,8 @@ const WS_SERVER = /\bnew\s+(WebSocketServer|WebSocket\.Server|WSServer)\s*\(|\bn
|
|
|
13
14
|
/** Lines that start a web-socket server in a file with no origin check (verifyClient, an origin test, allowRequest). Pure. */
|
|
14
15
|
export function wsNoOrigin(lines) {
|
|
15
16
|
const text = lines.join("\n");
|
|
16
|
-
|
|
17
|
+
// `origin: "*"` and `origin: true` name the origin without checking it, so they don't count as a check.
|
|
18
|
+
if (/\bverifyClient\b|\borigin\b|\ballowRequest\b|\bnoServer\s*:\s*true/.test(text.replace(/\borigin\s*:\s*(["'`]\*["'`]|true\b)/g, "")))
|
|
17
19
|
return [];
|
|
18
20
|
return lines.flatMap((l, i) => (WS_SERVER.test(l) ? [i + 1] : []));
|
|
19
21
|
}
|
|
@@ -32,7 +34,248 @@ export function inMcpServer(lines, re) {
|
|
|
32
34
|
}
|
|
33
35
|
const LLM03 = { framework: "owasp-llm", id: "LLM03:2026", title: "Excessive Agency" };
|
|
34
36
|
const LLM04 = { framework: "owasp-llm", id: "LLM04:2026", title: "Supply Chain" };
|
|
37
|
+
const LLM01 = { framework: "owasp-llm", id: "LLM01:2026", title: "Prompt Injection" };
|
|
38
|
+
/** MCP config: a server run from a version that can change after you approved it (Partial), or reached over plain HTTP (Gap). Pure.
|
|
39
|
+
* shortcut: reads npx-style args only ("-y", "pkg"); add uvx and docker image tags when a field test shows them. */
|
|
40
|
+
export function mcpConfigUnsafe(lines) {
|
|
41
|
+
if (!lines.some((l) => /"(mcpServers|servers|context_servers)"\s*:/.test(l)))
|
|
42
|
+
return [];
|
|
43
|
+
const out = [];
|
|
44
|
+
lines.forEach((l, i) => {
|
|
45
|
+
if (/"(url|serverUrl|endpoint)"\s*:\s*"http:\/\/(?!localhost|127\.0\.0\.1|\[::1\]|0\.0\.0\.0|host\.docker\.internal)/.test(l)) {
|
|
46
|
+
out.push({ line: i + 1, status: "gap" });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (/@latest"/.test(l)) {
|
|
50
|
+
out.push({ line: i + 1, status: "partial" });
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const yes = /"(-y|--yes)"\s*,?\s*(.*)$/.exec(l);
|
|
54
|
+
if (!yes)
|
|
55
|
+
return;
|
|
56
|
+
const same = /^"([^"]+)"/.exec(yes[2].trim()), next = /^\s*"([^"]+)"/.exec(lines[i + 1] ?? "");
|
|
57
|
+
const pkg = same?.[1] ?? next?.[1];
|
|
58
|
+
if (pkg && /^(@[\w.-]+\/)?[\w.-]+$/.test(pkg))
|
|
59
|
+
out.push({ line: same ? i + 1 : i + 2, status: "partial" });
|
|
60
|
+
});
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
const DOCKERFILE = /^(Dockerfile|Containerfile)|\.Dockerfile$/i;
|
|
64
|
+
const NATIVE = [".java", ".kt", ".swift", ".go", ".dart"];
|
|
65
|
+
// An IV or nonce that is the same for every message: zero bytes or fixed text. Reusing one with the same key breaks
|
|
66
|
+
// AES-GCM outright and leaks patterns in CBC. A buffer that is filled with random bytes on the next lines is fine (unlessNear).
|
|
67
|
+
const STATIC_IV = /\b(iv|IV|nonce|initVector|initializationVector)\s*[:=]\s*(Buffer\.alloc\(\s*\d+\s*(,\s*0\s*)?\)|Buffer\.from\(\s*["'][^"']+["'])|\b(iv|nonce)\s*=\s*(b["'][^"']+["']|bytes\(\s*\d+\s*\))|\b(Iv|GCM)ParameterSpec\(\s*(\d+\s*,\s*)?(new\s+byte\[\d+\]|ByteArray\(\d+\)|"[^"]+"\.(getBytes|toByteArray)\()|\b(iv|nonce)\s*:?=\s*\[\]byte\("[^"]+"\)/;
|
|
68
|
+
/** Key sizes and work factors below what current guidance accepts. Pure. */
|
|
69
|
+
export function weakCryptoParameter(l) {
|
|
70
|
+
// PBKDF2 is also used to derive cache keys and ids, where the round count doesn't matter: Gap only when a password is named.
|
|
71
|
+
const kdf = () => (/pass(word|wd|phrase)?/i.test(l) ? true : "partial");
|
|
72
|
+
if (/^\s*(\/\/|#|\*)/.test(l))
|
|
73
|
+
return false;
|
|
74
|
+
// PBKDF2 under 10,000 rounds (OWASP asks for 600,000 with SHA-256; a four-digit count is far off any guidance).
|
|
75
|
+
if (/\bpbkdf2(Sync)?\(\s*[^,]+,\s*[^,]+,\s*\d{1,4}\s*,|\bpbkdf2_hmac\(\s*[^,]+,\s*[^,]+,\s*[^,]+,\s*\d{1,4}\s*[,)]|\bPBEKeySpec\(\s*[^,]+,\s*[^,]+,\s*\d{1,4}\s*,/.test(l))
|
|
76
|
+
return kdf();
|
|
77
|
+
if (/\bPBKDF2\w*\(/.test(l) && /\biterations\s*=\s*\d{1,4}\s*[,)]/.test(l))
|
|
78
|
+
return kdf();
|
|
79
|
+
// bcrypt below 10 rounds.
|
|
80
|
+
if (/\bbcrypt\.(hash|hashSync|genSalt|genSaltSync)\(\s*(?:[^,()]+,\s*)?[1-9]\s*[,)]|\bgensalt\(\s*(?:rounds\s*=\s*)?[1-9]\s*\)/.test(l))
|
|
81
|
+
return true;
|
|
82
|
+
// RSA keys under 2048 bits.
|
|
83
|
+
return /\bmodulusLength\s*:\s*(512|768|1024)\b|\bkey_size\s*=\s*(512|768|1024)\b|\brsa\.GenerateKey\(\s*[^,]+,\s*(512|768|1024)\s*\)|\b\w*([Kk]eyGen|kpg|[Gg]enerator)\w*\.initialize\(\s*(512|768|1024)\s*[,)]|\bopenssl\s+genrsa\b[^|;\n]*\s(512|768|1024)\b/.test(l);
|
|
84
|
+
}
|
|
85
|
+
/** Android release build that can be debugged: the manifest flag, or `debuggable true` inside the release block of build.gradle. Pure. */
|
|
86
|
+
export function debuggableBuild(lines) {
|
|
87
|
+
return lines.flatMap((l, i) => {
|
|
88
|
+
if (/android:debuggable\s*=\s*"true"/.test(l))
|
|
89
|
+
return [i + 1];
|
|
90
|
+
if (!/\b(isDebuggable\s*=\s*true|debuggable\s+true|debuggable\s*=\s*true)\b/.test(l))
|
|
91
|
+
return [];
|
|
92
|
+
const block = lines.slice(Math.max(0, i - 12), i).reverse().find((x) => /^\s*(release|debug|getByName\("(release|debug)"\)|named\("(release|debug)"\))\s*\{/.test(x)) ?? "";
|
|
93
|
+
return /release/.test(block) ? [i + 1] : [];
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
const GDPR = (id, title) => ({ framework: "gdpr", id, title });
|
|
97
|
+
/** A line that declares a stored field with one of these names: SQL column, Prisma, Mongoose, Sequelize, TypeORM, Django,
|
|
98
|
+
* SQLAlchemy. A TypeScript type (`cvv: string`) describes a form value, not storage, so it doesn't count. Pure. */
|
|
99
|
+
export function storedField(names) {
|
|
100
|
+
const re = new RegExp(String.raw `\b(${names})\b["']?\s*(:\s*(\{\s*type\s*:\s*)?(String|Number|Boolean|DataTypes\.\w+|Sequelize\.\w+|Schema\.Types\.\w+)\b|\s+(VARCHAR|CHAR|TEXT|INT|INTEGER|SMALLINT|BOOLEAN|JSONB?)\b|\s+(String|Int|Boolean|Json)\??\s*(@|$)|\s*=\s*(models|db|sa|sqlalchemy)\.\w+\(|\s*=\s*(mapped_column|Column)\(|\s*:\s*Mapped\[)`, "i");
|
|
101
|
+
return (l) => !/^\s*(\/\/|#|--|\*)/.test(l) && (re.test(l) || (/@(Column|Prop)\(/.test(l) && new RegExp(String.raw `\b(${names})\b`, "i").test(l))) && (/@(Column|Prop)\(/.test(l) || !/:\s*(string|number|boolean)\b/.test(l));
|
|
102
|
+
}
|
|
103
|
+
const CARD_CODE = storedField("cvv2?|cvc2?|card_?security_?code|card_?verification_?(code|value)");
|
|
104
|
+
const SPECIAL = storedField("religion|religious_?belief|ethnicity|ethnic_?origin|sexual_?orientation|political_?(affiliation|opinion|party)|trade_?union(_?membership)?|hiv_?status|genetic_?data");
|
|
105
|
+
const CONSENT_WORD = /consent|marketing|newsletter|subscribe|opt[-_ ]?in|promotional/i;
|
|
106
|
+
/** A consent or marketing checkbox that starts ticked, or its state that starts as true. Pure. */
|
|
107
|
+
export function consentPreticked(lines) {
|
|
108
|
+
return lines.flatMap((l, i) => {
|
|
109
|
+
// State that starts true for a consent value; a flag that only shows the banner is not consent.
|
|
110
|
+
const st = /\[\s*(\w+)\s*,\s*set\w+\s*\]\s*=\s*useState(<[^>]*>)?\(\s*true\s*\)/.exec(l);
|
|
111
|
+
if (st && CONSENT_WORD.test(st[1]) && !/show|open|visible|banner|modal|dialog|loading|seen/i.test(st[1]))
|
|
112
|
+
return [i + 1];
|
|
113
|
+
// `checked={value}` is controlled state; only a bare attribute or a literal true pre-ticks the box.
|
|
114
|
+
const attrs = l.replace(/\b(defaultChecked|checked)\s*=\s*\{(?!\s*true\s*\})[^}]*\}/g, "");
|
|
115
|
+
// A variable or arrow parameter named `checked` (`const checked = ...`, `checked => ...`) is code, not the attribute.
|
|
116
|
+
if (/^\s*(const|let|var|return|if)\b/.test(l) || !/(^|\s)(defaultChecked|checked)(\s*=\s*(\{\s*true\s*\}|["'](checked|true)["'])(\s|\/?>|$)|(?!\s*=)(\s|\/?>|$))/.test(attrs))
|
|
117
|
+
return [];
|
|
118
|
+
const near = lines.slice(Math.max(0, i - 4), i + 5).join("\n");
|
|
119
|
+
return /type\s*=\s*["']checkbox["']|<Checkbox\b/.test(near) && CONSENT_WORD.test(near) ? [i + 1] : [];
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const IAC = [".tf", ".json", ".yml", ".yaml"];
|
|
123
|
+
// Ports that should never face the internet: remote login, databases, caches, search and the Docker API.
|
|
124
|
+
const ADMIN_PORTS = [22, 23, 3389, 5900, 1433, 1521, 3306, 5432, 6379, 9200, 9300, 11211, 27017, 5984, 2375, 2376];
|
|
125
|
+
const OPEN_CIDR = /cidr_blocks\s*=\s*\[[^\]]*"0\.0\.0\.0\/0"|ipv6_cidr_blocks\s*=\s*\[[^\]]*"::\/0"|\bCidrIp(v6)?\s*:\s*["']?(0\.0\.0\.0\/0|::\/0)|source_ranges\s*=\s*\[[^\]]*"0\.0\.0\.0\/0"|source_address_prefix\s*=\s*"(\*|0\.0\.0\.0\/0|Internet)"/;
|
|
126
|
+
/** A firewall rule that lets the whole internet reach an admin or database port. Reads the block around the open range:
|
|
127
|
+
* inbound only, and only when the ports are written there. Pure.
|
|
128
|
+
* shortcut: reads up to 10 lines either side of the range, not the parsed block; parse HCL if rules get longer. */
|
|
129
|
+
export function networkOpen(lines) {
|
|
130
|
+
return lines.flatMap((l, i) => {
|
|
131
|
+
if (!OPEN_CIDR.test(l) || /^\s*(#|\/\/)/.test(l))
|
|
132
|
+
return [];
|
|
133
|
+
const head = /^\s*(ingress|egress|resource|rule|allow|deny|security_rule|-\s*IpProtocol|SecurityGroup(Ingress|Egress))\b/;
|
|
134
|
+
let a = i, b = i;
|
|
135
|
+
while (a > 0 && i - a < 10 && !head.test(lines[a]))
|
|
136
|
+
a--;
|
|
137
|
+
while (b < lines.length - 1 && b - i < 10 && !/^\s*\}\s*$/.test(lines[b]) && !(b > i && head.test(lines[b + 1])))
|
|
138
|
+
b++;
|
|
139
|
+
const block = lines.slice(a, b + 1).join("\n");
|
|
140
|
+
if (/^\s*egress\b|SecurityGroupEgress|type\s*=\s*"egress"|direction\s*=\s*"(Outbound|EGRESS)"/im.test(block))
|
|
141
|
+
return [];
|
|
142
|
+
if (/protocol\s*=\s*"(-1|all)"|IpProtocol\s*:\s*["']?-1/.test(block))
|
|
143
|
+
return [i + 1];
|
|
144
|
+
const n = (re) => { const m = re.exec(block); return m ? Number(m[1]) : null; };
|
|
145
|
+
const lo = n(/\b(?:from_port|FromPort)\s*[=:]\s*"?(\d+)/), hi = n(/\b(?:to_port|ToPort)\s*[=:]\s*"?(\d+)/);
|
|
146
|
+
const single = [...block.matchAll(/\b(?:ports|destination_port_ranges?)\s*=\s*\[?([^\]\n]*)/g)].flatMap((m) => [...m[1].matchAll(/\d+/g)].map((x) => Number(x[0])));
|
|
147
|
+
if (lo !== null && ADMIN_PORTS.some((p) => p >= lo && p <= (hi ?? lo)))
|
|
148
|
+
return [i + 1];
|
|
149
|
+
return single.some((p) => ADMIN_PORTS.includes(p)) ? [i + 1] : [];
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/** A policy statement that allows every action on every resource. A Deny statement with the same wildcards is a guard. Pure. */
|
|
153
|
+
export function iamAllowAll(lines) {
|
|
154
|
+
return lines.flatMap((l, i) => {
|
|
155
|
+
if (!/"?\bAction"?\s*[:=]\s*\[?\s*["']\*["']|\bactions\s*=\s*\[\s*"\*"\s*\]/.test(l))
|
|
156
|
+
return [];
|
|
157
|
+
const near = lines.slice(Math.max(0, i - 6), i + 7).join("\n");
|
|
158
|
+
return /"?\bResource"?\s*[:=]\s*\[?\s*["']\*["']|\bresources\s*=\s*\[\s*"\*"\s*\]/.test(near) && !/\bEffect"?\s*[:=]\s*["']Deny["']/i.test(near) ? [i + 1] : [];
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
// `from x import y` inside a RUN python block is not a FROM instruction.
|
|
162
|
+
const from = (l) => (/\bimport\b/.test(l) ? null : /^\s*FROM\s+(?:--\S+\s+)*(\S+)(?:\s+AS\s+(\S+))?/i.exec(l));
|
|
163
|
+
// Official server images start as root and drop to their own user in the entrypoint.
|
|
164
|
+
const DROPS_ROOT = /^(docker\.io\/)?(library\/)?(mysql|mariadb|postgres|redis|mongo|rabbitmq|memcached|elasticsearch|influxdb|grafana\/grafana|clickhouse\/clickhouse-server)(:|@|$)/i;
|
|
165
|
+
/** Dockerfile whose last stage never switches away from root: the last FROM line, or its `USER root` line. Pure. */
|
|
166
|
+
export function dockerRunsAsRoot(lines) {
|
|
167
|
+
let last = -1;
|
|
168
|
+
lines.forEach((l, i) => { if (from(l))
|
|
169
|
+
last = i; });
|
|
170
|
+
if (last < 0)
|
|
171
|
+
return [];
|
|
172
|
+
// Images built to run without root, and `scratch` (nothing to switch to), are left alone.
|
|
173
|
+
if (/nonroot|rootless|unprivileged|chainguard|\bscratch\b/i.test(from(lines[last])[1]) || DROPS_ROOT.test(from(lines[last])[1]))
|
|
174
|
+
return [];
|
|
175
|
+
const users = lines.map((l, i) => [i, /^\s*USER\s+(\S+)/i.exec(l)?.[1]]).filter(([i, u]) => i > last && u);
|
|
176
|
+
if (!users.length)
|
|
177
|
+
return [last + 1];
|
|
178
|
+
const [line, user] = users[users.length - 1];
|
|
179
|
+
return /^(root|0)(:|$)/.test(user) ? [line + 1] : [];
|
|
180
|
+
}
|
|
181
|
+
/** FROM lines with no tag or the `latest` tag. A stage name, a digest, a build argument and `scratch` are not images to pin. Pure. */
|
|
182
|
+
export function dockerImageUnpinned(lines) {
|
|
183
|
+
const stages = new Set();
|
|
184
|
+
return lines.flatMap((l, i) => {
|
|
185
|
+
const m = from(l);
|
|
186
|
+
if (!m)
|
|
187
|
+
return [];
|
|
188
|
+
const image = m[1];
|
|
189
|
+
if (m[2])
|
|
190
|
+
stages.add(m[2].toLowerCase());
|
|
191
|
+
if (stages.has(image.toLowerCase()) && image.toLowerCase() !== m[2]?.toLowerCase())
|
|
192
|
+
return [];
|
|
193
|
+
if (image === "scratch" || image.includes("$") || image.includes("@sha256:"))
|
|
194
|
+
return [];
|
|
195
|
+
const tag = /:([^/:]+)$/.exec(image)?.[1];
|
|
196
|
+
return !tag || tag === "latest" ? [i + 1] : [];
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
// A secret given a value at build time stays in the image's layers and history for anyone who pulls it.
|
|
200
|
+
const BUILD_SECRET = /^\s*(ENV|ARG)\s+(?!NEXT_PUBLIC_|VITE_|PUBLIC_|EXPO_PUBLIC_|REACT_APP_)\w*(PASSWORD|PASSWD|SECRET|TOKEN|API_?KEY|PRIVATE_KEY|ACCESS_KEY)(=|\s+)["']?(?!changeme|change[_-]me|example|your[_-]|placeholder|dummy|xxx|none\b|null\b|true\b|false\b)[^\s"'$<{]{6,}/i;
|
|
35
201
|
export const moreRules = [
|
|
202
|
+
rule({ id: "crypto.static-iv", title: "Encryption with a fixed IV or nonce", status: "gap", severity: "medium", controls: [A04, GDPR("Art. 32", "Security of processing")],
|
|
203
|
+
fix: "Make a new random IV for every message (crypto.randomBytes, os.urandom, SecureRandom) and store it next to the ciphertext. It doesn't need to be secret, only never reused.",
|
|
204
|
+
note: "With the same key and the same IV, two messages can be compared and partly recovered. In AES-GCM a repeated nonce lets an attacker forge messages (CWE-329, CWE-323).",
|
|
205
|
+
extensions: [...CODE, ...NATIVE], test: (l) => STATIC_IV.test(l) && !/^\s*(\/\/|#|\*)/.test(l),
|
|
206
|
+
unlessNear: /randomFill|getRandomValues|randomBytes|rand\.Read|SecureRandom|nextBytes|urandom|secrets\.token/ }),
|
|
207
|
+
rule({ id: "crypto.weak-parameters", title: "Key size or work factor too low", status: "gap", severity: "medium", controls: [A04, GDPR("Art. 32", "Security of processing")],
|
|
208
|
+
fix: "Use RSA keys of 2048 bits or more, bcrypt with 10 rounds or more, and PBKDF2 with the iteration count current guidance gives (600,000 for SHA-256), or switch to Argon2.",
|
|
209
|
+
note: "Short keys can be factored and low work factors make stolen password hashes cheap to crack on ordinary hardware (CWE-326, CWE-916).",
|
|
210
|
+
extensions: [...CODE, ...NATIVE, ".sh", ".bash", ""], test: weakCryptoParameter }),
|
|
211
|
+
rule({ id: "mobile.debuggable-build", title: "Android release build that can be debugged", status: "gap", severity: "medium", controls: [A02, GDPR("Art. 32", "Security of processing")],
|
|
212
|
+
fix: "Remove android:debuggable from the manifest and keep debuggable false in the release build type. The build tools set it for debug builds on their own.",
|
|
213
|
+
note: "A debuggable app lets anyone with the phone attach a debugger, read its private files and change what it does (CWE-489).",
|
|
214
|
+
extensions: [".xml", ".gradle", ".kts"], fileName: /^(AndroidManifest\.xml|build\.gradle(\.kts)?)$/, fileTest: debuggableBuild }),
|
|
215
|
+
rule({ id: "privacy.consent-preticked", title: "Consent box that starts ticked", status: "gap", severity: "medium", controls: [GDPR("Art. 7", "Conditions for consent")],
|
|
216
|
+
fix: "Start the box empty and let the person tick it. Store when they did and the wording they saw.",
|
|
217
|
+
note: "Consent has to be an active choice. A box that is ticked for the person is not consent under the GDPR, so anything sent on that basis has no legal ground (Art. 7, recital 32).",
|
|
218
|
+
extensions: MARKUP, fileTest: consentPreticked,
|
|
219
|
+
unseen: "Lintsure can't tell whether this box is the legal basis for anything. A ticked box for a setting the person already chose earlier is fine." }),
|
|
220
|
+
rule({ id: "privacy.special-category-field", title: "Sensitive category of personal data stored", status: "partial", severity: "medium", controls: [GDPR("Art. 9", "Special categories of personal data")],
|
|
221
|
+
fix: "Check that you need this field at all. If you do, write down the Art. 9 exception you rely on, usually explicit consent, and limit who can read it.",
|
|
222
|
+
note: "Religion, ethnicity, sexual orientation, political views, union membership, health and genetic data may not be processed unless a specific exception applies. Marked Partial: the exception is a decision outside the code.",
|
|
223
|
+
extensions: [...CODE, ".sql", ".prisma"], test: (l) => SPECIAL(l) }),
|
|
224
|
+
rule({ id: "payment.card-code-stored", title: "Card security code stored", status: "gap", severity: "high", controls: [GDPR("Art. 32", "Security of processing"), A02],
|
|
225
|
+
fix: "Never store the card security code. Send the card straight to your payment provider and keep only the token it gives back.",
|
|
226
|
+
note: "The three or four digit code exists to prove the card is in the buyer's hand. Card scheme rules (PCI DSS 3.3.1) forbid keeping it after authorisation, even encrypted, and a leak makes every stored card usable.",
|
|
227
|
+
extensions: [...CODE, ".sql", ".prisma"], test: (l) => CARD_CODE(l) }),
|
|
228
|
+
rule({ id: "cloud.database-public", title: "Database reachable from the internet", status: "gap", severity: "high", controls: [A01, A02],
|
|
229
|
+
fix: "Set publicly_accessible to false, put the database in a private subnet, and reach it through the app, a bastion or a VPN.",
|
|
230
|
+
note: "A database with a public address is one leaked or guessed password away from a full data breach, and it is found by scanners within hours (CWE-284).",
|
|
231
|
+
extensions: [...IAC, ".ts", ".py"], test: (l) => /\bpublicly_accessible\s*=\s*true\b|\bPubliclyAccessible\s*:\s*["']?true\b|\bpubliclyAccessible\s*:\s*true\b|\bpublicly_accessible\s*=\s*True\b/.test(l) && !/^\s*(#|\/\/)/.test(l) }),
|
|
232
|
+
rule({ id: "cloud.network-open", title: "Admin or database port open to the whole internet", status: "gap", severity: "high", controls: [A01, A02],
|
|
233
|
+
fix: "Limit the rule to the addresses that need it (your office, a VPN, a bastion), or remove it and use a session manager.",
|
|
234
|
+
note: "Remote login and database ports that accept connections from 0.0.0.0/0 are scanned and attacked all day (CWE-284).",
|
|
235
|
+
extensions: IAC, fileTest: networkOpen,
|
|
236
|
+
unseen: "Lintsure reads this file only. It can't see a network ACL or a firewall in front that narrows the rule." }),
|
|
237
|
+
rule({ id: "cloud.iam-allow-all", title: "Policy that allows every action on every resource", status: "gap", severity: "high", controls: [A01, A02],
|
|
238
|
+
fix: "List the actions and resources the role really needs. Start from what it calls today and add as you go.",
|
|
239
|
+
note: "Whoever gets this role's credentials, through a leaked key or a compromised service, controls the whole account (CWE-732).",
|
|
240
|
+
extensions: IAC, fileTest: iamAllowAll }),
|
|
241
|
+
rule({ id: "cloud.function-url-no-auth", title: "Function URL that anyone can call", status: "partial", severity: "medium", controls: [A01, A07],
|
|
242
|
+
fix: "Use AWS_IAM as the authorization type, or check a signature or token in the function before doing anything.",
|
|
243
|
+
note: "With authorization set to NONE the function runs for anyone who has the URL. Marked Partial: public webhooks do this on purpose and check a signature in code.",
|
|
244
|
+
extensions: IAC, test: (l) => /\bauthorization_type\s*=\s*"NONE"|\bAuthType\s*:\s*["']?NONE\b/.test(l) && !/^\s*(#|\/\/)/.test(l) }),
|
|
245
|
+
rule({ id: "docker.runs-as-root", title: "Container image that runs as root", status: "partial", severity: "low", controls: [A02],
|
|
246
|
+
fix: "Add a user and switch to it in the last stage, for example `RUN adduser -D app` then `USER app`, or use a base image built to run without root.",
|
|
247
|
+
note: "With no USER line the app runs as root inside the container. A bug that lets someone run code then starts with full rights in the container, which makes breaking out to the host much easier (CWE-250). Marked Partial: the platform may set the user when it starts the container.",
|
|
248
|
+
extensions: [""], fileName: DOCKERFILE, fileTest: dockerRunsAsRoot,
|
|
249
|
+
unseen: "Lintsure can't see a user set at run time (Kubernetes runAsUser, docker run --user) or one the base image already sets." }),
|
|
250
|
+
rule({ id: "docker.image-unpinned", title: "Base image with no fixed version", status: "partial", severity: "low", controls: [A08],
|
|
251
|
+
fix: "Name a version, for example `FROM node:22.11-slim`, and update it on purpose. Pin a digest for anything you ship to others.",
|
|
252
|
+
note: "With no tag, or `latest`, every build can pull a different image, so a broken or tampered release reaches you without any change in your repo (CWE-829).",
|
|
253
|
+
extensions: [""], fileName: DOCKERFILE, fileTest: dockerImageUnpinned }),
|
|
254
|
+
rule({ id: "docker.secret-in-build", title: "Secret given a value in a Dockerfile", status: "gap", severity: "high", controls: [A02, A08],
|
|
255
|
+
fix: "Pass the secret when the container starts (an environment variable or a mounted secret), or use `RUN --mount=type=secret` for build steps. Rotate the value: it is in every image built so far.",
|
|
256
|
+
note: "ENV and ARG values are stored in the image. Anyone who can pull the image, or read its build history, can read the secret (CWE-798).",
|
|
257
|
+
extensions: [""], fileName: DOCKERFILE, test: (l) => BUILD_SECRET.test(l) }),
|
|
258
|
+
rule({ id: "mcp.config-unsafe-server", title: "MCP server run from a moving version or over plain HTTP", status: "partial", severity: "medium", controls: [LLM04, A08],
|
|
259
|
+
fix: "Pin the server to an exact version you have looked at, for example some-server@1.4.2, and update it on purpose. Use https for a remote server.",
|
|
260
|
+
note: "An agent trusts the tools this server offers. With no version, or @latest, the next start can load different code and different tool descriptions than the ones you approved. Over plain HTTP anyone on the network path can change them (OWASP LLM04, CWE-829).",
|
|
261
|
+
extensions: [".json"], pathMatch: AGENT_CONFIG,
|
|
262
|
+
unseen: "Lintsure can't see whether a lockfile or a private registry pins this package somewhere else.",
|
|
263
|
+
fileTest: mcpConfigUnsafe }),
|
|
264
|
+
// The model reads a tool's description before it decides to call the tool, so text there works as an instruction
|
|
265
|
+
// (tool poisoning, first reported for MCP in 2025). Any string in the server file counts: Python tools use the docstring.
|
|
266
|
+
rule({ id: "mcp.tool-description-poisoned", title: "MCP tool description that gives the agent orders", status: "gap", severity: "high", controls: [LLM01, LLM04],
|
|
267
|
+
fix: "Rewrite the description so it only says what the tool does and what it takes. Remove anything that tells the agent to ignore instructions, keep something from the user or read other files, and delete any invisible characters.",
|
|
268
|
+
note: "An agent reads tool descriptions as part of its instructions. A description that says to hide a step, ignore earlier rules or read key files can take over every agent that connects to this server (OWASP LLM01, CWE-1427).", extensions: [...CODE, ".json"],
|
|
269
|
+
unseen: "Lintsure reads this server's source, not the servers it connects to. It can't tell a real attack from a security tool that lists these phrases to detect them.",
|
|
270
|
+
// A scanner that lists these phrases to catch them is not an attack: lines that build a pattern or name an attempt are
|
|
271
|
+
// skipped, and in a JSON manifest only "description" values are read (field test: 6 of 6 new findings were detectors).
|
|
272
|
+
fileTest: (lines) => {
|
|
273
|
+
const code = lines.some((l) => MCP_TOOL.test(l));
|
|
274
|
+
if (!code && !lines.some((l) => /"inputSchema"\s*:/.test(l)))
|
|
275
|
+
return [];
|
|
276
|
+
return lines.flatMap((l, i) => (poisonedDescription(l) && !/^\s*(\/\/|#)/.test(l) && (code || /"description"\s*:/.test(l))
|
|
277
|
+
&& !/re\.compile\(|new RegExp\(|\(\?i\)|\b(attempt|detect\w*|patterns?|injection)\b/i.test(l) ? [i + 1] : []));
|
|
278
|
+
} }),
|
|
36
279
|
rule({ id: "mcp.tool-runs-shell", title: "MCP tool that runs shell commands", status: "partial", severity: "high", controls: [LLM03, A06],
|
|
37
280
|
fix: "Run a fixed program with execFile and an argument list, never a command string. Check every argument against an allow-list, and ask the user before anything that changes files or systems.",
|
|
38
281
|
note: "The agent decides what to pass to this tool, and anything it reads (a web page, an issue, a file) can steer it. If tool input reaches the command, a prompt injection becomes a shell on this machine (CWE-78).", extensions: CODE,
|
|
@@ -56,7 +299,8 @@ export const moreRules = [
|
|
|
56
299
|
fix: "Pass the algorithm you sign with, for example jwt.verify(token, key, { algorithms: [\"RS256\"] }), or algorithms=[\"HS256\"] in PyJWT.",
|
|
57
300
|
note: "Without a fixed list, some library versions accept a token signed with a different algorithm than you meant, for example one signed with your public key (CWE-347).", extensions: CODE,
|
|
58
301
|
confidence: "medium",
|
|
59
|
-
|
|
302
|
+
// Also an options object written on the line that has no algorithms list.
|
|
303
|
+
test: (l) => /\bjwt\.verify\(\s*[^,()]+,\s*[^,()]+\)/.test(l) || /\bjwt\.verify\(\s*[^,()]+,\s*[^,()]+,\s*\{(?![^}]*\balgorithms\b)[^{}]*\}\s*\)/.test(l) || /\bjwt\.decode\(\s*[\w.]+\s*,\s*[\w."']+\s*\)/.test(l) }),
|
|
60
304
|
rule({ id: "jwt.weak-secret", title: "Token signed with a short secret written in the code", status: "gap", severity: "high", controls: [A04, A07],
|
|
61
305
|
fix: "Read the signing key from the environment or a secret store, and make it at least 32 random bytes.",
|
|
62
306
|
note: "Anyone who reads the code, or guesses a short key, can sign their own login tokens (CWE-798, CWE-521).", extensions: CODE,
|
|
@@ -80,13 +324,31 @@ export const moreRules = [
|
|
|
80
324
|
rule({ id: "k8s.privileged", title: "Container runs privileged or shares the host", status: "gap", severity: "high", controls: [A02],
|
|
81
325
|
fix: "Remove privileged, hostNetwork, hostPID and hostIPC, set allowPrivilegeEscalation: false, and run as a non-root user.",
|
|
82
326
|
note: "A privileged container, or one sharing the host's network or processes, can take over the machine it runs on if it is broken into (CWE-250).", extensions: [".yml", ".yaml"],
|
|
83
|
-
|
|
327
|
+
// Also the one-line form, securityContext: {privileged: true}, and Compose's host namespaces.
|
|
328
|
+
test: (l) => /^\s*-?\s*(privileged|allowPrivilegeEscalation|hostNetwork|hostPID|hostIPC)\s*:\s*true\b/.test(l) || /^\s*-?\s*runAsUser\s*:\s*0\s*$/.test(l)
|
|
329
|
+
|| /\bsecurityContext\s*:\s*\{[^}]*\b(privileged|allowPrivilegeEscalation)\s*:\s*true\b/.test(l) || /^\s*(network_mode|pid|ipc)\s*:\s*["']?host["']?\s*(#.*)?$/.test(l)
|
|
330
|
+
// Capabilities that amount to host access, written on one line, and security profiles switched off.
|
|
331
|
+
|| /^\s*-?\s*(cap_add|add)\s*:\s*\[[^\]]*\b(SYS_ADMIN|SYS_PTRACE|SYS_MODULE|ALL)\b/.test(l) || /\b(seccomp|apparmor)[:=]unconfined\b/i.test(l),
|
|
332
|
+
// The same capabilities as list items: the nearest key above must be cap_add or add, never drop.
|
|
333
|
+
fileTest: (lines) => lines.flatMap((l, i) => {
|
|
334
|
+
if (!/^\s*-\s*["']?(SYS_ADMIN|SYS_PTRACE|SYS_MODULE|ALL)["']?\s*(#.*)?$/.test(l))
|
|
335
|
+
return [];
|
|
336
|
+
const key = lines.slice(Math.max(0, i - 6), i).reverse().find((x) => /^\s*-?\s*[\w-]+\s*:\s*(#.*)?$/.test(x)) ?? "";
|
|
337
|
+
return /^\s*-?\s*(cap_add|add)\s*:/.test(key) ? [i + 1] : [];
|
|
338
|
+
}) }),
|
|
84
339
|
rule({ id: "docker.socket-mounted", title: "Docker socket mounted into a container", status: "partial", severity: "high", controls: [A02],
|
|
85
340
|
fix: "Don't mount /var/run/docker.sock. If the container really needs Docker, point it at a separate, locked-down Docker daemon over TLS, or use a rootless or socket-proxy setup that allows only the calls it needs.",
|
|
86
341
|
note: "Whatever runs in the container gets the host's Docker, and with it the whole machine: it can start a privileged container that mounts the host's disk (CWE-250). Mounting it read-only (:ro) doesn't help, because the API still works.", extensions: [".yml", ".yaml", ".json", ".sh", ""],
|
|
87
342
|
unseen: "Lintsure can't tell whether this container is meant to manage Docker (a CI runner or a reverse proxy) or whether the host is a throwaway machine.",
|
|
88
343
|
// A mount, not a client setting: DOCKER_HOST=unix:///var/run/docker.sock only says where to connect.
|
|
89
|
-
|
|
344
|
+
// A socket proxy is the fix this rule asks for: the mount into the proxy itself is not a finding (0.3.14 review, 2 of 2).
|
|
345
|
+
// The service's image is the nearest `image:` line above the mount.
|
|
346
|
+
fileTest: (lines) => lines.flatMap((l, i) => {
|
|
347
|
+
if (!/(?<!unix:\/)\/var\/run\/docker\.sock\b|\/\/\.\/pipe\/docker_engine/.test(l) || /^\s*#|DOCKER_HOST\s*[:=]/.test(l))
|
|
348
|
+
return [];
|
|
349
|
+
const image = lines.slice(Math.max(0, i - 60), i).reverse().find((x) => /^\s*image\s*:/.test(x)) ?? "";
|
|
350
|
+
return /socket-proxy/i.test(image) ? [] : [i + 1];
|
|
351
|
+
}) }),
|
|
90
352
|
rule({ id: "cloud.public-bucket", title: "Storage bucket open to the public", status: "gap", severity: "high", controls: [A01],
|
|
91
353
|
fix: "Keep the bucket private and block public access. Share single files with short-lived signed URLs instead.",
|
|
92
354
|
note: "Anyone on the internet can list or download what's in a public bucket, and with write access, replace it (CWE-284).", extensions: [".tf", ".json", ".yml", ".yaml", ...CODE],
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { Control, Rule } from "../types.js";
|
|
2
|
-
|
|
2
|
+
export declare const AGENT_CONFIG: RegExp;
|
|
3
|
+
/** True when a line carries text hidden from a human reader. Pure. */
|
|
4
|
+
export declare const hiddenText: (l: string) => boolean;
|
|
5
|
+
export declare const poisonedDescription: (l: string) => boolean;
|
|
6
|
+
/** Agent instruction line: Gap for override, concealment, hidden text or sending secrets out; Partial for download-and-run. Pure. */
|
|
3
7
|
export declare function instructionsUnsafe(l: string): boolean | "partial";
|
|
4
8
|
/** True when a signing or encryption secret falls back to a fixed value written in the code. Pure. */
|
|
5
9
|
export declare function fallbackSecret(l: string): boolean;
|