Repository navigation
Conversation
…on tests Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
|
@copilot A rescan of the synthetic corpus found additional findings related to this issue. Please re-run your analysis against them, confirm whether the proposed change covers each scenario, and extend it where it does not. Rows marked (variant) differ from the originally linked pattern.
Please continue on this pull request. |
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>
I checked both rescan rows against the source. Neither needs a new model.
The test passes against the newer |
There was a problem hiding this comment.
🟡 Changes recommended
The Diesel 2.2 test dependency resolves to 2.3.14, leaving the claimed 2.2 compatibility unverified until the dependency is constrained and the lockfile and expected results are regenerated.
1 open issue
What changed in this PR
Adds Diesel raw-SQL sink models for rust/sql-injection, addressing the missing-model portion of #138. Regression fixtures cover detected flows, safe parameter binding, and documented dataflow limitations.
Changes:
- Introduces a Rust model pack with four Diesel SQL-injection sinks.
- Adds real-crate test fixtures, expected results, and local threat-model configuration.
- Enables Rust in the pack-installation script.
| File | Description |
|---|---|
scripts/install-codeql-packs.sh |
Accepts Rust as a language filter. |
languages/rust/custom/test/SqlInjectionModels/SqlInjection.qlref |
Selects the stock query and inline-expectation processor. |
languages/rust/custom/test/SqlInjectionModels/SqlInjection.expected |
Records expected alerts and dataflow paths. |
languages/rust/custom/test/SqlInjectionModels/options.yml |
Configures crate dependencies and Cargo checking. |
languages/rust/custom/test/SqlInjectionModels/main.rs |
Adds vulnerable and safe cases plus known-gap fixtures. |
languages/rust/custom/test/SqlInjectionModels/Cargo.lock |
Locks fixture dependency versions. |
languages/rust/custom/test/qlpack.yml |
Defines test-pack dependencies and extensions. |
languages/rust/custom/test/default-threat-models.model.yml |
Enables local sources for tests. |
languages/rust/custom/test/.gitignore |
Excludes generated Rust test artifacts. |
languages/rust/custom/models/qlpack.yml |
Defines the Rust model extension pack. |
languages/rust/custom/models/diesel.model.yml |
Models four Diesel raw-SQL arguments as sinks. |
Review effort: Balanced
|
@copilot A rescan of the synthetic corpus found additional medium and low severity findings that fit this gap. Please re-run your analysis against each finding below, confirm whether the proposed change covers each scenario, and extend it where it does not. Keep each change minimal with a positive and a negative regression test, keep every existing test passing, and do not broaden scope. The same findings are listed in the matching comment on issue #138. Linked findings
HandlingAdd 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
Finding details1. rust-vulnerable-apps sqli/sqli_good_002_sqlx/src/main.rs:21 (CWE-89, medium)
Please continue on this pull request. |
Co-authored-by: felickz <1760475+felickz@users.noreply.github.com>

📝 Data Extension Information
diesel.model.ymldiesel::query_builder(sql_query,SqlQuery::sql),diesel::expression::sql_literal(dsl::sql),diesel::connection(SimpleConnection::batch_execute)🎯 Description
What This Data Extension Models
An AI scan reported 3 CWE-89 findings that
rust/sql-injectionmissed. I reproduced each one in a test database built from the real crates. Only one is a missing model:sql_querywith concatenated file contentpostgres::Client::querywith file contentfilesource onstd::fs::read_to_string). Alerts only whenlocal/fileis enabled.param().then(|p| async move { sqlx::query(..) })async moveblock as captured content, but nothing in user code awaits the block, so the taint never enters its body. A summary model that tried to force the call had no effect.MISSING:. The.map(|p| {..})variant is detected.There is also a separate standard-library false negative, marked
MISSING::format!("{}", s.trim())drops taint. Formattingsdirectly, or concatenatings.trim()with+, is detected.Supporting changes:
languages/rust/custom/models, withlibrary: trueandextensionTargets: codeql/rust-all.languages/rust/custom/test. It depends oncodeql/rust-queriesplus the model pack, and enables thelocalthreat model the same way upstreamcodeql/rust-testsdoes. Crates come fromqltest_dependencies.Cargo.lockis committed; generatedCargo.toml,lib.rsandtarget/are gitignored.scripts/install-codeql-packs.shnow acceptsrustas a language.Threat Model
These are sinks, so they apply under any threat model. The Diesel test cases use
local/filesources (as in the reported findings) and aremoteWarp source. Under default setup (remoteonly), the file-based cases needlocalorfileenabled.Example Vulnerable Code
Example Safe Code
📦 Extension Details
Extension YAML
Access Path Explanation
Rust MaD rows key on the canonical path of the function where it is defined, not on the path used to call it. Both
diesel::sql_queryanddiesel::dsl::sql_queryresolve todiesel::query_builder::functions::sql_query. Trait methods use the<Trait>::methodform, sobatch_executematches everySimpleConnectionimplementation (SqliteConnection,PgConnection, ...). Each row marks the raw SQL string,Argument[0], as the sink. I read the canonical paths off the static call targets in the extracted test database.🧪 Testing
codeql database createorcodeql test extract)codeql query run --additional-packs=<model-pack-dir>)codeql test run --additional-packs=<model-pack-dir>)The model pack resolves through
codeql-workspace.yml, so neither command needs--additional-packs.📋 Checklist
languages/[language]/custom/src/). Placed in the dedicated model packlanguages/rust/custom/modelsinstead, because a query pack incustom/srccannot declareextensionTargets.qlpack.ymlincludesdataExtensionsconfiguration🔗 References
rust/sql-injection(queries/security/CWE-089/SqlInjection.ql)Note: This data extension was developed following CodeQL Models as Data best practices.