fix(findings): use parameterized queries to prevent SQL injection in list - #481
Merged
Conversation
…list
The severity and file filters in list_findings() interpolated user input
directly into SQL strings via format!():
format!("f.severity = '{}'", s.to_uppercase())
format!("f.file_path LIKE '%{}%'", f.replace('"', "'"))
This allowed SQL injection through --severity or --file flags. The
f.replace('"', "'") only escaped double-quotes, not the single-quote
SQL string delimiter, making it ineffective.
Fix: build WHERE clause with ? placeholders and pass user input via
rusqlite::params!, matching the pattern already used by dismiss() and
reopen().
SQL injection: The severity and file filters in list_findings() interpolated user input directly into SQL strings via format!(). Flaky test: data_dir tests mutated CODECORA_HOME without synchronization, causing intermittent failures when tests ran in parallel.
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.
What
Fixes SQL injection vulnerabilities in
cora findings listcommand.Vulnerable code (before)
Two filters interpolated user input directly into SQL via
format!():The
f.replace('"', "'")only escaped double-quotes — not single-quotes,which are the SQL string delimiter. This made it completely ineffective.
Attack vectors
--severitycritical' OR 1=1 --WHERE f.severity = 'CRITICAL' OR 1=1 --'--file'; DROP TABLE findings; --LIKE '%'; DROP TABLE findings; --%'Fix
Use
?placeholders +rusqlite::params!— the same pattern already usedby
dismiss()andreopen()in the same file.Why
Cora is a security tool. Shipping SQL injection in its own CLI undermines
credibility. While exploitability requires local access, this is a
defense-in-depth issue and a best-practice violation.
Testing
cargo test --bin cora— 782 pass, 0 failcargo clippy -- -D warnings— cleancargo fmt --all— cleancora findings list --severity "critical' OR 1=1 --"now returnsempty results (no matching severity) instead of leaking all findings