Skip to main content

SKY-D262 · Security in code

LLM output run as code, SQL, a shell command or a URL

CriticalCWE-1426

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
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

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

reports/ask.py · PythonReported on line 18
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

reports/digest.py · Python
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

  1. Runs with --danger on Python files that mention an LLM library (openai, anthropic, litellm, langchain and similar).
  2. Marks as model output the result of a model call (the same calls as SKY-D261: .chat.completions.create, .responses.create, .messages.create, .invoke, .generate and so on) and every variable assigned from an expression that contains model output, such as reply.choices[0].message.content or json.loads(reply...).
  3. Reports CRITICAL when model output appears anywhere in: the first argument of eval(), exec() or os.system(); the command of a subprocess.* call with shell=True; the first argument of a call ending in .execute, .executemany or .executescript; or the URL of requests.get/post/put/patch/delete/request or the same httpx calls.
  4. 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.

reports/ask.py · Python · the fix, against the flagged file
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]), where name came from the model and REPORTS holds fixed queries, is reported.
  • Missed: subprocess.run(cmd) without shell=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 queries
  • skylos baseline ., then --baseline, accepts reviewed findings and reports new ones.

  • [tool.skylos] ignore = ["SKY-D262"] turns the rule off for the whole project.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.