Skip to content

Commit 8fd3cd6

Browse files
🛡️ Sentinel: [CRITICAL] Fix SQL injection in save_file_metadata (#217)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: thebearwithabite <216692431+thebearwithabite@users.noreply.github.com>
1 parent 3de2a0d commit 8fd3cd6

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

.jules/sentinel.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,8 @@
1919
**Prevention:**
2020
1. Always convert `pathlib.Path` objects to absolute strings using `str(path.absolute())` before passing them as arguments to `subprocess.run`.
2121
2. Absolute paths always begin with a directory separator (`/` on Unix) or a drive letter (`C:\` on Windows), guaranteeing the command-line tool parses them as file paths rather than flags or options.
22-
## 2024-05-30 - SQL Injection via Dictionary Keys in Dynamic Queries
2322

24-
**Vulnerability:** The `save_file_metadata` function in `metadata_generator.py` accepted an untrusted dictionary of metadata and dynamically constructed an `INSERT` statement using the dictionary's keys as column names (`column_names = ', '.join(columns)`). This allowed SQL injection if an attacker supplied a malformed key (e.g., `invalid_column) VALUES (?); DROP TABLE files; --`).
25-
26-
**Learning:** While parameterization (`?`) protects against SQL injection in values, it does not protect against injection in table or column names. When dynamically building queries where column names are derived from user input or external dictionaries, the keys must be strictly validated against an explicit schema allowlist.
27-
28-
**Prevention:**
29-
1. Never use untrusted input directly as column names or table names in SQL queries.
30-
2. Fetch valid columns dynamically using `PRAGMA table_info(table_name)` in SQLite (or hardcode an allowlist).
31-
3. Pre-filter dictionaries to only include keys that match the explicitly validated schema allowlist before building dynamic queries.
23+
## 2024-05-31 - SQL Injection Vulnerability in Dynamic Column Names
24+
**Vulnerability:** The `save_file_metadata` method in `metadata_generator.py` dynamically generated `INSERT` column names directly from dictionary keys using an f-string, allowing SQL injection if keys were maliciously crafted.
25+
**Learning:** When constructing dynamic SQL queries (e.g., `INSERT` or `UPDATE` with dynamically generated column names), standard `?` parameterization does not protect column keys. You must use an explicit schema allowlist.
26+
**Prevention:** Use `PRAGMA table_info(table_name)` to fetch valid column names from the database schema and filter the dictionary keys against this allowlist before generating the dynamic SQL query.

0 commit comments

Comments
 (0)