SKY-D211 · Security in code
SQL injection
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
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
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
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
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
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
- Finds database calls:
.execute(),.executemany()and.executescript(), plus async driver calls such as asyncpgfetch(), pandasread_sql()and SQLAlchemytext(). - Checks that the receiver looks like a database object: its name is
cur,txortransaction, or containscursor,conn,session,engineordb, or it comes from a database call such assqlite3.connect()orconn.cursor(). A receiver that resolves to local code with no database effect is skipped. - Takes the query text (the first argument, or
sql=,query=orstatement=) and skips it when it cannot carry data: string literals, numbers fromint(),float()orlen(), placeholder runs such as",".join("?" * len(ids)), SQLAlchemyselect()/insert()constructs, psycopgsql.SQLcomposition and properly quoted identifiers. - 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.stdinor the environment. A query built earlier into a variable from untainted values falls to the next step. - Reports HIGH when the query is some other non-literal value and the call passes no parameters.
- For a chained call such as
sqlite3.connect(db).execute(q)it is stricter:qmust carry data from a real outside source, not just a helper's parameter. - 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.
- The other languages have their own checks with the same idea: template literals in TypeScript, concatenated SQL passed to
executeQuery(),execute()orprepareStatement()in Java,fmt.Sprintfin Go, command text in C#. Go findings come from the Go engine as SKY-G211 and are reported as SKY-D211. - 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 simpleformat!interpolation in the same function. - 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::pushthrough execution. Bound placeholders andpush_bindkeep data separate from the SQL text. - An async query needs a visible poll, such as
.await, and a SQLxfetchstream 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.
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
# noqadoes not hide HIGH or CRITICAL security findings.Python cur.execute(sql) # skylos: ignore[SKY-D211] sql comes from REPORT_QUERIESAccept the findings you already have with
skylos baseline ., then scan with--baselineso 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.