Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions rust/ql/lib/codeql/rust/frameworks/rusqlite.model.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extensions:
- addsTo:
pack: codeql/rust-all
extensible: sinkModel
data:
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::Connection>::execute", "Argument[0]", "sql-injection", "manual"]
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::Connection>::execute_batch", "Argument[0]", "sql-injection", "manual"]
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::Connection>::prepare", "Argument[0]", "sql-injection", "manual"]
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::Connection>::prepare_with_flags", "Argument[0]", "sql-injection", "manual"]
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::Connection>::query_row", "Argument[0]", "sql-injection", "manual"]
- ["repo:https://github.com/rusqlite/rusqlite:rusqlite", "<crate::Connection>::query_row_and_then", "Argument[0]", "sql-injection", "manual"]
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
| file://:0:0:0:0 | [summary param] 0 in lang:alloc::_::crate::fmt::format | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::crate::fmt::format | MaD:24 |
| file://:0:0:0:0 | [summary param] self in lang:alloc::_::<crate::string::String>::as_str | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::string::String>::as_str | MaD:22 |
| file://:0:0:0:0 | [summary param] 0 in lang:alloc::_::crate::fmt::format | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::crate::fmt::format | MaD:34 |
| file://:0:0:0:0 | [summary param] self in lang:alloc::_::<crate::string::String>::as_str | file://:0:0:0:0 | [summary] to write: ReturnValue in lang:alloc::_::<crate::string::String>::as_str | MaD:32 |
| file://:0:0:0:0 | [summary param] self in repo:https://github.com/seanmonstar/reqwest:reqwest::_::<crate::blocking::response::Response>::text | file://:0:0:0:0 | [summary] to write: ReturnValue.Variant[crate::result::Result::Ok(0)] in repo:https://github.com/seanmonstar/reqwest:reqwest::_::<crate::blocking::response::Response>::text | MaD:10 |
| main.rs:4:5:4:8 | 1000 | main.rs:4:5:4:12 | ... + ... | |
| main.rs:4:12:4:12 | i | main.rs:4:5:4:12 | ... + ... | |
Expand Down
Empty file.
20 changes: 20 additions & 0 deletions rust/ql/test/library-tests/frameworks/rusqlite/Rusqlite.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import rust
import codeql.rust.security.SqlInjectionExtensions
import codeql.rust.Concepts
import utils.test.InlineExpectationsTest

module RusqliteTest implements TestSig {
string getARelevantTag() { result = ["sql-sink"] }

predicate hasActualResult(Location location, string element, string tag, string value) {
exists(SqlInjection::Sink sink |
location = sink.getLocation() and
location.getFile().getBaseName() != "" and
element = sink.toString() and
tag = "sql-sink" and
value = ""
)
}
}

import MakeTest<RusqliteTest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[workspace]

[package]
name = "rusqlite-test"
version = "0.1.0"
edition = "2021"

[dependencies]
rusqlite = { version = "0.33", features = ["bundled"] }

[[bin]]
name = "rusqlite"
path = "./main.rs"
50 changes: 50 additions & 0 deletions rust/ql/test/library-tests/frameworks/rusqlite/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

use rusqlite::Connection;

#[derive(Debug)]
struct Person {
id: i32,
name: String,
age: i32,
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
// Get input from CLI
let args: Vec<String> = std::env::args().collect();
let name = &args[1];
let age = &args[2];

let connection = Connection::open_in_memory()?;

connection.execute( // $ sql-sink
"CREATE TABLE person (
id SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
age INT NOT NULL
)",
(),
)?;

let query = format!("INSERT INTO person (name, age) VALUES ('{}', '{}')", name, age);

connection.execute(&query, ())?; // $ sql-sink

let person = connection.query_row(&query, (), |row| { // $ sql-sink
Ok(Person {
id: row.get(0)?,
name: row.get(1)?,
age: row.get(2)?,
})
})?;

let mut stmt = connection.prepare("SELECT id, name, age FROM person")?; // $ sql-sink
let people = stmt.query_map([], |row| {
Ok(Person {
id: row.get(0)?,
name: row.get(1)?,
age: row.get(2)?,
})
})?;

Ok(())
}
3 changes: 3 additions & 0 deletions rust/ql/test/library-tests/frameworks/rusqlite/options.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
qltest_cargo_check: true
qltest_dependencies:
- rusqlite = { version = "0.33", features = ["bundled"] }