Skip to content

πŸ›‘οΈ Sentinel: [CRITICAL] Fix DuckDB SQL injection - #100

Open
aperetti wants to merge 1 commit into
mainfrom
sentinel-duckdb-sqli-16976048444502359098
Open

πŸ›‘οΈ Sentinel: [CRITICAL] Fix DuckDB SQL injection#100
aperetti wants to merge 1 commit into
mainfrom
sentinel-duckdb-sqli-16976048444502359098

Conversation

@aperetti

Copy link
Copy Markdown
Owner

🚨 Severity: CRITICAL
πŸ’‘ Vulnerability: SQL Injection. The start_time and end_time arguments 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 COPY or file-reading extensions), data exfiltration, or complete database manipulation.
πŸ”§ Fix: Refactored the DuckDBMeterDataRepository in backend/src/shared/meter_adapters/duckdb_adapter.py to entirely remove f-string interpolation for variables. Replaced these vulnerable structures with proper parameter binding ?::TIMESTAMP placeholders and passed the variables via the execute parameters 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

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>
@google-labs-jules

Copy link
Copy Markdown
Contributor

πŸ‘‹ 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant