Skip to content

Security: SQL Injection via String Formatting in SQLiteExtractor#904

Open
tomaioo wants to merge 1 commit into
graphnet-team:mainfrom
tomaioo:fix/security/sql-injection-via-string-formatting-in-s
Open

Security: SQL Injection via String Formatting in SQLiteExtractor#904
tomaioo wants to merge 1 commit into
graphnet-team:mainfrom
tomaioo:fix/security/sql-injection-via-string-formatting-in-s

Conversation

@tomaioo

@tomaioo tomaioo commented Jun 23, 2026

Copy link
Copy Markdown

Summary

Security: SQL Injection via String Formatting in SQLiteExtractor

Problem

Severity: High | File: src/graphnet/data/extractors/internal/sqlite_extractor.py:L35

The SQLiteExtractor.__call__ method constructs SQL queries using Python f-strings with direct string interpolation for table names and event lists. While event_nos uses map(str, event_nos) which converts to strings, the _extractor_name is used directly in the query without sanitization. If an attacker can control the extractor name, they could inject malicious SQL. More critically, the event_list is joined with commas but not parameterized, and the table name is directly interpolated.

Solution

Use parameterized queries with ? placeholders instead of string formatting. For the IN clause, use a parameterized approach: query = f'SELECT * FROM {self._extractor_name} WHERE event_no IN ({','.join('?' * len(event_nos))})' and pass event_nos as parameters to pd.read_sql_query. Also validate _extractor_name against a whitelist of allowed table names.

Changes

  • src/graphnet/data/extractors/internal/sqlite_extractor.py (modified)

The `SQLiteExtractor.__call__` method constructs SQL queries using Python f-strings with direct string interpolation for table names and event lists. While `event_nos` uses `map(str, event_nos)` which converts to strings, the `_extractor_name` is used directly in the query without sanitization. If an attacker can control the extractor name, they could inject malicious SQL. More critically, the `event_list` is joined with commas but not parameterized, and the table name is directly interpolated.

Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
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