Repository navigation
FIX: TransitionPQPFile: bind PQP INSERT values to prevent SQL injection - #9743
Conversation
|
@aliviahossain The following names might be missing from the
Please consider applying the following patch: --- AUTHORS 2026-07-14 18:39:02.297639344 +0000
+++ AUTHORS.new 2026-07-14 18:39:07.597931670 +0000
@@ -14,6 +14,7 @@
- Alexandra Scherbart
- Alexandra Zerck
- Alivia Hossain
+ - Alivia Hossain
- Amanda Wein
- Andreas Bertsch
- Andreas Simon |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthrough
ChangesParameterized PQP writes
Sequence Diagram(s)sequenceDiagram
participant TargetedExperiment
participant TransitionPQPFile
participant SQLite
TargetedExperiment->>TransitionPQPFile: provide transition-library rows
TransitionPQPFile->>SQLite: bind and execute prepared INSERTs
SQLite-->>TransitionPQPFile: store rows and mapping batches
TransitionPQPFile-->>TargetedExperiment: write PQP output for round-trip reading
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/openms/source/ANALYSIS/OPENSWATH/TransitionPQPFile.cpp (1)
70-148: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse
Exception::SqlOperationFailedfor bind/step failures, matchingOSWFile.cpp's convention.
PreparedInsert::fail_()throwsException::IllegalArgumentfor every failure mode, includingsqlite3_stepexecution failures and per-column bind failures. The sibling fix for the same bug class inOSWFile.cpp(checkSqliteReturnCode_/executePreparedStatement_) deliberately usesException::SqlOperationFailedfor these runtime SQL-execution failures, reservingIllegalArgumentfor statement-preparation errors (malformed SQL text, as inSqliteConnector::prepareStatement). Since this PR explicitly aims to mirrorOpenSwathOSWWriter's approach, aligning the exception taxonomy would keep error semantics consistent for anyone catching by exception type across the two mirrored write paths.♻️ Suggested exception-type split
- [[noreturn]] void fail_(const char* op) - { - throw Exception::IllegalArgument(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, - std::string(op) + " failed: " + sqlite3_errmsg(db_)); - } + [[noreturn]] void fail_(const char* op) + { + throw Exception::SqlOperationFailed(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, + std::string(op) + " failed: " + sqlite3_errmsg(db_)); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/openms/source/ANALYSIS/OPENSWATH/TransitionPQPFile.cpp` around lines 70 - 148, Update PreparedInsert::fail_() so bind and step execution failures throw Exception::SqlOperationFailed, matching the exception taxonomy used by OSWFile.cpp; preserve Exception::IllegalArgument for statement-preparation failures handled by SqliteConnector::prepareStatement.src/tests/class_tests/openms/source/TransitionPQPFile_test.cpp (1)
208-255: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winAdd an equivalent injection regression test for
convertLightTargetedExperimentToPQP.This section only exercises the heavy path (
convertTargetedExperimentToPQP/writePQPOutput_). The PR objectives and CHANGELOG state both write paths (writePQPOutput_andconvertLightTargetedExperimentToPQP) were parameterized to fix the same SQL-injection class; only one is regression-tested here.Based on the PR objectives: "Both write paths ... now prepare each INSERT once and bind those columns per row ... same class of issue as
#9730/#9734."🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/tests/class_tests/openms/source/TransitionPQPFile_test.cpp` around lines 208 - 255, Add a parallel SQL-injection regression section covering convertLightTargetedExperimentToPQP, using a LightTargetedExperiment with the same quoted payload in a free-text compound field. Verify the conversion succeeds, the COMPOUND row count is preserved, and converting the generated PQP back retains the payload verbatim, matching the existing convertTargetedExperimentToPQP test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/openms/source/ANALYSIS/OPENSWATH/TransitionPQPFile.cpp`:
- Around line 814-821: Update the PreparedInsert construction in the transition
insertion flow to replace conn.getDB() with
Internal::SqliteHelper::getNativeHandle(conn), or use the corresponding helper
overload. Apply the same change to every PreparedInsert site in this flow while
preserving the existing SQL and transaction behavior.
In `@src/tests/class_tests/openms/source/TransitionPQPFile_test.cpp`:
- Line 224: Replace the boolean assertions in the affected test cases with the
dedicated macros: change the compounds.empty() assertion to TEST_FALSE and the
value_survived assertion to TEST_TRUE, preserving the existing expressions and
test behavior.
---
Nitpick comments:
In `@src/openms/source/ANALYSIS/OPENSWATH/TransitionPQPFile.cpp`:
- Around line 70-148: Update PreparedInsert::fail_() so bind and step execution
failures throw Exception::SqlOperationFailed, matching the exception taxonomy
used by OSWFile.cpp; preserve Exception::IllegalArgument for
statement-preparation failures handled by SqliteConnector::prepareStatement.
In `@src/tests/class_tests/openms/source/TransitionPQPFile_test.cpp`:
- Around line 208-255: Add a parallel SQL-injection regression section covering
convertLightTargetedExperimentToPQP, using a LightTargetedExperiment with the
same quoted payload in a free-text compound field. Verify the conversion
succeeds, the COMPOUND row count is preserved, and converting the generated PQP
back retains the payload verbatim, matching the existing
convertTargetedExperimentToPQP test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 896d5872-55db-47bd-8cb4-d168ed29c16e
📒 Files selected for processing (3)
CHANGELOGsrc/openms/source/ANALYSIS/OPENSWATH/TransitionPQPFile.cppsrc/tests/class_tests/openms/source/TransitionPQPFile_test.cpp
- Route native SQLite handle through Internal::SqliteHelper::getNativeHandle instead of the non-existent SqliteConnector::getDB() (SQLite is now a private dependency, so conn.getDB() no longer compiles) - Use Internal::SqliteHelper::prepareStatement in PreparedInsert; it is a free helper, not a SqliteConnector member - Throw Exception::SqlOperationFailed for bind/step runtime failures to match OSWFile's convention (IllegalArgument stays for statement preparation) - Use TEST_FALSE/TEST_TRUE for boolean assertions in the regression test
|
@timosachsenberg I'd appreciate if you could review this PR and merge it if found suitable. Thanks ! |
|
Did you benchmark it on a large PQP file? Are there performance regressions? |
|
@timosachsenberg I haven't run a formal benchmark on a large library yet, mostly because I don't have a big .pqp on hand and the repo fixtures are all small. I did go through the perf side of the change though. If you want real numbers I can run a before/after timing against develop. If you can point me at a representative large library that'd help, otherwise I can synthesize one with TargetedFileConverter. |
|
synthesize is fine |
|
@timosachsenberg Done! Benchmarked the write path on a synthesized library, as suggested. I took one of the repo transition lists (OpenSwathAssayGenerator_output_4_roundtrip.tsv) and inflated it to about 976k transitions, then wrote it out to .pqp with TargetedFileConverter, timing the write on develop vs this branch. Same input file both times, one run:
No regression and slightly faster. That lines up with what I expected: the string columns now go through a single prepared statement that compiles once and does bind/step/reset per row, instead of SQLite re-parsing a freshly concatenated INSERT for every row, and it all stays inside the same BEGIN/END TRANSACTION. The read path is unchanged, so it isn't affected. I also added a regression test that exercises the injection directly. With the parameterized writer it passes, the COMPOUND table is left intact, and the value round-trips back verbatim as data. Please review this and you may discuss further or merge the PR if everything is clear ! |
|
thats great! |




Description
As proposed and discussed, I audited the remaining OpenSWATH SQLite write paths and moved src/openms/source/ANALYSIS/OPENSWATH/TransitionPQPFile.cpp over to parameterized inserts, closing a SQL injection in the PQP writer that the earlier fix did not cover.
I rewrote both write paths (writePQPOutput_ and convertLightTargetedExperimentToPQP) so every untrusted library string (compound, peptide, protein and gene names, SMILES, sum formula, adducts, group labels, modified sequences, annotations) is now bound as a parameter instead of concatenated into the SQL. I added a small PreparedInsert helper that prepares each statement once and does bind, step, reset per row, which mirrors the pattern OpenSwathOSWWriter already uses and keeps the existing 50,000 row batching. Numeric only mapping tables and decoy updates stay inline since they carry no user text. I also added a regression test.
Checklist
Before
insert_transition_sql << "INSERT INTO TRANSITION (...) VALUES (" << i << ",'"
<< transition.transition_name << "','" << transition.Annotation << "',...); ";
conn.executeStatement(insert_transition_sql.str()); // runs through sqlite3_exec
After
PreparedInsert insert_transition(conn.getDB(),
"INSERT INTO TRANSITION (...) VALUES (?,?,?,?,?,?,?,?,?,?,?,?);");
...
insert_transition.bindText(2, transition.transition_name); // bound, not concatenated
insert_transition.bindText(6, transition.Annotation);
insert_transition.step(); // bind, step, reset per row, batching kept
Files changed
Testing
TransitionPQPFile_test and TransitionTSVFile_test pass, plus 71 of 71 TargetedFileConverter, OpenSwathDecoyGenerator and OpenSwathAssayGenerator TOPP tests (TraML to PQP to TSV round trips). Numeric columns are now bound by value, so REAL columns store full precision doubles instead of 11 digit text, which stays within FuzzyDiff tolerance.
Please review it and merge it.
Closes #9741
Summary by CodeRabbit