SKY-D262 · Security in code
LLM output run as code, SQL, a shell command or a URL
A model's reply is text that anyone who can influence the prompt can shape. SKY-D262 reports Python code that passes that reply, without checking it, to eval() or exec(), a shell, a SQL execute() call or the URL of an HTTP request.
- Languages
- Python
- Quality gate
- counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans)
- Finding type
- review
- Catalog name
- Unsafe LLM output handling
Why it matters
A "text to SQL" feature that runs whatever query the model writes will run DROP TABLE or a query over another customer's rows as soon as a user asks for it cleverly. The same goes for generated shell commands, generated Python and URLs the server then fetches.
What Skylos flags
import sqlite3 from openai import OpenAI client = OpenAI() def run_report(question: str) -> list[tuple]: reply = client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "system", "content": "Write one SQLite query for the sales data."}, {"role": "user", "content": question}, ], ) sql = reply.choices[0].message.content conn = sqlite3.connect("sales.db") return conn.execute(sql).fetchall()What Skylos leaves alone
import os import requestsfrom openai import OpenAI client = OpenAI()SLACK_WEBHOOK_URL = os.environ["SLACK_WEBHOOK_URL"] def post_digest(question: str) -> None: reply = client.chat.completions.create( model="gpt-4o-mini", messages=[ {"role": "system", "content": "Summarise yesterday's sales in 3 lines."}, {"role": "user", "content": question}, ], ) summary = reply.choices[0].message.content requests.post(SLACK_WEBHOOK_URL, json={"text": summary}, timeout=10)Why Skylos leaves it alone
The reply reaches a network call, but only as the message body. The URL is a fixed setting, so the model cannot choose where the request goes. For HTTP calls only the URL argument is checked.
How Skylos decides
- Runs with
--dangeron Python files that mention an LLM library (openai,anthropic,litellm,langchainand similar). - Marks as model output the result of a model call (the same calls as SKY-D261:
.chat.completions.create,.responses.create,.messages.create,.invoke,.generateand so on) and every variable assigned from an expression that contains model output, such asreply.choices[0].message.contentorjson.loads(reply...). - Reports CRITICAL when model output appears anywhere in: the first argument of
eval(),exec()oros.system(); the command of asubprocess.*call withshell=True; the first argument of a call ending in.execute,.executemanyor.executescript; or the URL ofrequests.get/post/put/patch/delete/requestor the samehttpxcalls. - Nothing counts as a check: comparing the reply with a list, parsing it or looking it up in a dictionary still leaves it marked. Only keeping it out of those arguments avoids the finding.
How to fix it
Do not run what the model writes. Ask it for structured data, check each value against what you allow, and pass the value into fixed code: a bound SQL parameter, a command from your own list, a URL on your own host.
Added: import jsonimport sqlite3 from openai import OpenAI client = OpenAI()Added: REGIONS = {"north", "south", "east", "west"} def run_report(question: str) -> list[tuple]: reply = client.chat.completions.create( model="gpt-4o-mini", messages=[Removed: {"role": "system", "content": "Write one SQLite query for the sales data."},Added: {"role": "system", "content": 'Reply with JSON: {"region": "<name>"}.'}, {"role": "user", "content": question}, ], )Removed: sql = reply.choices[0].message.contentAdded: region = json.loads(reply.choices[0].message.content)["region"]Added: if region not in REGIONS:Added: raise ValueError("unknown region") conn = sqlite3.connect("sales.db")Removed: return conn.execute(sql).fetchall()Added: query = "SELECT SUM(total) FROM sales WHERE region = ?"Added: return conn.execute(query, (region,)).fetchall()When it can be wrong
- A reply checked against an allowlist is still reported when it ends up in the argument:
conn.execute(REPORTS[name]), wherenamecame from the model andREPORTSholds fixed queries, is reported. - Missed:
subprocess.run(cmd)withoutshell=True,urllib,aiohttp, SQL passed by keyword, output handed to a template or an HTML response, output that crosses into another function, and code in other languages.
Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.
How to silence it
Put the marker on the line of the sink call and say what makes the value safe.
Python return conn.execute(REPORTS[name]).fetchall() # skylos: ignore[SKY-D262] fixed queriesskylos baseline ., then--baseline, accepts reviewed findings and reports new ones.[tool.skylos] ignore = ["SKY-D262"]turns the rule off for the whole project.