Skip to content

Commit 8189f89

Browse files
authored
Add on unimplemented diagnostic to SqlStr (#4153)
* add diagnostic to `SqlStr` * Update note
1 parent 1dd526a commit 8189f89

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

sqlx-core/src/sql_str.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ use std::sync::Arc;
3535
/// [injection]: https://en.wikipedia.org/wiki/SQL_injection
3636
/// [`query()`]: crate::query::query
3737
/// [`raw_sql()`]: crate::raw_sql::raw_sql
38+
#[diagnostic::on_unimplemented(
39+
label = "dynamic SQL string",
40+
message = "dynamic SQL strings should be audited for possible injections",
41+
note = "prefer literal SQL strings with bind parameters or `QueryBuilder` to add dynamic data to a query.
42+
43+
To bypass this error, manually audit for potential injection vulnerabilities and wrap with `AssertSqlSafe()`.
44+
For details, see the docs for `SqlSafeStr`.\n",
45+
note = "this trait is only implemented for `&'static str`, not all `&str` like the compiler error may suggest"
46+
)]
3847
pub trait SqlSafeStr {
3948
/// Convert `self` to a [`SqlStr`].
4049
fn into_sql_str(self) -> SqlStr;

0 commit comments

Comments
 (0)