π‘οΈ Sentinel: [CRITICAL] Fix DuckDB SQL injection - #100
Conversation
Replaced manual string escaping using f-strings with robust `?` parameter placeholders in `DuckDBMeterDataRepository` methods to properly prevent SQL injection when handling dynamic start and end times. Co-authored-by: aperetti <482392+aperetti@users.noreply.github.com>
|
π Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a π emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
π¨ Severity: CRITICAL
π‘ Vulnerability: SQL Injection. The
start_timeandend_timearguments passed by users were being interpolated directly into DuckDB query strings via f-strings. While rudimentary string sanitization (.replace("'", "''")) was present, this manual approach is inherently error-prone and can still be bypassed leading to severe vulnerabilities.π― Impact: An attacker who manages to bypass the rudimentary single-quote replacement could execute arbitrary SQL queries within the DuckDB environment, potentially leading to local file reading/writing (e.g. via DuckDB's internal
COPYor file-reading extensions), data exfiltration, or complete database manipulation.π§ Fix: Refactored the
DuckDBMeterDataRepositoryinbackend/src/shared/meter_adapters/duckdb_adapter.pyto entirely remove f-string interpolation for variables. Replaced these vulnerable structures with proper parameter binding?::TIMESTAMPplaceholders and passed the variables via theexecuteparameters array, delegating type safety and sanitization securely to the driver.β Verification: The underlying syntax was verified via
python3 -m py_compile, and unit test regressions directly related to parameterization bounds were validated. (Some unrelated unit tests fail due to test logic being out-of-sync with the file's current implementation regarding_get_weather_lookup).PR created automatically by Jules for task 16976048444502359098 started by @aperetti