pub struct SafeSqlGuard {
pub policy: GuardPolicy,
}Expand description
防全表 UPDATE/DELETE 攻击守卫
通过 SQL 解析检测是否存在 WHERE 子句,对全表 UPDATE/DELETE 操作进行拦截。
§示例
use sz_orm_core::guard::{SafeSqlGuard, GuardPolicy, GuardError};
let guard = SafeSqlGuard::new(GuardPolicy::Strict);
// 拦截无 WHERE 子句的 UPDATE
assert!(matches!(
guard.check("UPDATE users SET name = 'a'"),
Err(GuardError::FullTableUpdate { .. })
));
// 允许带 WHERE 子句的 UPDATE
assert!(guard.check("UPDATE users SET name = 'a' WHERE id = 1").is_ok());Fields§
§policy: GuardPolicy策略
Implementations§
Source§impl SafeSqlGuard
impl SafeSqlGuard
Sourcepub fn new(policy: GuardPolicy) -> Self
pub fn new(policy: GuardPolicy) -> Self
创建守卫实例
Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
创建宽松守卫
Sourcepub fn check(&self, sql: &str) -> GuardResult<()>
pub fn check(&self, sql: &str) -> GuardResult<()>
检查 SQL 是否安全(拦截全表 UPDATE/DELETE)
Sourcepub fn check_update(&self, sql: &str) -> GuardResult<()>
pub fn check_update(&self, sql: &str) -> GuardResult<()>
检查 SQL 是否安全(与 check 等价,但明确表示检查 UPDATE)
Sourcepub fn check_delete(&self, sql: &str) -> GuardResult<()>
pub fn check_delete(&self, sql: &str) -> GuardResult<()>
检查 SQL 是否安全(与 check 等价,但明确表示检查 DELETE)
Trait Implementations§
Source§impl Clone for SafeSqlGuard
impl Clone for SafeSqlGuard
Source§fn clone(&self) -> SafeSqlGuard
fn clone(&self) -> SafeSqlGuard
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for SafeSqlGuard
Source§impl Debug for SafeSqlGuard
impl Debug for SafeSqlGuard
Auto Trait Implementations§
impl Freeze for SafeSqlGuard
impl RefUnwindSafe for SafeSqlGuard
impl Send for SafeSqlGuard
impl Sync for SafeSqlGuard
impl Unpin for SafeSqlGuard
impl UnsafeUnpin for SafeSqlGuard
impl UnwindSafe for SafeSqlGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more