Skip to main content

DetectionResult

Struct DetectionResult 

Source
pub struct DetectionResult {
    pub attack_type: String,
    pub category: AttackCategory,
    pub severity: Severity,
    pub matched_pattern: String,
    pub offset: usize,
    pub message: String,
}
Expand description

一条命中:字段是只读快照,切片、告警、审计日志都从这里取,库自身不解释处置动作。

两个对调用方有实际后果的契约:

  • 每个检测器对同一输入至多产出一条:同一个 attack_type 不会重复出现。 有强弱两档的检测器先试强档,未中再试弱档,两档共用同一个 attack_type, 只有 severity 不同。
  • 弱信号固定报 Severity::Low,单独不足以构成拒绝理由,详见 severity 字段。

Fields§

§attack_type: String

检测器名,与 Detector::name 逐字相等 (tests/invariants.rs 对 32 个检测器逐一核验);同时是 Scanner::scan_with 的过滤键。

§category: AttackCategory

四大类之一:注入 / 协议 / 数据 / 文件。

§severity: Severity

严重度。弱信号(weak signal)固定为 Severity::Low(5 分): Low 不单是“轻“,更是“该形态单独出现是正常内容的常态“—— 正常网页里的 <script src=...>、源码里的单级 ../ 都落这一档,因此 单条弱信号不得构成拒绝理由(参考流水线的拒绝线是 risk.level >= RiskLevel::High,40 分)。弱信号仍然被检出、照常计入 Scanner::assess 的累加,要不要拒绝看聚合分: 多条弱信号叠加会升级(3×Low = 15 → Medium,8×Low = 40 → High)。

§matched_pattern: String

命中的具体片段,恰好是 &input[offset..offset + matched_pattern.len()], 调用方可直接用它给用户标红。

§offset: usize

matched_pattern 在输入中的字节偏移(UTF-8 字节下标,不是字符数)。

§message: String

人类可读说明(英文,供日志直接打印)。

Trait Implementations§

Source§

impl Clone for DetectionResult

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DetectionResult

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for DetectionResult

Source§

impl PartialEq for DetectionResult

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DetectionResult

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.