Skip to content

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

Open
aperetti wants to merge 1 commit into
mainfrom
sentinel-fix-duckdb-sql-injection-1715859069918372886
Open

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

Conversation

@aperetti

Copy link
Copy Markdown
Owner

🚨 Severity: CRITICAL
πŸ’‘ Vulnerability: The DuckDB meter data adapter (DuckDBMeterDataRepository) was using f-string interpolation to insert start_time and end_time into SQL queries (e.g., WHERE r.timestamp >= '{st_lit}'::TIMESTAMP). Even with basic quote escaping, this pattern is dangerous and highly vulnerable to SQL injection, particularly given DuckDB's powerful analytical capabilities.
🎯 Impact: Exploitation of this vulnerability could allow an attacker to execute arbitrary DuckDB queries, potentially leading to unauthorized data exfiltration, modification, or denial of service within the local analytical engine.
πŸ”§ Fix: Refactored all query generation methods (estimate_aggregate_consumption, get_aggregate_consumption, get_voltage_distribution, estimate_map_voltage, get_map_voltage, get_map_edge_load, get_phase_balancing) to utilize DuckDB's native parameter binding (?::TIMESTAMP) via the parameter list argument of conn.execute(). Furthermore, associated unit tests in test_duckdb_adapter.py have been properly mocked and updated to assert the secure parameterization of the generated queries. Added a critical learning entry to .jules/sentinel.md noting the vulnerability.
βœ… Verification: Ensure the test suite passes successfully.

cd backend && PYTHONPATH=. PARQUET_DIR=dummy DB_PATH=dummy python3 -m pytest tests/test_duckdb_adapter.py

PR created automatically by Jules for task 1715859069918372886 started by @aperetti

Replaced f-string interpolation of start_time and end_time with
parameterized ?::TIMESTAMP bindings in DuckDBMeterDataRepository
to prevent SQL injection and improve query caching. Updated
associated unit tests to verify parameterization.

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