Skip to content

SQL injection in TransitionPQPFile PQP writer (same pattern as #9730) #9741

Closed

Description

@aliviahossain

Operating System and Hardware

Windows 11 10.0.26100

OpenMS Version

pyOpenMS 3.6.0

Installation Method

Other

Bug Description

Built from source.

While following up on the SQLite injection fix in #9730, I went through the rest of the OpenSWATH SQLite write paths to see whether the same concatenation pattern showed up elsewhere. It does, in src/openms/source/ANALYSIS/OPENSWATH/TransitionPQPFile.cpp.

The PQP writer builds its INSERT statements by concatenating string fields directly into SQL and then running them through conn.executeStatement() (which calls sqlite3_exec), with no escaping or binding. For example, around lines 772-783:

insert_transition_sql << "INSERT INTO TRANSITION (...) VALUES (" << i << ",'"
<< transition.transition_name << "'," ... << transition.fragment_type << "','"
<< transition.Annotation << "'," ...

The same pattern repeats for peptide.id, peptide.getPeptideGroupLabel(), and compound.id (lines ~835-876), and again in the second write path lower down (~1327-1450), which also concatenates compound_name, sum_formula, smiles, adducts, the protein accession, the gene name, and the modified peptide sequence.

These values come from externally supplied transition libraries (TraML/TSV/CSV converted to PQP), so they are untrusted. A name containing a single quote breaks the statement, and a crafted name can inject arbitrary SQL. It is the same class of issue as #9730, just in a different file.

Worth noting: the sibling writer OpenSwathOSWWriter.cpp was already migrated to bound statements (makeInsertStatement + bindRow, lines 386-449), so TransitionPQPFile.cpp looks like the one file in this area that never got moved over.

Suggested fix

One detail that makes this slightly more involved than #9730: instead of a single INSERT, this code accumulates thousands of statements into a stringstream and flushes them in batches of 50,000 through one executeStatement call. A plain executeBindStatement (which runs a single statement with a single bind set) does not map onto that directly. The cleaner approach here is to mirror the OSW writer's pattern: prepare the statement once and bind/step/reset per row inside the transaction, which keeps the batching. Only the string columns need placeholders; the numeric columns (mz, charge, intensity, decoy flags) can stay inline, the same way run_id_ was kept inline in the #9730 fix.

I would also add a regression test in the same spirit as the one added for #9730: round-trip a small library that has a ' and a ;-- in one of the name fields and confirm the values survive intact.

Assign me this issue if it is found suitable. Thanks !

Activity

  1. coderabbitai commented on Jul 14, 2026

    @coderabbitai
    Contributor
    🔗 Related PRs

    #7924 - BugFix : Fixed Targetedfileconverter crash [closed]
    #9734 - Fix SQL injection in MzMLSqliteHandler::writeRunLevelInformation (#9730) [merged]
    #9737 - Make SQLite a fully private dependency (no SQLite type in installed headers) [open]


    📝 Issue Planner

    Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.

    • Create Plan

    🧪 Issue enrichment is currently in open beta.

    You can configure auto-planning by selecting labels in the issue_enrichment configuration.

    To disable automatic issue enrichment, add the following to your .coderabbit.yaml:

    issue_enrichment:
      auto_enrich:
        enabled: false

    💬 Have feedback or questions? Drop into our discord!

  2. jcharkow commented on Jul 14, 2026

    @jcharkow
    Collaborator

    Proposal looks good, feel free to open a PR with the proposed changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions