Skip to content

SQL injection risk in MzMLSqliteHandler::writeRunLevelInformation via unescaped file path #9730

Closed

Description

@aliviahossain

Operating System and Hardware

Windows 11

OpenMS Version

pyOpenMS 3.60

Installation Method

Official Installer

Bug Description

writeRunLevelInformation builds an INSERT statement by directly concatenating the loaded file path into the SQL string, instead of using a parameterized query. The developer already left a TODO acknowledging this:

src/openms/source/FORMAT/HANDLERS/MzMLSqliteHandler.cpp, lines 887 to 890:

std::stringstream insert_run_sql;
const std::string& native_id = exp.getLoadedFilePath(); // TODO escape stuff like ' (SQL inject)
insert_run_sql << "INSERT INTO RUN (ID, FILENAME, NATIVE_ID) VALUES (" <<
run_id_ << ",'" << native_id << "','" << native_id << "'); ";

The resulting string is executed as is through conn.executeStatement(insert_run_sql.str()), which calls sqlite3_exec with no binding or escaping. native_id comes from exp.getLoadedFilePath(), which in most workflows is just a local file path chosen by the user, but it can also come from mzML metadata, batch scripts, automated pipelines, or file names supplied by someone other than the person running the tool. Any of those containing a single quote will at minimum break the query, and a deliberately crafted path or filename could inject arbitrary SQL into the sqlite database being written.

Why it matters
This runs whenever an MSExperiment gets written out as sqlite (.sqMass output, used by the OpenSWATH-related tools). Since the file path is attacker-influenceable in scripted or automated environments, this is not just a theoretical concern. It also sits right next to a working example of the correct pattern in the same codebase.

Suggested fix
SqliteConnector already has executeBindStatement(sqlite3* db, const std::string& prepare_statement, const std::vectorstd::string& data) (src/openms/source/FORMAT/SqliteConnector.cpp, around line 132), which uses sqlite3_bind_blob with ? placeholders. writeRunLevelInformation should build the INSERT with placeholders and pass native_id through that instead of concatenating it into the string, the same way parameter binding is already done elsewhere in this file.

Location
src/openms/source/FORMAT/HANDLERS/MzMLSqliteHandler.cpp:887-892

Please review the issue and assign it to me, if found suitable. Thanks !

Activity

  1. github-actions commented on Jul 12, 2026

    @github-actions
    Contributor

    Welcome @aliviahossain and thank you for your contribution to OpenMS! To help us better understand our userbase and contributors, we would appreciate if you could complete the survey at the link below. Completing this survey will help us get to your issue sooner. Thank you for your participation!

    Survey

  2. jcharkow commented on Jul 13, 2026

    @jcharkow
    Collaborator

    As @timosachsenberg said on discord this sounds like something that could be nice to have so feel free to test/fix. I would also recommend looking at the parquet implementations as we are migrating towards using those as output files in OpenSWATH so any feedback there would be greatly appreciated.

  3. aliviahossain commented on Jul 13, 2026

    @aliviahossain
    ContributorAuthor

    @jcharkow Sure, please assign me this issue. Meanwhile let me test this and also look into the parquet implementations. Will update you soon !

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions