@andesyte-oss/security-rules 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Foundation Machines Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # @andesyte-oss/security-rules
2
+
3
+ Curated Semgrep security rules for AI-integrated applications, shipped as
4
+ packaged files.
5
+
6
+ Rules are **never downloaded at runtime**. Semgrep is never invoked with
7
+ `--config auto`, which would contact the rule registry.
8
+
9
+ ## Coverage
10
+
11
+ Six rule packs mapped to the OWASP LLM Top 10:
12
+
13
+ | Pack | Focus |
14
+ |------|-------|
15
+ | `prompt-injection.yml` | Untrusted input spliced into prompts |
16
+ | `insecure-output-handling.yml` | Model output reaching `eval`, `innerHTML`, shell |
17
+ | `model-dos.yml` | Missing token caps, unbounded agent loops |
18
+ | `sensitive-info-disclosure.yml` | Secrets in prompts, full-request logging |
19
+ | `insecure-plugin-design.yml` | Tools running shells or fetching arbitrary URLs |
20
+ | `excessive-agency.yml` | Destructive tools without confirmation |
21
+
22
+ ## Usage
23
+
24
+ ```ts
25
+ import { rulePaths, rulesDir, RULESET_NAME } from "@andesyte-oss/security-rules";
26
+ ```
27
+
28
+ Or directly with Semgrep:
29
+
30
+ ```bash
31
+ semgrep scan --config node_modules/@andesyte-oss/security-rules/rules
32
+ ```
33
+
34
+ ## Source of truth
35
+
36
+ Rules are maintained in
37
+ [`andesyte-oss/semgrep-ai-security`](https://github.com/andesyte-oss/semgrep-ai-security)
38
+ and synchronised here with checksum verification (`rules.lock.json`).
39
+
40
+ ## License
41
+
42
+ MIT
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Rules ship as files inside this package. They are never downloaded at
3
+ * runtime and Semgrep is never invoked with `--config auto`, so a scan makes
4
+ * no network request to any rule registry.
5
+ */
6
+ export declare function rulesDir(): string;
7
+ export declare function rulePaths(): string[];
8
+ export declare const RULESET_NAME = "andesyte-local";
9
+ export declare const RULESET_VERSION = "0.1.0";
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ import { existsSync, readdirSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ const here = dirname(fileURLToPath(import.meta.url));
5
+ /**
6
+ * Rules ship as files inside this package. They are never downloaded at
7
+ * runtime and Semgrep is never invoked with `--config auto`, so a scan makes
8
+ * no network request to any rule registry.
9
+ */
10
+ export function rulesDir() {
11
+ // dist/index.js -> package root -> rules
12
+ const candidates = [join(here, "..", "rules"), join(here, "rules")];
13
+ for (const c of candidates) {
14
+ if (existsSync(c))
15
+ return c;
16
+ }
17
+ throw new Error("packaged rules directory not found");
18
+ }
19
+ export function rulePaths() {
20
+ const dir = rulesDir();
21
+ return readdirSync(dir)
22
+ .filter((f) => f.endsWith(".yml") || f.endsWith(".yaml"))
23
+ .sort()
24
+ .map((f) => join(dir, f));
25
+ }
26
+ export const RULESET_NAME = "andesyte-local";
27
+ export const RULESET_VERSION = "0.1.0";
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@andesyte-oss/security-rules",
3
+ "version": "0.1.0",
4
+ "description": "Andesyte curated Semgrep security rules, shipped as packaged local files (no registry fetch).",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "engines": { "node": ">=20.11" },
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": { "types": "./dist/index.d.ts", "default": "./dist/index.js" },
12
+ "./rules/*": "./rules/*"
13
+ },
14
+ "files": ["dist", "rules", "README.md", "LICENSE"],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/andesyte-oss/andesyte-cli.git",
18
+ "directory": "packages/security-rules"
19
+ },
20
+ "publishConfig": { "access": "public", "provenance": true },
21
+ "scripts": {
22
+ "build": "tsc -p tsconfig.json",
23
+ "typecheck": "tsc -p tsconfig.json --noEmit"
24
+ }
25
+ }
@@ -0,0 +1,166 @@
1
+ # LLM08 — Excessive Agency
2
+ #
3
+ # Agentic systems get into trouble when the LLM has direct access to
4
+ # irreversible side effects (sending emails, writing to prod DBs,
5
+ # transferring funds) without a confirm-step. These rules flag the most
6
+ # common patterns.
7
+
8
+ rules:
9
+ # GENERALISED DECORATOR + OPERATION MATCHING.
10
+ #
11
+ # The original version hardcoded `@tool` (bare) and three destructive call
12
+ # shapes. Mutation testing across seven realistic spellings found four
13
+ # false negatives: `@tool("name", return_direct=True)`, the OpenAI Agents
14
+ # SDK's `@function_tool`, `conn.execute("DELETE FROM ...")` (the string
15
+ # ellipsis never matched a partial literal), and `os.remove(...)`.
16
+ #
17
+ # The decorator is now matched by name shape (bare, called, or
18
+ # module-qualified) and the destructive operation by a verb allowlist, so
19
+ # the rule follows the *category* of call rather than one spelling.
20
+ - id: ai.excessive-agency.tool-deletes-without-confirmation-py
21
+ message: >-
22
+ LLM-callable tool performs a delete / destroy operation with no
23
+ explicit `confirm` argument the model must surface to the user.
24
+ Prompt-injection turns this into a one-click data-loss vector.
25
+ Require an explicit confirmation token, or route through a
26
+ human-in-the-loop approval step before executing the destructive
27
+ call.
28
+ severity: WARNING
29
+ languages: [python]
30
+ metadata:
31
+ cwe: "CWE-863: Incorrect Authorization"
32
+ owasp: "LLM08:2026 Excessive Agency"
33
+ impact: HIGH
34
+ patterns:
35
+ - pattern-either:
36
+ # Destructive method / function call by verb.
37
+ - patterns:
38
+ - pattern-either:
39
+ - pattern: |
40
+ @$DEC
41
+ def $NAME(...):
42
+ ...
43
+ $X.$M(...)
44
+ ...
45
+ - pattern: |
46
+ @$DEC(...)
47
+ def $NAME(...):
48
+ ...
49
+ $X.$M(...)
50
+ ...
51
+ - pattern: |
52
+ @$DEC
53
+ async def $NAME(...):
54
+ ...
55
+ $X.$M(...)
56
+ ...
57
+ - pattern: |
58
+ @$DEC(...)
59
+ async def $NAME(...):
60
+ ...
61
+ $X.$M(...)
62
+ ...
63
+ - metavariable-regex:
64
+ metavariable: $M
65
+ regex: "^(delete|delete_one|delete_many|delete_object|delete_objects|destroy|drop|drop_table|drop_collection|remove|unlink|rmtree|purge|truncate|wipe)$"
66
+ # Destructive SQL executed through a generic cursor API.
67
+ - patterns:
68
+ - pattern-either:
69
+ - pattern: |
70
+ @$DEC
71
+ def $NAME(...):
72
+ ...
73
+ $X.$M($Q, ...)
74
+ ...
75
+ - pattern: |
76
+ @$DEC(...)
77
+ def $NAME(...):
78
+ ...
79
+ $X.$M($Q, ...)
80
+ ...
81
+ - pattern: |
82
+ @$DEC
83
+ async def $NAME(...):
84
+ ...
85
+ $X.$M($Q, ...)
86
+ ...
87
+ - pattern: |
88
+ @$DEC(...)
89
+ async def $NAME(...):
90
+ ...
91
+ $X.$M($Q, ...)
92
+ ...
93
+ - metavariable-regex:
94
+ metavariable: $M
95
+ regex: "^(execute|executemany|execute_query|exec_driver_sql|run)$"
96
+ - metavariable-regex:
97
+ metavariable: $Q
98
+ regex: '(?is)^[frbu]*[''"].*\b(delete\s+from|drop\s+table|truncate\s+table)\b.*$'
99
+ - metavariable-regex:
100
+ metavariable: $DEC
101
+ regex: "^([A-Za-z_][A-Za-z_0-9]*\\.)*(tool|function_tool|ai_function|agent_tool)$"
102
+ - metavariable-regex:
103
+ metavariable: $NAME
104
+ regex: "^(delete|destroy|drop|wipe|purge|remove|truncate)_.*"
105
+ # A confirmation parameter the model must set is exactly the mitigation
106
+ # this rule asks for. Flagging a correctly-guarded tool teaches users
107
+ # that doing the right thing still trips the scanner.
108
+ - pattern-not: |
109
+ @$DEC
110
+ def $NAME(..., $CONFIRM, ...):
111
+ ...
112
+ if ...:
113
+ raise ...
114
+ ...
115
+ - pattern-not: |
116
+ @$DEC(...)
117
+ def $NAME(..., $CONFIRM, ...):
118
+ ...
119
+ if ...:
120
+ raise ...
121
+ ...
122
+ - pattern-not: |
123
+ @$DEC
124
+ async def $NAME(..., $CONFIRM, ...):
125
+ ...
126
+ if ...:
127
+ raise ...
128
+ ...
129
+
130
+ - id: ai.excessive-agency.tool-broad-shell-py
131
+ message: >-
132
+ An LLM tool named like a generic shell ("execute_command",
133
+ "run_shell", "bash", "sh") is exposed without an allowlist. This
134
+ gives the model arbitrary shell access. Replace with narrow,
135
+ verb-specific tools (e.g. `list_files`, `read_file`) and refuse
136
+ wildcard shell access entirely.
137
+ severity: ERROR
138
+ languages: [python]
139
+ metadata:
140
+ cwe: "CWE-77: Improper Neutralization of Special Elements used in a Command"
141
+ owasp: "LLM08:2026 Excessive Agency"
142
+ impact: HIGH
143
+ patterns:
144
+ - pattern-either:
145
+ - pattern: |
146
+ @$DEC
147
+ def $NAME(...):
148
+ ...
149
+ - pattern: |
150
+ @$DEC(...)
151
+ def $NAME(...):
152
+ ...
153
+ - pattern: |
154
+ @$DEC
155
+ async def $NAME(...):
156
+ ...
157
+ - pattern: |
158
+ @$DEC(...)
159
+ async def $NAME(...):
160
+ ...
161
+ - metavariable-regex:
162
+ metavariable: $DEC
163
+ regex: "^([A-Za-z_][A-Za-z_0-9]*\\.)*(tool|function_tool|ai_function|agent_tool)$"
164
+ - metavariable-regex:
165
+ metavariable: $NAME
166
+ regex: "^(execute_command|run_shell|run_bash|run_command|shell|bash|sh|run|exec|execute)$"
@@ -0,0 +1,222 @@
1
+ # LLM02 — Insecure Output Handling
2
+ #
3
+ # LLM output is *untrusted text from a remote server* and must be treated
4
+ # as such. The same model output that renders fine in your dashboard
5
+ # becomes XSS when piped into innerHTML, RCE when piped into eval, and
6
+ # SSRF when fed into a URL builder. These rules catch the most common
7
+ # pipelines.
8
+
9
+ rules:
10
+ # TAINT MODE after mutation testing.
11
+ #
12
+ # The syntactic version enumerated five exact shapes and missed 6 of 8
13
+ # realistic spellings of the same RCE: the response passed through two
14
+ # variables instead of one, `exec` reached via an intermediate variable,
15
+ # an Anthropic response bound to a variable first, `compile` as the sink,
16
+ # `self.client` inside a class, and `.strip()` called before eval.
17
+ #
18
+ # Taint mode follows the model output to whichever code-execution sink it
19
+ # reaches, however many hops away.
20
+ - id: ai.insecure-output-handling.eval-llm-response-py
21
+ message: >-
22
+ LLM response reaches `eval` / `exec` / `compile`. This is remote
23
+ code execution by any reasonable threat model — the model will
24
+ happily emit attacker-controlled code if the input prompt is
25
+ compromised. Use a sandboxed code interpreter or restrict to a
26
+ structured-output schema (e.g. tool calls / JSON Schema).
27
+ severity: ERROR
28
+ languages: [python]
29
+ mode: taint
30
+ metadata:
31
+ cwe: "CWE-94: Improper Control of Generation of Code"
32
+ owasp: "LLM02:2026 Insecure Output Handling"
33
+ impact: HIGH
34
+ pattern-sources:
35
+ - pattern-either:
36
+ - pattern: $X.choices[0].message.content
37
+ - pattern: $X.choices[0].delta.content
38
+ - pattern: $X.content[0].text
39
+ - pattern: $CLIENT.chat.completions.create(...)
40
+ - pattern: $CLIENT.messages.create(...)
41
+ pattern-sanitizers:
42
+ # Structured parsing is the recommended fix: `json.loads` raises on
43
+ # anything that is not data, so it cannot carry code through to a sink.
44
+ # `ast.literal_eval` likewise evaluates literals only.
45
+ - pattern: json.loads(...)
46
+ - pattern: ast.literal_eval(...)
47
+ pattern-sinks:
48
+ - patterns:
49
+ - pattern-either:
50
+ - pattern: eval($CODE, ...)
51
+ - pattern: exec($CODE, ...)
52
+ - pattern: compile($CODE, ...)
53
+ - focus-metavariable: $CODE
54
+
55
+ # TAINT MODE after mutation testing.
56
+ #
57
+ # The syntactic version matched two exact assignment shapes and missed 4 of
58
+ # 7 realistic spellings: the html held in a variable first, a Vercel AI SDK
59
+ # `generateText().text` result, `outerHTML`, and `insertAdjacentHTML` — all
60
+ # the same XSS with the same consequence.
61
+ - id: ai.insecure-output-handling.innerhtml-llm-response-ts
62
+ message: >-
63
+ LLM-generated text reaches `innerHTML` / `outerHTML` /
64
+ `insertAdjacentHTML` / `dangerouslySetInnerHTML`. Even if your prompt
65
+ instructs the model to return plain text, an attacker can manipulate
66
+ the response via prompt injection. Render via `textContent` / a JSX
67
+ text child, or sanitise with DOMPurify before injection.
68
+ severity: ERROR
69
+ languages: [typescript, javascript]
70
+ mode: taint
71
+ metadata:
72
+ cwe: "CWE-79: Cross-site Scripting"
73
+ owasp: "LLM02:2026 Insecure Output Handling"
74
+ impact: HIGH
75
+ pattern-sources:
76
+ - pattern-either:
77
+ - pattern: $X.choices[0].message.content
78
+ - pattern: $X.choices[0].delta.content
79
+ - pattern: $X.content[0].text
80
+ - pattern: generateText(...)
81
+ - pattern: streamText(...)
82
+ pattern-sanitizers:
83
+ # An HTML sanitiser is the documented fix; flagging sanitised output
84
+ # would teach users that doing the right thing still trips the scanner.
85
+ - pattern: DOMPurify.sanitize(...)
86
+ - pattern: $D.sanitize(...)
87
+ - pattern: sanitizeHtml(...)
88
+ pattern-sinks:
89
+ - patterns:
90
+ - pattern-either:
91
+ - pattern: $EL.innerHTML = $HTML
92
+ - pattern: $EL.outerHTML = $HTML
93
+ - pattern: $EL.insertAdjacentHTML($POS, $HTML)
94
+ - pattern: |
95
+ <$TAG dangerouslySetInnerHTML={{ __html: $HTML }} />
96
+ - focus-metavariable: $HTML
97
+
98
+ # SPLIT BY LANGUAGE, DELIBERATELY.
99
+ #
100
+ # This rule previously declared `languages: [python, typescript, javascript]`
101
+ # with Python-only patterns (`subprocess.run`, `os.system`). Semgrep must
102
+ # parse every pattern in EVERY declared language; `subprocess.run(...)` is not
103
+ # valid JavaScript, so the whole rule was silently dropped — no error, no
104
+ # warning, zero findings. Verified: identical patterns matched under
105
+ # [python] and [python, typescript] but NOT under [python, typescript,
106
+ # javascript].
107
+ #
108
+ # Keep language sets narrow and matched to the syntax they contain.
109
+ - id: ai.insecure-output-handling.shell-exec-llm-response-py
110
+ message: >-
111
+ LLM response is passed to a shell-exec primitive
112
+ (`subprocess.run(..., shell=True)`, `os.system`).
113
+ A successful prompt-injection here is full remote shell access on
114
+ whatever host runs this code. Replace with an exec form that takes
115
+ an argv array, or refuse non-allowlisted commands.
116
+ severity: ERROR
117
+ languages: [python]
118
+ mode: taint
119
+ metadata:
120
+ cwe: "CWE-78: OS Command Injection"
121
+ owasp: "LLM02:2026 Insecure Output Handling"
122
+ impact: HIGH
123
+ pattern-sources:
124
+ - pattern-either:
125
+ - pattern: $X.choices[0].message.content
126
+ - pattern: $X.choices[0].delta.content
127
+ - pattern: $X.content[0].text
128
+ - pattern: $CLIENT.chat.completions.create(...)
129
+ - pattern: $CLIENT.messages.create(...)
130
+ pattern-sanitizers:
131
+ # An argv ARRAY is the correct, safe form: no shell is involved, so
132
+ # model output cannot inject a command. Flagging it teaches users that
133
+ # doing the right thing still trips the scanner.
134
+ - pattern: subprocess.run([...], ...)
135
+ - pattern: subprocess.call([...], ...)
136
+ - pattern: subprocess.Popen([...], ...)
137
+ - pattern: subprocess.check_output([...], ...)
138
+ pattern-sinks:
139
+ - patterns:
140
+ - pattern-either:
141
+ - pattern: subprocess.run($CMD, shell=True, ...)
142
+ - pattern: subprocess.call($CMD, shell=True, ...)
143
+ - pattern: subprocess.Popen($CMD, shell=True, ...)
144
+ - pattern: subprocess.check_output($CMD, shell=True, ...)
145
+ - pattern: os.system($CMD)
146
+ - pattern: os.popen($CMD)
147
+
148
+ # Unconditional companion to the taint rule above.
149
+ #
150
+ # Taint requires a visible LLM source in the SAME file. In agent codebases
151
+ # the command frequently arrives as a plain function parameter from another
152
+ # module, where taint sees nothing. `shell=True` on a caller-supplied string
153
+ # is dangerous regardless of provenance, so this rule stands on the sink
154
+ # alone and deliberately does not try to prove the value came from a model.
155
+ - id: ai.insecure-output-handling.shell-true-untrusted-py
156
+ message: >-
157
+ A shell command is built from a non-literal value with `shell=True`
158
+ (or passed to `os.system`/`os.popen`). If that value can be influenced
159
+ by model output or user input — directly or several calls away — this is
160
+ remote command execution. Use an argv array with `shell=False`, or
161
+ allowlist the command.
162
+ severity: WARNING
163
+ languages: [python]
164
+ metadata:
165
+ cwe: "CWE-78: OS Command Injection"
166
+ owasp: "LLM02:2026 Insecure Output Handling"
167
+ impact: HIGH
168
+ patterns:
169
+ - pattern-either:
170
+ - pattern: subprocess.run($CMD, shell=True, ...)
171
+ - pattern: subprocess.call($CMD, shell=True, ...)
172
+ - pattern: subprocess.Popen($CMD, shell=True, ...)
173
+ - pattern: subprocess.check_output($CMD, shell=True, ...)
174
+ - pattern: os.system($CMD)
175
+ - pattern: os.popen($CMD)
176
+ # A hardcoded string literal is the developer's own command, not input.
177
+ - pattern-not: subprocess.run("...", shell=True, ...)
178
+ - pattern-not: subprocess.call("...", shell=True, ...)
179
+ - pattern-not: subprocess.Popen("...", shell=True, ...)
180
+ - pattern-not: subprocess.check_output("...", shell=True, ...)
181
+ - pattern-not: os.system("...")
182
+ - pattern-not: os.popen("...")
183
+
184
+ # TAINT MODE after mutation testing.
185
+ #
186
+ # The syntactic version matched `child_process.exec` and bare `exec`/
187
+ # `execSync` with an inline response expression, missing 3 of 7 realistic
188
+ # spellings: an aliased namespace import (`import * as cp`), the command
189
+ # held in a variable first, and `spawn(cmd, { shell: true })`.
190
+ - id: ai.insecure-output-handling.shell-exec-llm-response-js
191
+ message: >-
192
+ LLM response reaches a shell-exec primitive (`child_process.exec`,
193
+ `execSync`, or `spawn` with `shell: true`). A successful
194
+ prompt-injection here is full remote shell access on whatever host
195
+ runs this code. Use `execFile` with an argv array, or refuse
196
+ non-allowlisted commands.
197
+ severity: ERROR
198
+ languages: [typescript, javascript]
199
+ mode: taint
200
+ metadata:
201
+ cwe: "CWE-78: OS Command Injection"
202
+ owasp: "LLM02:2026 Insecure Output Handling"
203
+ impact: HIGH
204
+ pattern-sources:
205
+ - pattern-either:
206
+ - pattern: $X.choices[0].message.content
207
+ - pattern: $X.choices[0].delta.content
208
+ - pattern: $X.content[0].text
209
+ - pattern: generateText(...)
210
+ - pattern: streamText(...)
211
+ pattern-sinks:
212
+ - patterns:
213
+ - pattern-either:
214
+ - pattern: $CP.exec($CMD, ...)
215
+ - pattern: $CP.execSync($CMD, ...)
216
+ - pattern: exec($CMD, ...)
217
+ - pattern: execSync($CMD, ...)
218
+ - pattern: "$CP.spawn($CMD, { ..., shell: true, ... })"
219
+ - pattern: "spawn($CMD, { ..., shell: true, ... })"
220
+ - pattern: "$CP.spawnSync($CMD, { ..., shell: true, ... })"
221
+ - pattern: "spawnSync($CMD, { ..., shell: true, ... })"
222
+ - focus-metavariable: $CMD
@@ -0,0 +1,155 @@
1
+ # LLM07 — Insecure Plugin / Tool Design
2
+ #
3
+ # When you expose a tool to an LLM, it's effectively a user-controlled API
4
+ # endpoint with no authn. These rules flag tool implementations that are
5
+ # unsafe by themselves *regardless* of what the LLM does.
6
+
7
+ rules:
8
+ # GENERALISED DECORATOR + SINK MATCHING.
9
+ #
10
+ # The original version enumerated exactly `@tool` / `@tool(...)` with
11
+ # `subprocess.run(..., shell=True)` or `os.system`. Mutation testing across
12
+ # seven realistic spellings found four false negatives: `subprocess.call`,
13
+ # `subprocess.Popen`, `subprocess.check_output`, and the OpenAI Agents SDK's
14
+ # `@function_tool`. The decorator is now matched by name shape and the sink
15
+ # by the family of shell-exec primitives.
16
+ - id: ai.insecure-plugin.tool-runs-shell-py
17
+ message: >-
18
+ LLM tool implementation runs a shell command via `subprocess(..., shell=True)`
19
+ or `os.system`. The tool argument is, by construction, attacker-controlled
20
+ (any prompt injection can call this tool with any string). Refuse the tool
21
+ entirely, switch to an allowlisted operation, or use argv form with a
22
+ strict argument schema.
23
+ severity: ERROR
24
+ languages: [python]
25
+ metadata:
26
+ cwe: "CWE-78: OS Command Injection"
27
+ owasp: "LLM07:2026 Insecure Plugin Design"
28
+ impact: HIGH
29
+ patterns:
30
+ - pattern-either:
31
+ - pattern: |
32
+ @$DEC
33
+ def $NAME(...):
34
+ ...
35
+ $SHELL
36
+ ...
37
+ - pattern: |
38
+ @$DEC(...)
39
+ def $NAME(...):
40
+ ...
41
+ $SHELL
42
+ ...
43
+ - pattern: |
44
+ @$DEC
45
+ async def $NAME(...):
46
+ ...
47
+ $SHELL
48
+ ...
49
+ - pattern: |
50
+ @$DEC(...)
51
+ async def $NAME(...):
52
+ ...
53
+ $SHELL
54
+ ...
55
+ - metavariable-regex:
56
+ metavariable: $DEC
57
+ regex: "^([A-Za-z_][A-Za-z_0-9]*\\.)*(tool|function_tool|ai_function|agent_tool)$"
58
+ - metavariable-pattern:
59
+ metavariable: $SHELL
60
+ patterns:
61
+ - pattern-either:
62
+ - pattern: subprocess.run($CMD, ..., shell=True, ...)
63
+ - pattern: subprocess.call($CMD, ..., shell=True, ...)
64
+ - pattern: subprocess.Popen($CMD, ..., shell=True, ...)
65
+ - pattern: subprocess.check_output($CMD, ..., shell=True, ...)
66
+ - pattern: subprocess.check_call($CMD, ..., shell=True, ...)
67
+ - pattern: os.system($CMD)
68
+ - pattern: os.popen($CMD)
69
+ # An argv ARRAY never involves a shell, so it is the recommended
70
+ # fix and must stay quiet.
71
+ - pattern-not: subprocess.$M([...], ...)
72
+
73
+ # URL ARGUMENT SHAPE, NOT ONE CLIENT LIBRARY.
74
+ #
75
+ # The original version required the first tool parameter to be passed
76
+ # *directly* to `requests.get` / `httpx.$M` / `urllib.request.urlopen`.
77
+ # Mutation testing found three false negatives: the URL copied into a local
78
+ # first, `requests.post(url, json=...)`, and `requests.request("GET", url)`.
79
+ #
80
+ # The rule now flags any HTTP client call inside a tool whose URL argument is
81
+ # a bare identifier — i.e. a value flowing from the tool's own arguments.
82
+ # A string literal or an allowlist lookup (`ALLOWED[name]`) is not a bare
83
+ # identifier, which is what keeps the safe forms quiet.
84
+ - id: ai.insecure-plugin.tool-fetches-arbitrary-url-py
85
+ message: >-
86
+ LLM tool implementation performs a network request to a URL derived
87
+ from its arguments without any allowlist check. This is SSRF — an
88
+ attacker can pivot from prompt injection to internal-network access
89
+ (cloud metadata endpoints, internal admin APIs, etc.). Enforce an
90
+ allowlist of host patterns before the request leaves the function.
91
+ severity: ERROR
92
+ languages: [python]
93
+ metadata:
94
+ cwe: "CWE-918: Server-Side Request Forgery (SSRF)"
95
+ owasp: "LLM07:2026 Insecure Plugin Design"
96
+ impact: HIGH
97
+ patterns:
98
+ - pattern-either:
99
+ - pattern: |
100
+ @$DEC
101
+ def $NAME(...):
102
+ ...
103
+ $FETCH
104
+ ...
105
+ - pattern: |
106
+ @$DEC(...)
107
+ def $NAME(...):
108
+ ...
109
+ $FETCH
110
+ ...
111
+ - pattern: |
112
+ @$DEC
113
+ async def $NAME(...):
114
+ ...
115
+ $FETCH
116
+ ...
117
+ - pattern: |
118
+ @$DEC(...)
119
+ async def $NAME(...):
120
+ ...
121
+ $FETCH
122
+ ...
123
+ - metavariable-regex:
124
+ metavariable: $DEC
125
+ regex: "^([A-Za-z_][A-Za-z_0-9]*\\.)*(tool|function_tool|ai_function|agent_tool)$"
126
+ - metavariable-pattern:
127
+ metavariable: $FETCH
128
+ patterns:
129
+ - pattern-either:
130
+ # URL is the first positional argument.
131
+ - patterns:
132
+ - pattern-either:
133
+ - pattern: requests.$M($URL, ...)
134
+ - pattern: httpx.$M($URL, ...)
135
+ - pattern: aiohttp.$M($URL, ...)
136
+ - pattern: $SESSION.get($URL, ...)
137
+ - pattern: $SESSION.post($URL, ...)
138
+ - metavariable-regex:
139
+ metavariable: $M
140
+ regex: "^(get|post|put|patch|delete|head|options|request|stream)$"
141
+ # urllib has no method metavariable to constrain.
142
+ - pattern: urllib.request.urlopen($URL, ...)
143
+ - pattern: urlopen($URL, ...)
144
+ # `requests.request("GET", url)` — verb first, URL second.
145
+ - patterns:
146
+ - pattern-either:
147
+ - pattern: requests.request($VERB, $URL, ...)
148
+ - pattern: httpx.request($VERB, $URL, ...)
149
+ - pattern: $SESSION.request($VERB, $URL, ...)
150
+ # Only a bare identifier counts: a literal URL is the developer's
151
+ # own endpoint and `ALLOWED[name]` is the allowlist this rule asks
152
+ # for. Neither is attacker-controlled.
153
+ - metavariable-regex:
154
+ metavariable: $URL
155
+ regex: "^[A-Za-z_][A-Za-z_0-9]*$"
@@ -0,0 +1,88 @@
1
+ # LLM04 — Model Denial of Service
2
+ #
3
+ # Naive LLM integrations can be DoS'd cheaply by sending huge inputs,
4
+ # unbounded completion lengths, or by exploiting agent loops with no
5
+ # step ceiling. These rules flag the most common shapes.
6
+
7
+ rules:
8
+ - id: ai.model-dos.no-max-tokens-openai-py
9
+ message: >-
10
+ OpenAI completion call has no `max_tokens` (or `max_completion_tokens`)
11
+ cap. Without one, a maliciously-crafted prompt can drive the response
12
+ to the model's context limit and burn API spend at attacker pace. Set
13
+ an explicit cap appropriate to the use case (typically 1024–4096).
14
+ severity: WARNING
15
+ languages: [python]
16
+ metadata:
17
+ cwe: "CWE-770: Allocation of Resources Without Limits or Throttling"
18
+ owasp: "LLM04:2026 Model Denial of Service"
19
+ impact: MEDIUM
20
+ patterns:
21
+ - pattern: $CLIENT.chat.completions.create(...)
22
+ - pattern-not: $CLIENT.chat.completions.create(..., max_tokens=..., ...)
23
+ - pattern-not: $CLIENT.chat.completions.create(..., max_completion_tokens=..., ...)
24
+
25
+ - id: ai.model-dos.no-max-tokens-anthropic-py
26
+ message: >-
27
+ Anthropic messages call has no `max_tokens` cap. `max_tokens` is
28
+ technically required by the API but the SDK accepts None and the
29
+ server's default is very high — attackers can drive cost per
30
+ request to multiple dollars trivially. Always set an explicit cap.
31
+ severity: WARNING
32
+ languages: [python]
33
+ metadata:
34
+ cwe: "CWE-770: Allocation of Resources Without Limits or Throttling"
35
+ owasp: "LLM04:2026 Model Denial of Service"
36
+ impact: MEDIUM
37
+ patterns:
38
+ - pattern: $CLIENT.messages.create(...)
39
+ - pattern-not: $CLIENT.messages.create(..., max_tokens=..., ...)
40
+
41
+ - id: ai.model-dos.unbounded-agent-loop-langchain
42
+ message: >-
43
+ LangChain AgentExecutor is constructed without `max_iterations` /
44
+ `max_execution_time`. A malicious tool result can cause the agent
45
+ to loop indefinitely (each iteration ≈ one LLM round-trip = ~$0.01).
46
+ Set `max_iterations=10` and `max_execution_time=60` by default,
47
+ tuned upward only when the workload requires it.
48
+ severity: WARNING
49
+ languages: [python]
50
+ metadata:
51
+ cwe: "CWE-835: Loop with Unreachable Exit Condition"
52
+ owasp: "LLM04:2026 Model Denial of Service"
53
+ impact: MEDIUM
54
+ patterns:
55
+ - pattern-either:
56
+ - pattern: AgentExecutor(...)
57
+ - pattern: AgentExecutor.from_agent_and_tools(...)
58
+ # `import langchain.agents as la` -> `la.AgentExecutor(...)`.
59
+ - pattern: $MOD.AgentExecutor(...)
60
+ - pattern: $MOD.AgentExecutor.from_agent_and_tools(...)
61
+ # `from langchain.agents import AgentExecutor as AE` -> `AE(...)`.
62
+ # The alias is only meaningful next to the import that created it,
63
+ # so the import is matched as part of the pattern rather than
64
+ # trusting a bare identifier.
65
+ - pattern: |
66
+ from langchain.agents import AgentExecutor as $AE
67
+ ...
68
+ $AE(...)
69
+ - pattern: |
70
+ from langchain.agents import AgentExecutor as $AE
71
+ ...
72
+ $AE.from_agent_and_tools(...)
73
+ - pattern-not: |
74
+ AgentExecutor(..., max_iterations=..., ...)
75
+ - pattern-not: |
76
+ AgentExecutor.from_agent_and_tools(..., max_iterations=..., ...)
77
+ - pattern-not: |
78
+ $MOD.AgentExecutor(..., max_iterations=..., ...)
79
+ - pattern-not: |
80
+ $MOD.AgentExecutor.from_agent_and_tools(..., max_iterations=..., ...)
81
+ - pattern-not: |
82
+ from langchain.agents import AgentExecutor as $AE
83
+ ...
84
+ $AE(..., max_iterations=..., ...)
85
+ - pattern-not: |
86
+ from langchain.agents import AgentExecutor as $AE
87
+ ...
88
+ $AE.from_agent_and_tools(..., max_iterations=..., ...)
@@ -0,0 +1,156 @@
1
+ # LLM01 — Prompt Injection
2
+ #
3
+ # Rules in this pack flag *sinks* that splice untrusted user input directly
4
+ # into an LLM prompt. We focus on the construction site (where the prompt
5
+ # is built) rather than the call site (where it's sent), because that's the
6
+ # point at which sanitisation should happen.
7
+ #
8
+ # False-positive policy: only flag when the value spliced into the prompt
9
+ # is *unambiguously* untrusted (req.body, request.json(), event.body, etc.)
10
+ # AND the splice is inline. Variables that pass through any normalisation
11
+ # helper are out of scope here — taint mode would handle that and we save
12
+ # it for v2.
13
+
14
+ rules:
15
+ # TAINT MODE, DELIBERATELY.
16
+ #
17
+ # The original syntactic version matched only the exact shape
18
+ # `create(..., messages=[{"content": f"...{request.attr}..."}])`. Mutation
19
+ # testing across eight realistic style variants of the SAME vulnerability
20
+ # found a 50% false-negative rate: it missed the messages list assigned to a
21
+ # variable first, `"..." + request.body`, `"%s" % request.body`, and any
22
+ # parameter not literally named request/req/event/body/payload.
23
+ #
24
+ # Taint mode follows the value instead of pattern-matching one spelling of
25
+ # it, which is what a real codebase looks like. Verified 8/8 on the variants
26
+ # and 0/3 false positives on safe equivalents.
27
+ - id: ai.prompt-injection.openai-python-fstring-user-input
28
+ message: >-
29
+ User-controlled input is interpolated into an LLM prompt (f-string,
30
+ concatenation or %-formatting). An attacker can override the system
31
+ prompt or exfiltrate tool credentials by injecting role markers. Pass
32
+ untrusted text as its own message parameter rather than building it into
33
+ an instruction string, or wrap it in a delimiter and instruct the model
34
+ to treat it as data.
35
+ severity: WARNING
36
+ languages: [python]
37
+ mode: taint
38
+ metadata:
39
+ cwe: "CWE-77: Improper Neutralization of Special Elements used in a Command"
40
+ owasp: "LLM01:2026 Prompt Injection"
41
+ impact: HIGH
42
+ references:
43
+ - https://genai.owasp.org/llmrisk/llm01-prompt-injection/
44
+ pattern-sources:
45
+ - patterns:
46
+ - pattern-either:
47
+ - pattern: $REQ.$F
48
+ - pattern: $REQ.$F(...)
49
+ - metavariable-regex:
50
+ metavariable: $REQ
51
+ regex: "^(request|req|event|body|payload|user_message|user_input|message|msg|input|data|query|prompt_input)$"
52
+ # Handing untrusted text to the API as its own message value is the
53
+ # CORRECT pattern. Only building it into a string is the risk, so a bare
54
+ # content value sanitises the flow while interpolated forms do not.
55
+ pattern-sanitizers:
56
+ - patterns:
57
+ - pattern: '{"role": ..., "content": $X}'
58
+ - pattern-not: '{"role": ..., "content": f"..."}'
59
+ - pattern-not: '{"role": ..., "content": $A + $B}'
60
+ - pattern-not: '{"role": ..., "content": $A % $B}'
61
+ - pattern-not: '{"role": ..., "content": $A.format(...)}'
62
+ pattern-sinks:
63
+ - patterns:
64
+ - pattern-either:
65
+ - pattern: $CLIENT.chat.completions.create(...)
66
+ - pattern: $CLIENT.messages.create(...)
67
+
68
+ # TAINT MODE, for the same reason as the rule above.
69
+ #
70
+ # The syntactic version required an f-string containing a `$REQ.$F` access
71
+ # spelled inline inside `.invoke(...)`, with $REQ literally named
72
+ # request/req/event/body/payload. Mutation testing across eight realistic
73
+ # spellings found 5 false negatives: string concatenation, the prompt built
74
+ # into a variable first, a differently-named parameter, `.predict(...)`, and
75
+ # the async `.ainvoke(...)`.
76
+ - id: ai.prompt-injection.langchain-string-prompt
77
+ message: >-
78
+ A LangChain prompt is constructed with raw string concatenation /
79
+ f-string interpolation of untrusted input. Use PromptTemplate /
80
+ ChatPromptTemplate with named variables — those route untrusted text
81
+ through LangChain's parameter binding, which (a) prevents accidental
82
+ role injection and (b) lets you swap in an input sanitiser later.
83
+ severity: WARNING
84
+ languages: [python]
85
+ mode: taint
86
+ metadata:
87
+ cwe: "CWE-77: Improper Neutralization of Special Elements used in a Command"
88
+ owasp: "LLM01:2026 Prompt Injection"
89
+ impact: HIGH
90
+ pattern-sources:
91
+ - patterns:
92
+ - pattern-either:
93
+ - pattern: $REQ.$F
94
+ - pattern: $REQ.$F(...)
95
+ - metavariable-regex:
96
+ metavariable: $REQ
97
+ regex: "^(request|req|event|body|payload|user_message|user_input|message|msg|input|data|query|prompt_input)$"
98
+ pattern-sanitizers:
99
+ # PromptTemplate binding is the fix this rule recommends: the untrusted
100
+ # text becomes a bound parameter, not part of the instruction string.
101
+ - pattern: $TPL.format(...)
102
+ - pattern: $TPL.format_prompt(...)
103
+ - pattern: $TPL.invoke({...})
104
+ pattern-sinks:
105
+ - patterns:
106
+ - pattern-either:
107
+ - pattern: $LLM.invoke($P, ...)
108
+ - pattern: $LLM.ainvoke($P, ...)
109
+ - pattern: $LLM.predict($P, ...)
110
+ - pattern: $LLM.apredict($P, ...)
111
+ - pattern: $LLM.stream($P, ...)
112
+ - pattern: $LLM.astream($P, ...)
113
+ - pattern: $LLM.batch($P, ...)
114
+ - focus-metavariable: $P
115
+
116
+ # TAINT MODE, same reasoning as the Python rules above.
117
+ #
118
+ # The syntactic version required the template literal spelled inline in the
119
+ # `prompt:` property. Mutation testing found the obvious miss: the prompt
120
+ # assigned to a `const` first and passed by shorthand.
121
+ - id: ai.prompt-injection.vercel-ai-sdk-template-literal
122
+ message: >-
123
+ A Vercel AI SDK prompt is built from request-scoped data. Use the
124
+ `messages` array with role-separated content blocks, and pass
125
+ untrusted input as a user-role message wrapped in a delimiter the
126
+ model is instructed to treat as data only.
127
+ severity: WARNING
128
+ languages: [typescript, javascript]
129
+ mode: taint
130
+ metadata:
131
+ cwe: "CWE-77: Improper Neutralization of Special Elements used in a Command"
132
+ owasp: "LLM01:2026 Prompt Injection"
133
+ impact: HIGH
134
+ pattern-sources:
135
+ - patterns:
136
+ - pattern-either:
137
+ - pattern: $REQ.$F
138
+ - pattern: $REQ.$F(...)
139
+ - pattern: await $REQ.$F(...)
140
+ - metavariable-regex:
141
+ metavariable: $REQ
142
+ regex: "^(req|request|event|body|payload|searchParams|userInput|user_input|input|data|query|message|msg)$"
143
+ pattern-sanitizers:
144
+ # Passing untrusted text as its own message value is the correct
145
+ # pattern; only building it into an instruction string is the risk.
146
+ - patterns:
147
+ - pattern: "{ role: ..., content: $X }"
148
+ - pattern-not: "{ role: ..., content: `...` }"
149
+ pattern-sinks:
150
+ - patterns:
151
+ - pattern-either:
152
+ - pattern: "generateText({ ..., prompt: $P, ... })"
153
+ - pattern: "streamText({ ..., prompt: $P, ... })"
154
+ - pattern: "generateObject({ ..., prompt: $P, ... })"
155
+ - pattern: "streamObject({ ..., prompt: $P, ... })"
156
+ - focus-metavariable: $P
@@ -0,0 +1,105 @@
1
+ # LLM06 — Sensitive Information Disclosure
2
+ #
3
+ # Two failure modes: (a) secrets / PII embedded in the system prompt or
4
+ # tool definitions, where they leak as soon as the prompt is recoverable
5
+ # via prompt injection; (b) logging the full LLM request including the
6
+ # system prompt, where the secret leaks through observability.
7
+
8
+ rules:
9
+ # TAINT MODE after mutation testing.
10
+ #
11
+ # The syntactic version required a double-quoted literal sitting *directly*
12
+ # in a `{"role": "system", ...}` dict. Eight realistic spellings of the same
13
+ # vulnerability showed three false negatives: single-quoted dicts (`{'role':
14
+ # 'system', ...}`), the `developer` role (OpenAI's o-series rename of
15
+ # `system`), and the common shape where the key lives in a module constant
16
+ # that is interpolated into the content string.
17
+ #
18
+ # Taint mode follows the secret literal to whichever prompt slot it reaches.
19
+ - id: ai.sensitive-info.hardcoded-secret-in-system-prompt-py
20
+ message: >-
21
+ What looks like a long random token / API key reaches a system prompt
22
+ string. Anything in the system prompt is recoverable via prompt
23
+ injection — never put secrets there. Inject them via tool calls or
24
+ fetch them server-side from the request context.
25
+ severity: ERROR
26
+ languages: [python]
27
+ mode: taint
28
+ metadata:
29
+ cwe: "CWE-798: Use of Hard-coded Credentials"
30
+ owasp: "LLM06:2026 Sensitive Information Disclosure"
31
+ impact: HIGH
32
+ pattern-sources:
33
+ - patterns:
34
+ - pattern: $S
35
+ - metavariable-regex:
36
+ metavariable: $S
37
+ # Vendor key shapes with enough entropy to be unambiguous. The
38
+ # length floors are what keep `"The sku is sk-123."` quiet.
39
+ regex: '(?s)^[frbu]*[''"].*(sk_live_|sk-[A-Za-z0-9]{20,}|ghp_[A-Za-z0-9]{30,}|AKIA[0-9A-Z]{16}|AIza[0-9A-Za-z\-_]{30,}).*[''"]$'
40
+ pattern-sinks:
41
+ - patterns:
42
+ - pattern-either:
43
+ # `developer` is OpenAI's o-series rename of the system role and
44
+ # carries exactly the same disclosure risk.
45
+ - pattern: '{"role": "system", "content": $C}'
46
+ - pattern: "{'role': 'system', 'content': $C}"
47
+ - pattern: '{"role": "developer", "content": $C}'
48
+ - pattern: "{'role': 'developer', 'content': $C}"
49
+ - focus-metavariable: $C
50
+
51
+ # TAINT MODE after real-world testing.
52
+ #
53
+ # The original patterns were `logger.$LEVEL(..., $MSGS, ...)` and
54
+ # `print(f"...{$MSGS}...")`, which match ANY logging call and ANY f-string
55
+ # print. Scanned against real repositories (langserve, openai-python) they
56
+ # produced 33 findings, ALL false positives — `print(f"LANGSERVE: ...")`,
57
+ # `logger.error(error_message)`. Noise on that scale gets a scanner switched
58
+ # off, which is a security failure by a slower route.
59
+ #
60
+ # Now requires an actual LLM payload to reach a logging sink.
61
+ - id: ai.sensitive-info.log-full-llm-request-py
62
+ message: >-
63
+ An LLM request payload or response is being logged. If the system
64
+ prompt or conversation contains anything secret (API keys, internal
65
+ URLs, customer identifiers), it is now in your log aggregator.
66
+ Log an identifier or a redacted summary instead of the payload.
67
+ severity: WARNING
68
+ languages: [python]
69
+ mode: taint
70
+ metadata:
71
+ cwe: "CWE-532: Insertion of Sensitive Information into Log File"
72
+ owasp: "LLM06:2026 Sensitive Information Disclosure"
73
+ impact: MEDIUM
74
+ pattern-sources:
75
+ - pattern-either:
76
+ # The payload itself, however it was built.
77
+ - pattern: |
78
+ $MSGS = [{"role": ..., "content": ...}, ...]
79
+ - pattern: $CLIENT.chat.completions.create(...)
80
+ - pattern: $CLIENT.messages.create(...)
81
+ pattern-sanitizers:
82
+ # Aggregates and redactions carry no payload content. `len(messages)` is
83
+ # the canonical "log a size, not the data" fix and must not be flagged,
84
+ # otherwise the rule punishes the remediation it recommends.
85
+ - pattern-either:
86
+ - pattern: len(...)
87
+ - pattern: $X.count(...)
88
+ - pattern: redact(...)
89
+ - pattern: $X.redact(...)
90
+ - pattern: scrub(...)
91
+ - pattern: $X.scrub(...)
92
+ pattern-sinks:
93
+ # `print` is deliberately NOT a sink. Real-world testing showed the
94
+ # overwhelming majority of matches were CLI demos printing model output
95
+ # to a terminal — `print(completion.choices[0].message.content)` — which
96
+ # is the intended behaviour of that code, not a disclosure. Persistent
97
+ # log sinks are the actual risk: they ship payloads to an aggregator.
98
+ - pattern-either:
99
+ - pattern: logging.$LEVEL(...)
100
+ - pattern: logger.$LEVEL(...)
101
+ - pattern: $LOG.debug(...)
102
+ - pattern: $LOG.info(...)
103
+ - pattern: $LOG.warning(...)
104
+ - pattern: $LOG.error(...)
105
+ - pattern: $LOG.exception(...)