Skip to main content

SKY-D211 · Security in code

SQL injection

CriticalCWE-89

CRITICAL needs outside data or a query string built in the call itself. In Python, a query that is some other non-literal value and passes no parameters is HIGH ("Likely unparameterized SQL execution"). In Go, Java, Kotlin and C#, a query string-built from values with no proven outside source is HIGH.

SQL injection happens when text from outside the program becomes part of a SQL statement instead of being passed as a separate value. Skylos reports SKY-D211 when a query that is pasted together with an f-string, +, % or .format(), or that carries outside input, reaches a database call such as cursor.execute(). In Rails controllers, it checks whether request data reaches raw SQL.

Languages
Python, TypeScript/JavaScript, Java, Kotlin, Go, C#, PHP, Ruby, Rust
Quality gate
counted toward the gate limits; a CRITICAL finding fails the gate on its own (full and diff scans)
Finding type
review
Go engine ID
SKY-G211, reported as SKY-D211
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

A visitor who types ' OR '1'='1 into a search box can read every row, and other payloads can change or delete data. One string-built query on a login or search route is enough to leak a whole table.

What Skylos flags

app/users.py · PythonReported on line 13
import sqlite3 from flask import Flask, request app = Flask(__name__)  @app.get("/users")def find_user():    name = request.args.get("name", "")    conn = sqlite3.connect("app.db")    cur = conn.cursor()    cur.execute(f"SELECT id, email FROM users WHERE name = '{name}'")    return {"rows": cur.fetchall()}

What Skylos leaves alone

app/users.py · Python
import sqlite3 from flask import Flask, request app = Flask(__name__)  @app.get("/users")def find_users():    ids = [int(value) for value in request.args.getlist("id")]    marks = ",".join("?" * len(ids))    conn = sqlite3.connect("app.db")    cur = conn.cursor()    cur.execute(f"SELECT id, email FROM users WHERE id IN ({marks})", ids)    return {"rows": cur.fetchall()}

Why Skylos leaves it alone

The f-string only inserts marks, a run of ? placeholders built from string literals and a count. Skylos treats text made only of literals and numbers as safe, and the user's values travel separately as bound parameters.

More languages

Rust

Flagged

src/lookup.rs · RustReported on line 6
use axum::extract::Path;use rusqlite::Connection; pub fn lookup(Path(name): Path<String>, db: &Connection) -> rusqlite::Result<i64> {    let query = format!("SELECT id FROM users WHERE name = '{name}'");    db.query_row(&query, [], |row| row.get(0))}

Not flagged

src/lookup.rs · Rust
use axum::extract::Path;use rusqlite::Connection; pub fn lookup(Path(name): Path<String>, db: &Connection) -> rusqlite::Result<i64> {    db.query_row("SELECT id FROM users WHERE name = ?1", [name], |row| row.get(0))}

Why Skylos leaves it alone

The SQL text is fixed. SQLite binds the name to ?1 as a value.

How Skylos decides

  1. Finds database calls: .execute(), .executemany() and .executescript(), plus async driver calls such as asyncpg fetch(), pandas read_sql() and SQLAlchemy text().
  2. Checks that the receiver looks like a database object: its name is cur, tx or transaction, or contains cursor, conn, session, engine or db, or it comes from a database call such as sqlite3.connect() or conn.cursor(). A receiver that resolves to local code with no database effect is skipped.
  3. Takes the query text (the first argument, or sql=, query= or statement=) and skips it when it cannot carry data: string literals, numbers from int(), float() or len(), placeholder runs such as ",".join("?" * len(ids)), SQLAlchemy select()/insert() constructs, psycopg sql.SQL composition and properly quoted identifiers.
  4. Reports CRITICAL when the query argument is itself an f-string, +, % or .format() expression that inserts a value Skylos cannot prove to be fixed text, or holds tainted data: a function parameter, request.*, input(), sys.argv, sys.stdin or the environment. A query built earlier into a variable from untainted values falls to the next step.
  5. Reports HIGH when the query is some other non-literal value and the call passes no parameters.
  6. For a chained call such as sqlite3.connect(db).execute(q) it is stricter: q must carry data from a real outside source, not just a helper's parameter.
  7. A project proof can recognize a native SQLite cursor initialized by a registered queue worker. It checks the source-defined registration, decorator, forwarding of the callback and arguments, and the cursor lifetime. Row values interpolated into SQL on that path produce a HIGH finding for caller-supplied data. Valid placeholder construction with values in a separate binding argument can remain quiet.
  8. The other languages have their own checks with the same idea: template literals in TypeScript, concatenated SQL passed to executeQuery(), execute() or prepareStatement() in Java, fmt.Sprintf in Go, command text in C#. Go findings come from the Go engine as SKY-G211 and are reported as SKY-D211.
  9. In Rust, Skylos follows request text and the text of a reqwest HTTP response into a SQL statement. It recognizes destructured string extractors, Actix's HttpRequest::query_string(), string concatenation and simple format! interpolation in the same function.
  10. For rusqlite, mysql and mysql_async, Skylos checks recognized connection methods. It also tracks prepared statements until execution and rusqlite row iterators until consumption. For SQLx, it follows dynamic queries, raw SQL and QueryBuilder::push through execution. Bound placeholders and push_bind keep data separate from the SQL text.
  11. An async query needs a visible poll, such as .await, and a SQLx fetch stream needs a consumer. SQL prepared and discarded in a local variable stays quiet. Calls inside closures or nested async blocks and database wrappers outside the source file can require separate analysis.

How to fix it

Keep the SQL text fixed and pass every value as a parameter. The driver sends the value separately, so it can never change the statement.

app/users.py · Python · the fix, against the flagged file
import sqlite3 from flask import Flask, request app = Flask(__name__)  @app.get("/users")def find_user():    name = request.args.get("name", "")    conn = sqlite3.connect("app.db")    cur = conn.cursor()Removed:     cur.execute(f"SELECT id, email FROM users WHERE name = '{name}'")Added:     cur.execute("SELECT id, email FROM users WHERE name = ?", (name,))    return {"rows": cur.fetchall()}

When it can be wrong

  • A helper that receives the SQL as a parameter, such as def run(cur, sql): cur.execute(sql), is reported even when every caller passes a constant. Parameters count as untrusted.
  • A table or column name checked against an allowlist is still reported, even when the check sits just above the query: the SQL check does not recognise allowlist tests.
  • A non-database object named like one (for example an SSH session) whose .execute() receives a built string can be reported.

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

  • Silence one line and say why. Only the listed rule is hidden. A bare # noqa does not hide HIGH or CRITICAL security findings.

    Python
    cur.execute(sql)  # skylos: ignore[SKY-D211] sql comes from REPORT_QUERIES
  • Accept the findings you already have with skylos baseline ., then scan with --baseline so only new ones are listed. The baseline records the absolute file path and the line, so an entry stops matching when the checkout moves or the line shifts.

  • Turning the rule off for the whole project with [tool.skylos] ignore = ["SKY-D211"] is possible but hides real injections too.

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