use vyre_foundation::ir::Program;
use vyre_primitives::graph::program_graph::ProgramGraphShape;
#[cfg(test)]
use crate::security::flow_composition::dataflow_hit_cpu_ref;
use crate::security::flow_composition::{
dataflow_hit_fixture_expected, dataflow_hit_fixture_inputs, security_flow_program,
SecurityFlowOptions, SinkProjection,
};
pub(crate) const OP_ID: &str = "vyre-libs::security::taint_pollution";
#[must_use]
pub fn taint_pollution(
shape: ProgramGraphShape,
source_buf: &str,
label_set: &str,
reach_buf: &str,
hits_buf: &str,
out_scalar: &str,
) -> Program {
security_flow_program(SecurityFlowOptions::hit(
OP_ID,
shape,
source_buf,
reach_buf,
SinkProjection {
sink: label_set,
hits: hits_buf,
out_scalar,
},
))
}
pub struct TaintPollution;
impl vyre_spec::soundness::SoundnessTagged for TaintPollution {
fn soundness(&self) -> vyre_spec::soundness::Soundness {
vyre_spec::soundness::Soundness::MayOver
}
}
inventory::submit! {
vyre_foundation::operation::OperationRegistration::library(
OP_ID,
|| taint_pollution(ProgramGraphShape::new(4, 3), "source", "label_set", "reach", "hits", "out_scalar"),
Some(dataflow_hit_fixture_inputs),
Some(dataflow_hit_fixture_expected),
)
.with_category("security")
}
#[cfg(test)]
mod tests {
use super::*;
use vyre_primitives::predicate::edge_kind;
#[test]
fn one_hop_to_labeled_returns_one() {
let off = vec![0u32, 1, 1];
let tgt = vec![1u32];
let msk = vec![edge_kind::ASSIGNMENT];
assert_eq!(
dataflow_hit_cpu_ref(2, &off, &tgt, &msk, &[0b01], &[0b10]),
1
);
}
#[test]
fn no_label_hit_returns_zero() {
let off = vec![0u32, 1, 1];
let tgt = vec![1u32];
let msk = vec![edge_kind::ASSIGNMENT];
assert_eq!(dataflow_hit_cpu_ref(2, &off, &tgt, &msk, &[0b01], &[0]), 0);
}
#[test]
fn empty_source_returns_zero() {
let off = vec![0u32, 1, 1];
let tgt = vec![1u32];
let msk = vec![edge_kind::ASSIGNMENT];
assert_eq!(
dataflow_hit_cpu_ref(2, &off, &tgt, &msk, &[0], &[0xFFFF]),
0
);
}
#[test]
fn unreachable_label_returns_zero() {
let off = vec![0u32, 1, 1];
let tgt = vec![1u32];
let msk = vec![edge_kind::ASSIGNMENT];
assert_eq!(
dataflow_hit_cpu_ref(2, &off, &tgt, &msk, &[0b01], &[0b01]),
0
);
}
}