@andesyte-oss/security-rules 0.1.2 → 0.1.3
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 +1 -1
- package/README.md +12 -37
- package/dist/index.d.ts +10 -1
- package/dist/index.js +20 -2
- package/package.json +7 -3
- package/rules/insecure-output-handling.yml +31 -32
- package/rules/sensitive-info-disclosure.yml +5 -66
- package/rules/excessive-agency.yml +0 -166
- package/rules/insecure-plugin-design.yml +0 -155
- package/rules/model-dos.yml +0 -88
- package/rules/prompt-injection.yml +0 -156
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,42 +1,17 @@
|
|
|
1
1
|
# @andesyte-oss/security-rules
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Six packaged local Semgrep rules for narrow AI-application review. Four rules
|
|
4
|
+
apply to Python; two each apply to JavaScript and TypeScript.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
- Insecure output handling: model output reaching execution, shell or HTML,
|
|
7
|
+
plus a nonliteral Python shell-command review heuristic.
|
|
8
|
+
- Sensitive information: credential-shaped prompt literals.
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
This is not general SAST, prompt-injection prevention, model-DoS detection, SSRF
|
|
11
|
+
or tool authorization review. Eleven unsound/broad heuristics were retired; the
|
|
12
|
+
repository's rule-decision ledger preserves their rationale and regression history.
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
14
|
+
Rules never download at runtime. The canonical source is
|
|
15
|
+
`andesyte-oss/semgrep-ai-security`, synchronized with a checksum lock. Use
|
|
16
|
+
`@andesyte-oss/cli` for the executable; this package only locates rule files.
|
|
17
|
+
MIT.
|
package/dist/index.d.ts
CHANGED
|
@@ -6,4 +6,13 @@
|
|
|
6
6
|
export declare function rulesDir(): string;
|
|
7
7
|
export declare function rulePaths(): string[];
|
|
8
8
|
export declare const RULESET_NAME = "andesyte-local";
|
|
9
|
-
export declare const RULESET_VERSION
|
|
9
|
+
export declare const RULESET_VERSION: string;
|
|
10
|
+
export interface RulesetDescriptor {
|
|
11
|
+
name: string;
|
|
12
|
+
version: string;
|
|
13
|
+
rulePaths: string[];
|
|
14
|
+
/** Extensions for Semgrep languages not known to scanner-core. */
|
|
15
|
+
languageExtensions: Readonly<Record<string, readonly string[]>>;
|
|
16
|
+
}
|
|
17
|
+
/** Complete descriptor consumed by scanner adapters. */
|
|
18
|
+
export declare function ruleset(): RulesetDescriptor;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, readdirSync } from "node:fs";
|
|
1
|
+
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
2
2
|
import { dirname, join } from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
@@ -24,4 +24,22 @@ export function rulePaths() {
|
|
|
24
24
|
.map((f) => join(dir, f));
|
|
25
25
|
}
|
|
26
26
|
export const RULESET_NAME = "andesyte-local";
|
|
27
|
-
|
|
27
|
+
function packageVersion() {
|
|
28
|
+
try {
|
|
29
|
+
const manifest = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8"));
|
|
30
|
+
return typeof manifest.version === "string" ? manifest.version : "unknown";
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return "unknown";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export const RULESET_VERSION = packageVersion();
|
|
37
|
+
/** Complete descriptor consumed by scanner adapters. */
|
|
38
|
+
export function ruleset() {
|
|
39
|
+
return {
|
|
40
|
+
name: RULESET_NAME,
|
|
41
|
+
version: RULESET_VERSION,
|
|
42
|
+
rulePaths: rulePaths(),
|
|
43
|
+
languageExtensions: {},
|
|
44
|
+
};
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andesyte-oss/security-rules",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Andesyte curated Semgrep security rules, shipped as packaged local files (no registry fetch).",
|
|
5
|
+
"homepage": "https://andesyte.com",
|
|
6
|
+
"author": "Andesyte <lewis@andesyte.com>",
|
|
7
|
+
"bugs": {
|
|
8
|
+
"email": "lewis@andesyte.com"
|
|
9
|
+
},
|
|
5
10
|
"license": "MIT",
|
|
6
11
|
"type": "module",
|
|
7
12
|
"engines": {
|
|
@@ -28,8 +33,7 @@
|
|
|
28
33
|
"directory": "packages/security-rules"
|
|
29
34
|
},
|
|
30
35
|
"publishConfig": {
|
|
31
|
-
"access": "public"
|
|
32
|
-
"provenance": true
|
|
36
|
+
"access": "public"
|
|
33
37
|
},
|
|
34
38
|
"scripts": {
|
|
35
39
|
"build": "tsc -p tsconfig.json",
|
|
@@ -19,11 +19,10 @@ rules:
|
|
|
19
19
|
# reaches, however many hops away.
|
|
20
20
|
- id: ai.insecure-output-handling.eval-llm-response-py
|
|
21
21
|
message: >-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
structured-output schema (e.g. tool calls / JSON Schema).
|
|
22
|
+
Model output reaches eval, exec or compile. Treat generated code as
|
|
23
|
+
untrusted. Avoid executing it, or use an isolated interpreter with
|
|
24
|
+
explicit permissions. JSON parsing or schema validation does not make
|
|
25
|
+
an extracted string safe to execute.
|
|
27
26
|
severity: ERROR
|
|
28
27
|
languages: [python]
|
|
29
28
|
mode: taint
|
|
@@ -38,12 +37,8 @@ rules:
|
|
|
38
37
|
- pattern: $X.content[0].text
|
|
39
38
|
- pattern: $CLIENT.chat.completions.create(...)
|
|
40
39
|
- pattern: $CLIENT.messages.create(...)
|
|
41
|
-
|
|
42
|
-
|
|
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(...)
|
|
40
|
+
- pattern: $CLIENT.responses.create(...)
|
|
41
|
+
- pattern: $X.output_text
|
|
47
42
|
pattern-sinks:
|
|
48
43
|
- patterns:
|
|
49
44
|
- pattern-either:
|
|
@@ -82,9 +77,16 @@ rules:
|
|
|
82
77
|
pattern-sanitizers:
|
|
83
78
|
# An HTML sanitiser is the documented fix; flagging sanitised output
|
|
84
79
|
# would teach users that doing the right thing still trips the scanner.
|
|
85
|
-
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
- patterns:
|
|
81
|
+
- pattern: $PURIFY.sanitize(...)
|
|
82
|
+
- pattern-inside: |
|
|
83
|
+
import $PURIFY from "dompurify";
|
|
84
|
+
...
|
|
85
|
+
- patterns:
|
|
86
|
+
- pattern: $SANITIZE(...)
|
|
87
|
+
- pattern-inside: |
|
|
88
|
+
import $SANITIZE from "sanitize-html";
|
|
89
|
+
...
|
|
88
90
|
pattern-sinks:
|
|
89
91
|
- patterns:
|
|
90
92
|
- pattern-either:
|
|
@@ -110,9 +112,9 @@ rules:
|
|
|
110
112
|
message: >-
|
|
111
113
|
LLM response is passed to a shell-exec primitive
|
|
112
114
|
(`subprocess.run(..., shell=True)`, `os.system`).
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
Untrusted output can become a shell command. Use a fixed executable
|
|
116
|
+
with shell=False and validated arguments, or refuse the operation.
|
|
117
|
+
An argv array with shell=True is not a safe replacement.
|
|
116
118
|
severity: ERROR
|
|
117
119
|
languages: [python]
|
|
118
120
|
mode: taint
|
|
@@ -127,14 +129,8 @@ rules:
|
|
|
127
129
|
- pattern: $X.content[0].text
|
|
128
130
|
- pattern: $CLIENT.chat.completions.create(...)
|
|
129
131
|
- pattern: $CLIENT.messages.create(...)
|
|
130
|
-
|
|
131
|
-
|
|
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([...], ...)
|
|
132
|
+
- pattern: $CLIENT.responses.create(...)
|
|
133
|
+
- pattern: $X.output_text
|
|
138
134
|
pattern-sinks:
|
|
139
135
|
- patterns:
|
|
140
136
|
- pattern-either:
|
|
@@ -142,6 +138,7 @@ rules:
|
|
|
142
138
|
- pattern: subprocess.call($CMD, shell=True, ...)
|
|
143
139
|
- pattern: subprocess.Popen($CMD, shell=True, ...)
|
|
144
140
|
- pattern: subprocess.check_output($CMD, shell=True, ...)
|
|
141
|
+
- pattern: subprocess.check_call($CMD, shell=True, ...)
|
|
145
142
|
- pattern: os.system($CMD)
|
|
146
143
|
- pattern: os.popen($CMD)
|
|
147
144
|
|
|
@@ -157,8 +154,8 @@ rules:
|
|
|
157
154
|
A shell command is built from a non-literal value with `shell=True`
|
|
158
155
|
(or passed to `os.system`/`os.popen`). If that value can be influenced
|
|
159
156
|
by model output or user input — directly or several calls away — this is
|
|
160
|
-
|
|
161
|
-
|
|
157
|
+
a command-injection risk. Review the value's origin. Prefer a fixed
|
|
158
|
+
executable with shell=False and validated arguments.
|
|
162
159
|
severity: WARNING
|
|
163
160
|
languages: [python]
|
|
164
161
|
metadata:
|
|
@@ -189,11 +186,9 @@ rules:
|
|
|
189
186
|
# held in a variable first, and `spawn(cmd, { shell: true })`.
|
|
190
187
|
- id: ai.insecure-output-handling.shell-exec-llm-response-js
|
|
191
188
|
message: >-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
runs this code. Use `execFile` with an argv array, or refuse
|
|
196
|
-
non-allowlisted commands.
|
|
189
|
+
Model output reaches a shell-exec primitive. Prefer execFile with a
|
|
190
|
+
fixed executable and validated arguments; an argv array alone does
|
|
191
|
+
not prevent option injection or unsafe executable selection.
|
|
197
192
|
severity: ERROR
|
|
198
193
|
languages: [typescript, javascript]
|
|
199
194
|
mode: taint
|
|
@@ -219,4 +214,8 @@ rules:
|
|
|
219
214
|
- pattern: "spawn($CMD, { ..., shell: true, ... })"
|
|
220
215
|
- pattern: "$CP.spawnSync($CMD, { ..., shell: true, ... })"
|
|
221
216
|
- pattern: "spawnSync($CMD, { ..., shell: true, ... })"
|
|
217
|
+
- pattern: "$CP.spawn($CMD, $ARGS, { ..., shell: true, ... })"
|
|
218
|
+
- pattern: "spawn($CMD, $ARGS, { ..., shell: true, ... })"
|
|
219
|
+
- pattern: "$CP.spawnSync($CMD, $ARGS, { ..., shell: true, ... })"
|
|
220
|
+
- pattern: "spawnSync($CMD, $ARGS, { ..., shell: true, ... })"
|
|
222
221
|
- focus-metavariable: $CMD
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
#
|
|
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.
|
|
1
|
+
# Credential-shaped literals in model-visible prompt roles.
|
|
2
|
+
# Not a general secret scanner or logging-policy check.
|
|
7
3
|
|
|
8
4
|
rules:
|
|
9
5
|
# TAINT MODE after mutation testing.
|
|
@@ -18,10 +14,9 @@ rules:
|
|
|
18
14
|
# Taint mode follows the secret literal to whichever prompt slot it reaches.
|
|
19
15
|
- id: ai.sensitive-info.hardcoded-secret-in-system-prompt-py
|
|
20
16
|
message: >-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
fetch them server-side from the request context.
|
|
17
|
+
A credential-shaped literal reaches a system or developer prompt.
|
|
18
|
+
Confirm whether it is a real credential. Keep credentials in server-side
|
|
19
|
+
tool implementation, outside model-visible prompts and tool arguments.
|
|
25
20
|
severity: ERROR
|
|
26
21
|
languages: [python]
|
|
27
22
|
mode: taint
|
|
@@ -47,59 +42,3 @@ rules:
|
|
|
47
42
|
- pattern: '{"role": "developer", "content": $C}'
|
|
48
43
|
- pattern: "{'role': 'developer', 'content': $C}"
|
|
49
44
|
- 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(...)
|
|
@@ -1,166 +0,0 @@
|
|
|
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)$"
|
|
@@ -1,155 +0,0 @@
|
|
|
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]*$"
|
package/rules/model-dos.yml
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
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=..., ...)
|
|
@@ -1,156 +0,0 @@
|
|
|
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
|