T09 · Insecure Skill Coding Practices
- Location
scripts/run_read_query.py:11- Finding
Read-Only SQL Validation Can Be Bypassed by Side-Effecting SELECT Operations
- Content
View full analysis
None: normalized = _normalize_sql(sql) lowered = normalized.lower() if not lowered.startswith(READ_ONLY_PREFIXES): raise ValueError("Query must start with a read-only statement.") tokens = set(re.findall(r"[a-z_]+", lowered)) found = BLOCKED_TOKENS & tokens if found: raise ValueError(f"Blocked non-read-only token(s) found: {', '.join(sorted(found))}") ``` ### Technical Analysis The script attempts to enforce read-only behavior by checking the beginning of the SQL string and searching for a limited set of blocked lexical tokens. This is not equivalent to parsing the statement according to MySQL grammar. A statement beginning with `SELECT` is not necessarily free of side effects. In particular, MySQL supports `SELECT ... INTO OUTFILE` and `SELECT ... INTO DUMPFILE`, which can create files using the database server process and its privileges. Neither `outfile` nor `dumpfile` is blocked. The `LOAD_FILE()` function can also read files accessible to the database server. The tokenizer treats `LOAD_FILE` as the single token `load_file`, whereas the blocklist contains only `load`. Consequently, this function is not rejected. These operations remain subject to MySQL configuration, the database account's `FILE` privilege, filesystem permissions, and server-side path restrictions. Nevertheless, the script itself does not en ...[truncated 1414 chars]- Remediation
View remediation
