Parameterize gemc-sqlite queries and validate the column list#13
Open
zhaozhiwen wants to merge 1 commit into
Open
Parameterize gemc-sqlite queries and validate the column list#13zhaozhiwen wants to merge 1 commit into
zhaozhiwen wants to merge 1 commit into
Conversation
The gemc-sqlite CLI built WHERE clauses and the SELECT column list with
raw f-string interpolation of user values (args.ef/vf/sf/rf and -what).
Any value with a quote broke the query, and the values were a SQL
injection vector (e.g. -ef "' OR '1'='1" returned every row).
Build the WHERE clause from "column = ?" placeholders and pass the values
as bound parameters to cursor.execute(query, params). The column list is
an identifier and can't be bound, so validate it against the table's real
columns (PRAGMA_TABLE_INFO allowlist) and reject unknown columns. Table
names remain fixed literals ("geometry"/"materials").
Verified: a normal filter returns the right row; a quoted/injection value
returns no spurious rows and does not crash; "' OR '1'='1" returns nothing
(literal, not injected); an unknown -what column is rejected (Python 3.12).
Fixes gemc#7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
gemc-sqliteCLI built WHERE clauses and the SELECT column list with raw f-string interpolation of user values (args.ef/vf/sf/rfand-what). Any value with a quote broke the query, and the values were a SQL injection vector (e.g.-ef "' OR '1'='1"returned every row).Build the WHERE clause from
column = ?placeholders and pass values as bound parameters tocursor.execute(query, params). The column list is an identifier and can't be bound, so validate it against the table's real columns (PRAGMA_TABLE_INFOallowlist) and reject unknown columns. Table names remain fixed literals.Validation: a normal filter returns the right row; a quoted/injection value returns no spurious rows and doesn't crash;
"' OR '1'='1"returns nothing (literal, not injected); an unknown-whatcolumn is rejected (Python 3.12).Fixes #7