@lintsure/core 0.3.14 → 0.3.16

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.
@@ -1,3 +1,4 @@
1
+ import { AGENT_CONFIG, AGENT_DIRS, AST, 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
- if (/\bverifyClient\b|\borigin\b|\ballowRequest\b|\bnoServer\s*:\s*true/.test(text))
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,329 @@ 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
+ // Files an agent loads as a skill or a command: a SKILL.md anywhere, or a file in an agent's skills, commands or agents folder.
39
+ // AGENTS.md and CLAUDE.md are left out: a project telling its own agent to keep its notes up to date is ordinary.
40
+ const SKILL_FILE = new RegExp(String.raw `(^|\/)SKILL\.md$|(^|\/)${AGENT_DIRS}\/(skills|commands|agents)\/.+\.md$`, "i");
41
+ // A line that forbids the thing describes a guard, it doesn't ask for it.
42
+ const FORBIDDEN = /\b(never|do not|don'?t|must not|avoid|refuse)\b/i;
43
+ // "Follow the instructions at <url>", or "fetch <url> and follow it": what the agent does next is decided by that page.
44
+ const FOLLOW_REMOTE = new RegExp([
45
+ String.raw `\b(follow|obey|execute|carry out|apply|act on|do what)\b[^.\n]{0,60}\b(instructions?|steps|commands?|rules|guidance|prompts?)\b[^.\n]{0,40}\b(at|from|in|on)\s+[<(\x60]?https?:\/\/`,
46
+ String.raw `\b(fetch|download|curl|wget|retrieve|load|read|open|visit|get)\b[^.\n]{0,60}https?:\/\/\S+[^.\n]{0,80}\b(and|then)\s+(follow|execute|run|apply|obey|do what)\b`,
47
+ ].join("|"), "i");
48
+ /** A skill line that sends the agent to a page on the internet for its next instructions. Pure. */
49
+ export const followsRemote = (l) => FOLLOW_REMOTE.test(l) && !FORBIDDEN.test(l) && !/https?:\/\/(localhost|127\.|\[::1\])/i.test(l);
50
+ // The files an agent reads as its own standing instructions or settings.
51
+ const MEMORY_FILE = String.raw `(AGENTS\.md|CLAUDE\.md|GEMINI\.md|SOUL\.md|MEMORY\.md|\.cursorrules|\.windsurfrules|copilot-instructions\.md|\.claude\/settings(\.local)?\.json)`;
52
+ const WRITES_MEMORY = new RegExp(String.raw `\b(append|add|adds|write|writes|insert|modify|update|edit|overwrite|save|persist|put)\b[^.\n]{0,70}\b(to|into|in)\s+[\x60"'*]*(the\s+|your\s+)?[\x60"'*]*(?:[\w~.-]+\/)*` + MEMORY_FILE, "i");
53
+ /** A skill line that has the agent change its own standing instructions or settings. Pure. */
54
+ export const writesMemory = (l) => WRITES_MEMORY.test(l) && !FORBIDDEN.test(l);
55
+ // Front matter that hands a skill the whole shell: Bash with no command limit, every tool, or shell: true.
56
+ const OPEN_SHELL = /^\s*allowed[-_]tools\s*:.*(?<![\w-])Bash(?!\s*\()(?![\w-])|^\s*allowed[-_]tools\s*:\s*["']?\*["']?\s*$|^\s*shell\s*:\s*true\b/i;
57
+ // A server told to listen on every network interface.
58
+ // A list of allowed values in a type ("127.0.0.1" | "0.0.0.0") names the address without listening on it.
59
+ // The address must be what the server listens on: a listen call, or a host or bind setting. In a list of address
60
+ // ranges to refuse it is the opposite of a risk (check on the reference MCP servers: 1 of 1 was such a list).
61
+ const ALL_INTERFACES = { test: (l) => /(\blisten\s*\(|\bhost(name)?\s*[:=]|\bbind\w*\s*[:=(]|--host\b)[^\n]*["'\x60]0\.0\.0\.0["'\x60]/i.test(l) && !/["'\x60]\s*\|\s*["'\x60]/.test(l) };
62
+ /** MCP config: a server run from a version that can change after you approved it (Partial), or reached over plain HTTP (Gap). Pure.
63
+ * shortcut: reads npx-style args only ("-y", "pkg"); add uvx and docker image tags when a field test shows them. */
64
+ export function mcpConfigUnsafe(lines) {
65
+ if (!lines.some((l) => /"(mcpServers|servers|context_servers)"\s*:/.test(l)))
66
+ return [];
67
+ const out = [];
68
+ lines.forEach((l, i) => {
69
+ if (/"(url|serverUrl|endpoint)"\s*:\s*"http:\/\/(?!localhost|127\.0\.0\.1|\[::1\]|0\.0\.0\.0|host\.docker\.internal)/.test(l)) {
70
+ out.push({ line: i + 1, status: "gap" });
71
+ return;
72
+ }
73
+ if (/@latest"/.test(l)) {
74
+ out.push({ line: i + 1, status: "partial" });
75
+ return;
76
+ }
77
+ const yes = /"(-y|--yes)"\s*,?\s*(.*)$/.exec(l);
78
+ if (!yes)
79
+ return;
80
+ const same = /^"([^"]+)"/.exec(yes[2].trim()), next = /^\s*"([^"]+)"/.exec(lines[i + 1] ?? "");
81
+ const pkg = same?.[1] ?? next?.[1];
82
+ if (pkg && /^(@[\w.-]+\/)?[\w.-]+$/.test(pkg))
83
+ out.push({ line: same ? i + 1 : i + 2, status: "partial" });
84
+ });
85
+ return out;
86
+ }
87
+ const DOCKERFILE = /^(Dockerfile|Containerfile)|\.Dockerfile$/i;
88
+ const NATIVE = [".java", ".kt", ".swift", ".go", ".dart"];
89
+ // An IV or nonce that is the same for every message: zero bytes or fixed text. Reusing one with the same key breaks
90
+ // AES-GCM outright and leaks patterns in CBC. A buffer that is filled with random bytes on the next lines is fine (unlessNear).
91
+ 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\("[^"]+"\)/;
92
+ /** Key sizes and work factors below what current guidance accepts. Pure. */
93
+ export function weakCryptoParameter(l) {
94
+ // PBKDF2 is also used to derive cache keys and ids, where the round count doesn't matter: Gap only when a password is named.
95
+ const kdf = () => (/pass(word|wd|phrase)?/i.test(l) ? true : "partial");
96
+ if (/^\s*(\/\/|#|\*)/.test(l))
97
+ return false;
98
+ // PBKDF2 under 10,000 rounds (OWASP asks for 600,000 with SHA-256; a four-digit count is far off any guidance).
99
+ 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))
100
+ return kdf();
101
+ if (/\bPBKDF2\w*\(/.test(l) && /\biterations\s*=\s*\d{1,4}\s*[,)]/.test(l))
102
+ return kdf();
103
+ // bcrypt below 10 rounds.
104
+ if (/\bbcrypt\.(hash|hashSync|genSalt|genSaltSync)\(\s*(?:[^,()]+,\s*)?[1-9]\s*[,)]|\bgensalt\(\s*(?:rounds\s*=\s*)?[1-9]\s*\)/.test(l))
105
+ return true;
106
+ // RSA keys under 2048 bits.
107
+ 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);
108
+ }
109
+ /** Android release build that can be debugged: the manifest flag, or `debuggable true` inside the release block of build.gradle. Pure. */
110
+ export function debuggableBuild(lines) {
111
+ return lines.flatMap((l, i) => {
112
+ if (/android:debuggable\s*=\s*"true"/.test(l))
113
+ return [i + 1];
114
+ if (!/\b(isDebuggable\s*=\s*true|debuggable\s+true|debuggable\s*=\s*true)\b/.test(l))
115
+ return [];
116
+ 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)) ?? "";
117
+ return /release/.test(block) ? [i + 1] : [];
118
+ });
119
+ }
120
+ const GDPR = (id, title) => ({ framework: "gdpr", id, title });
121
+ /** A line that declares a stored field with one of these names: SQL column, Prisma, Mongoose, Sequelize, TypeORM, Django,
122
+ * SQLAlchemy. A TypeScript type (`cvv: string`) describes a form value, not storage, so it doesn't count. Pure. */
123
+ export function storedField(names) {
124
+ 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");
125
+ 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));
126
+ }
127
+ const CARD_CODE = storedField("cvv2?|cvc2?|card_?security_?code|card_?verification_?(code|value)");
128
+ const SPECIAL = storedField("religion|religious_?belief|ethnicity|ethnic_?origin|sexual_?orientation|political_?(affiliation|opinion|party)|trade_?union(_?membership)?|hiv_?status|genetic_?data");
129
+ const CONSENT_WORD = /consent|marketing|newsletter|subscribe|opt[-_ ]?in|promotional/i;
130
+ /** A consent or marketing checkbox that starts ticked, or its state that starts as true. Pure. */
131
+ export function consentPreticked(lines) {
132
+ return lines.flatMap((l, i) => {
133
+ // State that starts true for a consent value; a flag that only shows the banner is not consent.
134
+ const st = /\[\s*(\w+)\s*,\s*set\w+\s*\]\s*=\s*useState(<[^>]*>)?\(\s*true\s*\)/.exec(l);
135
+ if (st && CONSENT_WORD.test(st[1]) && !/show|open|visible|banner|modal|dialog|loading|seen/i.test(st[1]))
136
+ return [i + 1];
137
+ // `checked={value}` is controlled state; only a bare attribute or a literal true pre-ticks the box.
138
+ const attrs = l.replace(/\b(defaultChecked|checked)\s*=\s*\{(?!\s*true\s*\})[^}]*\}/g, "");
139
+ // A variable or arrow parameter named `checked` (`const checked = ...`, `checked => ...`) is code, not the attribute.
140
+ 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))
141
+ return [];
142
+ const near = lines.slice(Math.max(0, i - 4), i + 5).join("\n");
143
+ return /type\s*=\s*["']checkbox["']|<Checkbox\b/.test(near) && CONSENT_WORD.test(near) ? [i + 1] : [];
144
+ });
145
+ }
146
+ const IAC = [".tf", ".json", ".yml", ".yaml"];
147
+ // Ports that should never face the internet: remote login, databases, caches, search and the Docker API.
148
+ const ADMIN_PORTS = [22, 23, 3389, 5900, 1433, 1521, 3306, 5432, 6379, 9200, 9300, 11211, 27017, 5984, 2375, 2376];
149
+ 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)"/;
150
+ /** A firewall rule that lets the whole internet reach an admin or database port. Reads the block around the open range:
151
+ * inbound only, and only when the ports are written there. Pure.
152
+ * shortcut: reads up to 10 lines either side of the range, not the parsed block; parse HCL if rules get longer. */
153
+ export function networkOpen(lines) {
154
+ return lines.flatMap((l, i) => {
155
+ if (!OPEN_CIDR.test(l) || /^\s*(#|\/\/)/.test(l))
156
+ return [];
157
+ const head = /^\s*(ingress|egress|resource|rule|allow|deny|security_rule|-\s*IpProtocol|SecurityGroup(Ingress|Egress))\b/;
158
+ let a = i, b = i;
159
+ while (a > 0 && i - a < 10 && !head.test(lines[a]))
160
+ a--;
161
+ while (b < lines.length - 1 && b - i < 10 && !/^\s*\}\s*$/.test(lines[b]) && !(b > i && head.test(lines[b + 1])))
162
+ b++;
163
+ const block = lines.slice(a, b + 1).join("\n");
164
+ if (/^\s*egress\b|SecurityGroupEgress|type\s*=\s*"egress"|direction\s*=\s*"(Outbound|EGRESS)"/im.test(block))
165
+ return [];
166
+ if (/protocol\s*=\s*"(-1|all)"|IpProtocol\s*:\s*["']?-1/.test(block))
167
+ return [i + 1];
168
+ const n = (re) => { const m = re.exec(block); return m ? Number(m[1]) : null; };
169
+ const lo = n(/\b(?:from_port|FromPort)\s*[=:]\s*"?(\d+)/), hi = n(/\b(?:to_port|ToPort)\s*[=:]\s*"?(\d+)/);
170
+ 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])));
171
+ if (lo !== null && ADMIN_PORTS.some((p) => p >= lo && p <= (hi ?? lo)))
172
+ return [i + 1];
173
+ return single.some((p) => ADMIN_PORTS.includes(p)) ? [i + 1] : [];
174
+ });
175
+ }
176
+ /** A policy statement that allows every action on every resource. A Deny statement with the same wildcards is a guard. Pure. */
177
+ export function iamAllowAll(lines) {
178
+ return lines.flatMap((l, i) => {
179
+ if (!/"?\bAction"?\s*[:=]\s*\[?\s*["']\*["']|\bactions\s*=\s*\[\s*"\*"\s*\]/.test(l))
180
+ return [];
181
+ const near = lines.slice(Math.max(0, i - 6), i + 7).join("\n");
182
+ return /"?\bResource"?\s*[:=]\s*\[?\s*["']\*["']|\bresources\s*=\s*\[\s*"\*"\s*\]/.test(near) && !/\bEffect"?\s*[:=]\s*["']Deny["']/i.test(near) ? [i + 1] : [];
183
+ });
184
+ }
185
+ // `from x import y` inside a RUN python block is not a FROM instruction.
186
+ const from = (l) => (/\bimport\b/.test(l) ? null : /^\s*FROM\s+(?:--\S+\s+)*(\S+)(?:\s+AS\s+(\S+))?/i.exec(l));
187
+ // Official server images start as root and drop to their own user in the entrypoint.
188
+ const DROPS_ROOT = /^(docker\.io\/)?(library\/)?(mysql|mariadb|postgres|redis|mongo|rabbitmq|memcached|elasticsearch|influxdb|grafana\/grafana|clickhouse\/clickhouse-server)(:|@|$)/i;
189
+ /** Dockerfile whose last stage never switches away from root: the last FROM line, or its `USER root` line. Pure. */
190
+ export function dockerRunsAsRoot(lines) {
191
+ let last = -1;
192
+ lines.forEach((l, i) => { if (from(l))
193
+ last = i; });
194
+ if (last < 0)
195
+ return [];
196
+ // Images built to run without root, and `scratch` (nothing to switch to), are left alone.
197
+ if (/nonroot|rootless|unprivileged|chainguard|\bscratch\b/i.test(from(lines[last])[1]) || DROPS_ROOT.test(from(lines[last])[1]))
198
+ return [];
199
+ const users = lines.map((l, i) => [i, /^\s*USER\s+(\S+)/i.exec(l)?.[1]]).filter(([i, u]) => i > last && u);
200
+ if (!users.length)
201
+ return [last + 1];
202
+ const [line, user] = users[users.length - 1];
203
+ return /^(root|0)(:|$)/.test(user) ? [line + 1] : [];
204
+ }
205
+ /** 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. */
206
+ export function dockerImageUnpinned(lines) {
207
+ const stages = new Set();
208
+ return lines.flatMap((l, i) => {
209
+ const m = from(l);
210
+ if (!m)
211
+ return [];
212
+ const image = m[1];
213
+ if (m[2])
214
+ stages.add(m[2].toLowerCase());
215
+ if (stages.has(image.toLowerCase()) && image.toLowerCase() !== m[2]?.toLowerCase())
216
+ return [];
217
+ if (image === "scratch" || image.includes("$") || image.includes("@sha256:"))
218
+ return [];
219
+ const tag = /:([^/:]+)$/.exec(image)?.[1];
220
+ return !tag || tag === "latest" ? [i + 1] : [];
221
+ });
222
+ }
223
+ // A secret given a value at build time stays in the image's layers and history for anyone who pulls it.
224
+ 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
225
  export const moreRules = [
226
+ 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")],
227
+ 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.",
228
+ 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).",
229
+ extensions: [...CODE, ...NATIVE], test: (l) => STATIC_IV.test(l) && !/^\s*(\/\/|#|\*)/.test(l),
230
+ unlessNear: /randomFill|getRandomValues|randomBytes|rand\.Read|SecureRandom|nextBytes|urandom|secrets\.token/ }),
231
+ 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")],
232
+ 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.",
233
+ note: "Short keys can be factored and low work factors make stolen password hashes cheap to crack on ordinary hardware (CWE-326, CWE-916).",
234
+ extensions: [...CODE, ...NATIVE, ".sh", ".bash", ""], test: weakCryptoParameter }),
235
+ 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")],
236
+ 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.",
237
+ note: "A debuggable app lets anyone with the phone attach a debugger, read its private files and change what it does (CWE-489).",
238
+ extensions: [".xml", ".gradle", ".kts"], fileName: /^(AndroidManifest\.xml|build\.gradle(\.kts)?)$/, fileTest: debuggableBuild }),
239
+ rule({ id: "privacy.consent-preticked", title: "Consent box that starts ticked", status: "gap", severity: "medium", controls: [GDPR("Art. 7", "Conditions for consent")],
240
+ fix: "Start the box empty and let the person tick it. Store when they did and the wording they saw.",
241
+ 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).",
242
+ extensions: MARKUP, fileTest: consentPreticked,
243
+ 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." }),
244
+ 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")],
245
+ 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.",
246
+ 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.",
247
+ extensions: [...CODE, ".sql", ".prisma"], test: (l) => SPECIAL(l) }),
248
+ rule({ id: "payment.card-code-stored", title: "Card security code stored", status: "gap", severity: "high", controls: [GDPR("Art. 32", "Security of processing"), A02],
249
+ fix: "Never store the card security code. Send the card straight to your payment provider and keep only the token it gives back.",
250
+ 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.",
251
+ extensions: [...CODE, ".sql", ".prisma"], test: (l) => CARD_CODE(l) }),
252
+ rule({ id: "cloud.database-public", title: "Database reachable from the internet", status: "gap", severity: "high", controls: [A01, A02],
253
+ fix: "Set publicly_accessible to false, put the database in a private subnet, and reach it through the app, a bastion or a VPN.",
254
+ 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).",
255
+ 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) }),
256
+ rule({ id: "cloud.network-open", title: "Admin or database port open to the whole internet", status: "gap", severity: "high", controls: [A01, A02],
257
+ fix: "Limit the rule to the addresses that need it (your office, a VPN, a bastion), or remove it and use a session manager.",
258
+ note: "Remote login and database ports that accept connections from 0.0.0.0/0 are scanned and attacked all day (CWE-284).",
259
+ extensions: IAC, fileTest: networkOpen,
260
+ unseen: "Lintsure reads this file only. It can't see a network ACL or a firewall in front that narrows the rule." }),
261
+ rule({ id: "cloud.iam-allow-all", title: "Policy that allows every action on every resource", status: "gap", severity: "high", controls: [A01, A02],
262
+ fix: "List the actions and resources the role really needs. Start from what it calls today and add as you go.",
263
+ note: "Whoever gets this role's credentials, through a leaked key or a compromised service, controls the whole account (CWE-732).",
264
+ extensions: IAC, fileTest: iamAllowAll }),
265
+ rule({ id: "cloud.function-url-no-auth", title: "Function URL that anyone can call", status: "partial", severity: "medium", controls: [A01, A07],
266
+ fix: "Use AWS_IAM as the authorization type, or check a signature or token in the function before doing anything.",
267
+ 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.",
268
+ extensions: IAC, test: (l) => /\bauthorization_type\s*=\s*"NONE"|\bAuthType\s*:\s*["']?NONE\b/.test(l) && !/^\s*(#|\/\/)/.test(l) }),
269
+ rule({ id: "docker.runs-as-root", title: "Container image that runs as root", status: "partial", severity: "low", controls: [A02],
270
+ 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.",
271
+ 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.",
272
+ extensions: [""], fileName: DOCKERFILE, fileTest: dockerRunsAsRoot,
273
+ unseen: "Lintsure can't see a user set at run time (Kubernetes runAsUser, docker run --user) or one the base image already sets." }),
274
+ rule({ id: "docker.image-unpinned", title: "Base image with no fixed version", status: "partial", severity: "low", controls: [A08],
275
+ 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.",
276
+ 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).",
277
+ extensions: [""], fileName: DOCKERFILE, fileTest: dockerImageUnpinned }),
278
+ // `COPY . .` takes everything the build can see: .env files, the .git folder, and the folders coding agents keep their
279
+ // settings and notes in. A firewall rule set we studied blocks requests for those folders because they get deployed
280
+ // by accident this way. Reported once per Dockerfile, and only when no .dockerignore keeps .env out.
281
+ rule({ id: "docker.copies-everything", title: "Whole project copied into the image with nothing kept out", status: "partial", severity: "low", controls: [A02, A08],
282
+ fix: "Add a .dockerignore next to the Dockerfile that lists .env files, .git and agent folders such as .claude and .cursor, or copy only the folders the app needs.",
283
+ note: "Whatever is copied stays in the image, where anyone who can pull it can read it. Local settings, keys in .env, git history and an agent's notes about the project are not meant to ship (CWE-538).",
284
+ unseen: "Lintsure looked for a .dockerignore that mentions .env. It can't see what is on the build machine, or a build context that is narrower than the project.",
285
+ extensions: [""], fileName: DOCKERFILE, sharedFiles: /(^|\/)\.dockerignore$/,
286
+ fileTest: (lines, _shared, files = {}) => {
287
+ if (Object.values(files).some((t) => /^\s*(\*\*\/)?\.env\b/m.test(t)))
288
+ return [];
289
+ const i = lines.findIndex((l) => /^\s*(COPY|ADD)\s+(--\S+\s+)*\.\/?\s+\S/i.test(l));
290
+ return i < 0 ? [] : [i + 1];
291
+ } }),
292
+ // A memory layer keeps what users tell an agent, across sessions. That is personal data with a long life, and people
293
+ // have the right to have it removed. A file that only ever adds to memory is where that right usually gets lost.
294
+ rule({ id: "privacy.memory-no-delete", title: "Agent memory that is written but never deleted", status: "partial", severity: "low", controls: [GDPR("Art. 17", "Right to erasure"), GDPR("Art. 5(1)(e)", "Storage limitation")],
295
+ fix: "Give users a way to see and delete what the agent remembers about them, and set how long memories are kept. Most memory libraries have a delete call per user: wire it to account deletion.",
296
+ note: "Memories are built from what people say, so they hold names, contacts, health and other personal details. Kept for good with no delete path, they can't be removed when a user asks or leaves (GDPR Art. 17).",
297
+ unseen: "Lintsure looked in this file only. A delete call may live in another file, or the memory service may expire entries by itself.",
298
+ extensions: CODE,
299
+ fileTest: (lines) => {
300
+ const text = lines.join("\n");
301
+ if (!/\b(mem0|mem0ai|zep_cloud|zep_python|langmem|letta)\b|@mem0\/|@getzep\//.test(text) || /\.(delete|delete_all|delete_memory|delete_user|forget|reset)\s*\(|\bttl\b|expir/i.test(text))
302
+ return [];
303
+ // The call must be on the memory object or name whose memory it is: `updated_keys.add(x)` is a set (field check).
304
+ const i = lines.findIndex((l) => /\b\w*(mem|zep|letta)\w*(\.\w+)*\.(add|add_memory|aadd)\s*\(|\.save_context\s*\(|\.(add|aadd)\s*\([^)]*\b(user_?id|session_?id|agent_?id)\b/i.test(l) && !/^\s*(\/\/|#)/.test(l));
305
+ return i < 0 ? [] : [i + 1];
306
+ } }),
307
+ rule({ id: "docker.secret-in-build", title: "Secret given a value in a Dockerfile", status: "gap", severity: "high", controls: [A02, A08],
308
+ 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.",
309
+ 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).",
310
+ extensions: [""], fileName: DOCKERFILE, test: (l) => BUILD_SECRET.test(l) }),
311
+ 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, AST("02", "Supply Chain Compromise"), AST("07", "Update Drift")],
312
+ 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.",
313
+ 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).",
314
+ extensions: [".json"], pathMatch: AGENT_CONFIG,
315
+ unseen: "Lintsure can't see whether a lockfile or a private registry pins this package somewhere else.",
316
+ fileTest: mcpConfigUnsafe }),
317
+ // The model reads a tool's description before it decides to call the tool, so text there works as an instruction
318
+ // (tool poisoning, first reported for MCP in 2025). Any string in the server file counts: Python tools use the docstring.
319
+ rule({ id: "mcp.tool-description-poisoned", title: "MCP tool description that gives the agent orders", status: "gap", severity: "high", controls: [LLM01, LLM04],
320
+ 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.",
321
+ 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"],
322
+ 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.",
323
+ // A scanner that lists these phrases to catch them is not an attack: lines that build a pattern or name an attempt are
324
+ // skipped, and in a JSON manifest only "description" values are read (field test: 6 of 6 new findings were detectors).
325
+ fileTest: (lines) => {
326
+ // A JSON file is data: only its "description" values are read, even when it quotes code that registers a tool.
327
+ const code = !/^\s*[\[{]/.test(lines.find((l) => l.trim()) ?? "") && lines.some((l) => MCP_TOOL.test(l));
328
+ if (!code && !lines.some((l) => /"inputSchema"\s*:/.test(l)))
329
+ return [];
330
+ return lines.flatMap((l, i) => (poisonedDescription(l) && !/^\s*(\/\/|#)/.test(l) && (code || /"description"\s*:/.test(l))
331
+ && !/re\.compile\(|new RegExp\(|\(\?i\)|\b(attempt|detect\w*|patterns?|injection)\b/i.test(l) ? [i + 1] : []));
332
+ } }),
333
+ // Skills are prose an agent follows. These three read a skill the way a reviewer would: where its next instructions
334
+ // come from, whether it rewrites the agent's own standing instructions, and how much of the machine it asks for.
335
+ rule({ id: "skill.fetches-remote-instructions", title: "Skill tells the agent to follow a page on the internet", status: "partial", severity: "medium", controls: [AST("05", "Untrusted External Instructions"), LLM01],
336
+ fix: "Put the steps in the skill itself, or keep a reviewed copy in the repo and point to that. If the page must be fetched, tell the agent to treat it as reference text and to ask before acting on it.",
337
+ note: "The skill was reviewed once, but the page can change at any time, and whoever controls it then decides what the agent does with your permissions (CWE-829).",
338
+ extensions: [".md", ".mdc"], pathMatch: SKILL_FILE,
339
+ unseen: "Lintsure can't see what the page says today or who controls it, and it can't tell reference reading from instructions the agent will act on.",
340
+ test: followsRemote }),
341
+ rule({ id: "skill.writes-agent-memory", title: "Skill changes the agent's own instructions or settings", status: "partial", severity: "medium", controls: [AST("01", "Malicious Skills"), AST("03", "Over-Privileged Skills")],
342
+ fix: "Have the skill show the change and ask the user before writing to these files. If writing them is not the skill's stated job, remove the line.",
343
+ note: "AGENTS.md, CLAUDE.md, memory files and agent settings are read at the start of every later session. A skill that writes to them keeps its influence after it has finished, and can loosen limits for everything that follows.",
344
+ extensions: [".md", ".mdc"], pathMatch: SKILL_FILE,
345
+ unseen: "Lintsure can't tell a skill whose stated job is to manage these files, with the user's agreement, from one that changes them on the quiet.",
346
+ test: writesMemory }),
347
+ rule({ id: "skill.unrestricted-shell", title: "Skill is allowed any shell command", status: "partial", severity: "low", controls: [AST("03", "Over-Privileged Skills"), LLM03],
348
+ fix: "List the commands the skill needs, for example `Bash(npm run test:*)`, and leave the rest to the agent's normal permission prompts.",
349
+ note: "With the whole shell allowed, the skill's other limits mean little: any file can be read or changed and anything can be sent out through a command. One poisoned input to the skill then reaches the whole machine.",
350
+ extensions: [".md", ".mdc"], pathMatch: SKILL_FILE,
351
+ unlessPath: /(^|\/)evals?\//, // an eval's own settings file sits in the skill folder and is not a skill
352
+ // shortcut: reads allowed-tools on one line; a YAML list spread over several lines is not read. Upgrade when one is seen in the field.
353
+ unseen: "Lintsure can't see the agent's own settings, which may still ask before each command.",
354
+ test: (l) => OPEN_SHELL.test(l) }),
355
+ rule({ id: "mcp.server-binds-all-interfaces", title: "MCP server listens on every network interface", status: "partial", severity: "medium", controls: [AST("06", "Weak Isolation"), A02],
356
+ fix: "Listen on 127.0.0.1 unless other machines must reach the server. If they must, require sign-in on every request and put it behind a firewall.",
357
+ note: "An agent's tool server usually runs on a developer's machine. On 0.0.0.0, anyone on the same network can call its tools, which often read files and run commands (CWE-1327).", extensions: CODE,
358
+ unseen: "Lintsure can't see a firewall, a container network or sign-in in front of this server.",
359
+ fileTest: (lines) => inMcpServer(lines, ALL_INTERFACES) }),
36
360
  rule({ id: "mcp.tool-runs-shell", title: "MCP tool that runs shell commands", status: "partial", severity: "high", controls: [LLM03, A06],
37
361
  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
362
  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 +380,8 @@ export const moreRules = [
56
380
  fix: "Pass the algorithm you sign with, for example jwt.verify(token, key, { algorithms: [\"RS256\"] }), or algorithms=[\"HS256\"] in PyJWT.",
57
381
  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
382
  confidence: "medium",
59
- test: (l) => /\bjwt\.verify\(\s*[^,()]+,\s*[^,()]+\)/.test(l) || /\bjwt\.decode\(\s*[\w.]+\s*,\s*[\w."']+\s*\)/.test(l) }),
383
+ // Also an options object written on the line that has no algorithms list.
384
+ 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
385
  rule({ id: "jwt.weak-secret", title: "Token signed with a short secret written in the code", status: "gap", severity: "high", controls: [A04, A07],
61
386
  fix: "Read the signing key from the environment or a secret store, and make it at least 32 random bytes.",
62
387
  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 +405,31 @@ export const moreRules = [
80
405
  rule({ id: "k8s.privileged", title: "Container runs privileged or shares the host", status: "gap", severity: "high", controls: [A02],
81
406
  fix: "Remove privileged, hostNetwork, hostPID and hostIPC, set allowPrivilegeEscalation: false, and run as a non-root user.",
82
407
  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
- test: (l) => /^\s*-?\s*(privileged|allowPrivilegeEscalation|hostNetwork|hostPID|hostIPC)\s*:\s*true\b/.test(l) || /^\s*-?\s*runAsUser\s*:\s*0\s*$/.test(l) }),
408
+ // Also the one-line form, securityContext: {privileged: true}, and Compose's host namespaces.
409
+ test: (l) => /^\s*-?\s*(privileged|allowPrivilegeEscalation|hostNetwork|hostPID|hostIPC)\s*:\s*true\b/.test(l) || /^\s*-?\s*runAsUser\s*:\s*0\s*$/.test(l)
410
+ || /\bsecurityContext\s*:\s*\{[^}]*\b(privileged|allowPrivilegeEscalation)\s*:\s*true\b/.test(l) || /^\s*(network_mode|pid|ipc)\s*:\s*["']?host["']?\s*(#.*)?$/.test(l)
411
+ // Capabilities that amount to host access, written on one line, and security profiles switched off.
412
+ || /^\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),
413
+ // The same capabilities as list items: the nearest key above must be cap_add or add, never drop.
414
+ fileTest: (lines) => lines.flatMap((l, i) => {
415
+ if (!/^\s*-\s*["']?(SYS_ADMIN|SYS_PTRACE|SYS_MODULE|ALL)["']?\s*(#.*)?$/.test(l))
416
+ return [];
417
+ const key = lines.slice(Math.max(0, i - 6), i).reverse().find((x) => /^\s*-?\s*[\w-]+\s*:\s*(#.*)?$/.test(x)) ?? "";
418
+ return /^\s*-?\s*(cap_add|add)\s*:/.test(key) ? [i + 1] : [];
419
+ }) }),
84
420
  rule({ id: "docker.socket-mounted", title: "Docker socket mounted into a container", status: "partial", severity: "high", controls: [A02],
85
421
  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
422
  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
423
  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
424
  // A mount, not a client setting: DOCKER_HOST=unix:///var/run/docker.sock only says where to connect.
89
- test: (l) => /(?<!unix:\/)\/var\/run\/docker\.sock\b|\/\/\.\/pipe\/docker_engine/.test(l) && !/^\s*#|DOCKER_HOST\s*[:=]/.test(l) }),
425
+ // 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).
426
+ // The service's image is the nearest `image:` line above the mount.
427
+ fileTest: (lines) => lines.flatMap((l, i) => {
428
+ if (!/(?<!unix:\/)\/var\/run\/docker\.sock\b|\/\/\.\/pipe\/docker_engine/.test(l) || /^\s*#|DOCKER_HOST\s*[:=]/.test(l))
429
+ return [];
430
+ const image = lines.slice(Math.max(0, i - 60), i).reverse().find((x) => /^\s*image\s*:/.test(x)) ?? "";
431
+ return /socket-proxy/i.test(image) ? [] : [i + 1];
432
+ }) }),
90
433
  rule({ id: "cloud.public-bucket", title: "Storage bucket open to the public", status: "gap", severity: "high", controls: [A01],
91
434
  fix: "Keep the bucket private and block public access. Share single files with short-lived signed URLs instead.",
92
435
  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,6 +1,17 @@
1
1
  import type { Control, Rule } from "../types.js";
2
- /** Agent instruction line: Gap for override, concealment or sending secrets out; Partial for download-and-run. Pure. */
2
+ export declare const AGENT_CONFIG: RegExp;
3
+ export declare const AGENT_DIRS: string;
4
+ export declare const AGENT_INSTRUCTIONS: RegExp;
5
+ /** True when a line carries text hidden from a human reader. Pure. */
6
+ export declare const hiddenText: (l: string) => boolean;
7
+ export declare const poisonedDescription: (l: string) => boolean;
8
+ /** A YAML permissions file whose allow list names the whole shell or every tool (Continue's permissions.yaml). Only items
9
+ * under "allow:" count: the same entry under "ask:" or "exclude:" is a limit. Returns line numbers. Pure. */
10
+ export declare function yamlAllowsAll(lines: string[]): number[];
11
+ /** Agent instruction line: Gap for override, concealment, hidden text or sending secrets out; Partial for download-and-run. Pure. */
3
12
  export declare function instructionsUnsafe(l: string): boolean | "partial";
13
+ /** A risk in the OWASP list for agent skills. Ids and names only. */
14
+ export declare const AST: (n: string, title: string) => Control;
4
15
  /** True when a signing or encryption secret falls back to a fixed value written in the code. Pure. */
5
16
  export declare function fallbackSecret(l: string): boolean;
6
17
  export declare const owaspRules: Rule[];