ConcatSQL
ConcatSQL(concatsql) is a secure SQL database library.
You can use string concatenation to prevent SQL injection.
Supported databases:
You can configure the database backend in Cargo.toml:
[]
= { = "<version>", = ["<postgres|mysql|sqlite>"] }
Examples
Normal value
let id = Stringfrom; // User supplied input
let passwd = Stringfrom; // User supplied input
let query = query!;
assert_eq!;
for row in conn.rows.unwrap
Dangerous value
let id = Stringfrom; // User supplied input
let passwd = Stringfrom; // User supplied input
let query = query!;
assert_eq!;
for row in conn.rows.unwrap
If you did not use the query!
Cannot compile ... secure!
let id = Stringfrom;
let passwd = Stringfrom;
let query = format!;
conn.execute.unwrap; // error
When using query(<String>)
Cannot compile ... secure!
let age = Stringfrom;
let query = query! + query!; // error
Why can this library prevent SQL injection?
This is because it is achieved using Operator Overloading rather than simple string concatenation.
The query! macro returns the library's own type(WrapString).
For example, if you combine this WrapString type with a String type, the escaped String type will be combined and a new WrapString will be returned.
let bar: String = Stringfrom;
let num: i32 = 42;
let foobar42: WrapString = query!;
foobar42
sqlite3_prepare_v2;
sqlite3_bind_text;
sqlite3_bind_int;
License
MIT