Skip to content

[Data Extension Create]: CWE-89 HIGH - Rust: data extension models for sql nosql ldap injection #138

Open

Description

@felickz

Target Language

rust

Library Repository / Documentation URL

To be determined from the linked findings

Data Extension Name (Optional)

cwe-89.model.yml

Library Modules / Components

See linked findings for the frameworks involved.

Data Extension Description

AI Scan reported 3 high-severity CWE-89 (sql nosql ldap injection) finding(s) in Rust public synthetic repositories that the baseline CodeQL default-setup scan did not report. Gap categories: missing-framework-model. Existing queries considered: rust/sql-injection.

Why CodeQL appears to have missed these (unverified until reproduced with a test database):

  • The SQLx sink is modeled, but no Warp source model was found. A remote-source data extension for Warp path parameters should connect the flow.
  • The installed query has no postgres::Client query sink model, and the fixed-file source also depends on local threat-model configuration.
  • rust/sql-injection exists, but installed libraries model SQLx and not Diesel sql_query. The fixed-file source may also require a local threat model.

Linked findings (gap-key: rust/data-extension-create/sql-nosql-ldap-injection)

Repo CWE Severity AI scan alert Summary
rust-vulnerable-apps CWE-89 high https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/19 The Warp path parameter is embedded in a SQL string and executed without parameter binding. A request value containing SQL syntax can alter the query, exposing or modifying database data.
rust-vulnerable-apps CWE-89 high https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/22 Untrusted file content is formatted directly into a PostgreSQL query and executed with no bound parameter. An attacker able to control the input can inject SQL expressions or additional query content.
rust-vulnerable-apps CWE-89 high https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/25 Untrusted file content is concatenated into raw SQL and passed to sql_query. Use a placeholder and bound parameter; the current construction allows attacker input to change query semantics.

Findings come from AI Scan on public synthetic apps. Hypotheses above are unverified until reproduced with a test database. Verify first whether CodeQL already covers a case (for example via a different query or threat model) before adding code.

Code Examples

See the linked alerts above for the vulnerable pattern; reduce each to a minimal test case with a safe counterpart that should not alert.

Additional References (Optional)

https://cwe.mitre.org/data/definitions/89.html

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    enhancement
    on Oct 16, 2026
  2. self-assigned this
    on Oct 16, 2026
  3. added
    CWE-89
    severity:high
    on Oct 16, 2026
  4. felickz commented on Oct 16, 2026

    @felickz
    Author

    Update: the findings below were forwarded to the linked pull request #141 for the Copilot agent to re-validate.

    Repo Location CWE Severity Pattern Context
    rust-vulnerable-apps sqli/sqli_bad_007_postgres/src/Sqli_bad_007.rs:12 CWE-89 high additional-instance-same-pattern In rust-vulnerable-apps at sqli/sqli_bad_007_postgres/src/Sqli_bad_007.rs:12: Same unsafe pattern as main.rs: untrusted input read from a file is interpolated into the SQL string passed to client.query, enabling SQL injection. CodeQL would need the model/query described as: SQL string built with format! from a Warp path parameter or file-read value and passed to postgres/sqlx query; needs the framework source and sqlx/postgres query sinks modeled.
    rust-vulnerable-apps sqli/sqli_good_001_sqlx/src/main.rs:23 CWE-89 high additional-instance-same-pattern In rust-vulnerable-apps at sqli/sqli_good_001_sqlx/src/main.rs:23: The Warp path parameter is passed to vuln_func, interpolated into a query string, and executed without parameterization. CodeQL would need the model/query described as: SQL string built with format! from a Warp path parameter or file-read value and passed to postgres/sqlx query; needs the framework source and sqlx/postgres query sinks modeled.
  5. felickz commented on Oct 31, 2026

    @felickz
    Author

    Update: additional medium and low severity findings fit this gap (gap-key rust/data-extension-create/sql-nosql-ldap-injection). They are listed with full context so the Copilot agent can re-validate each one against the proposed change and extend it where it does not cover them.

    Linked findings

    Repo CWE Severity AI scan alert Summary
    rust-vulnerable-apps CWE-89 medium https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/30 The file-controlled value is first embedded directly into the SQL text; the subsequent .bind() does not undo that injection. An attacker can include SQL syntax plus one placeholder (for example, close the quote and add a tautological expression containing ?) so the added bind count remains va...

    Handling

    Add a data extension (model-as-data). An existing query should report these once the library is modeled; add the missing sources, sinks, summaries or barriers as extension rows.

    Patterns

    • missing-source-or-sink-model (1 finding), for example rust-vulnerable-apps sqli/sqli_good_002_sqlx/src/main.rs

    Finding details

    1. rust-vulnerable-apps sqli/sqli_good_002_sqlx/src/main.rs:21 (CWE-89, medium)
    • AI Scan alert: https://github.com/codeql-forks-felickz/rust-vulnerable-apps/security/code-scanning/30
    • AI Scan message: The file-controlled value is first embedded directly into the SQL text; the subsequent .bind() does not undo that injection. An attacker can include SQL syntax plus one placeholder (for example, close the quote and add a tautological expression containing ?) so the added bind count remains valid while the altered query executes. Keep the SQL text constant (... WHERE key = ?) and bind the value only once.
    • Context for the agent: In rust-vulnerable-apps at sqli/sqli_good_002_sqlx/src/main.rs:21: The file-controlled value is first embedded directly into the SQL text; the subsequent .bind() does not undo that injection. CodeQL would need the model/query described as: SQL string built with format! from a Warp path parameter or file-read value and passed to postgres/sqlx query; needs the framework source and sqlx/postgres query sinks modeled.
    • Why CodeQL appears to miss it: missing-source-or-sink-model: SQL string built with format! from a Warp path parameter or file-read value and passed to postgres/sqlx query; needs the framework source and sqlx/postgres query sinks modeled.
    • Existing CodeQL queries considered: rust/sql-injection
    • Recommended action from the comparison: extend-existing-query (classification confidence: medium)
  6. added
    precision:very-high
    on Nov 3, 2026
  7. felickz commented on Nov 3, 2026

    @felickz
    Author

    Upstream triage

    precision:very-high Exact API/type-based fix, no heuristics. github/codeql candidate if the pattern is real-world.

    Candidate for github/codeql. Very high precision with a real-world basis and no material performance or false-positive concerns. No tags:experimental label.

    Linked pull request: #141

    Why. Adds exact-path sink rows for Diesel raw SQL entry points (sql_query, SqlQuery::sql, dsl::sql, SimpleConnection::batch_execute), matching how stock sqlx, postgres, rusqlite and mysql are modeled; Diesel has no rows upstream. Each sink is exercised with bound-parameter negatives. The str::trim summary is a small stdlib fix best sent as a separate PR. Diesel is a public Rust ORM, so this is a general model addition.

    Change Data extension (model) addition
    Target Diesel raw-SQL sinks (sql_query, SqlQuery::sql, dsl::sql, batch_execute) for rust/sql-injection; str::trim summary
    Precision assessed very-high. diesel.model.yml: four sinkModel rows with exact canonical paths, all Argument[0], each hit by a test with bound-parameter negatives. No name or regexp heuristics. core.model.yml adds one exact summary on str::trim; a trimmed tainted string stays tainted.
    Real-world basis general. Diesel is a public Rust ORM crate; sql_query, SqlQuery::sql, dsl::sql and SimpleConnection::batch_execute take raw SQL text, so interpolating request or file data into them is a real injection pattern.
    Stock overlap none. No Diesel rows in rust-all 0.2.21 or upstream main (local grep, code search). Stock sqlx/postgres/rusqlite/mysql rows are the pattern. Stock str::trim row only taints ReturnValue.Reference.
    Concerns, overlap and next steps

    What an upstream change would look like. New rust/ql/lib/codeql/rust/frameworks/diesel.model.yml with the four sinkModel rows; tests in rust/ql/test/query-tests/security/CWE-089 (diesel.rs, options.yml, SqlInjection.expected, SqlSinks.expected); change note in rust/ql/lib/change-notes. The trim row goes in a separate PR.

    Before opening an upstream pull request

    • Move the rows to rust/ql/lib/codeql/rust/frameworks/diesel.model.yml and port the Diesel test into query-tests/security/CWE-089
    • Pin the Diesel version in options.yml (2.2 is a caret range and the lockfile resolves 2.3.x)
    • Drop the sqlx MISSING case and the installer script edit; they are unrelated to the Diesel sinks
    • Send the str::trim summary separately with a taint test, or fix format! reference handling instead
    • Add a rust/ql/lib change note

    Split note. Two independent parts: the Diesel sinks (very-high, general) and the str::trim summary (a global stdlib change that affects every Rust query). Submit them as two upstream PRs. The installer script edit is not for upstream.

    This is a recommendation only. A human reviews it before any pull request is opened against github/codeql or the Community Packs repository.

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

Metadata

Metadata

Labels

CWE-89data-extension-createenhancementprecision:very-highseverity:high

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions