diff --git a/crates/redos-wasm/src/lib.rs b/crates/redos-wasm/src/lib.rs index 5d6b073..8aa85e0 100644 --- a/crates/redos-wasm/src/lib.rs +++ b/crates/redos-wasm/src/lib.rs @@ -26,3 +26,11 @@ pub fn vulnerabilities(regex: &str) -> String { redos::vulnerabilities(regex, &Default::default()).map(|r| r.vulnerabilities) ) } + +#[wasm_bindgen] +pub fn dfa(regex: &str) -> String { + format!( + "{:#?}", + redos::vulnerabilities(regex, &Default::default()).map(|r| r.dfa) + ) +} diff --git a/crates/redos/src/ir.rs b/crates/redos/src/ir.rs index 53779a8..d0050b1 100644 --- a/crates/redos/src/ir.rs +++ b/crates/redos/src/ir.rs @@ -23,13 +23,13 @@ pub enum IrAssertion { NotWordBoundary, } -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Clone)] pub enum ExprConditional { Condition(Box), BackrefExistsCondition(usize), } -#[derive(Debug, PartialEq, Eq)] +#[derive(Debug, PartialEq, Eq, Clone)] pub enum Expr { /// Some token, whether its a character class, any character, etc. Token, diff --git a/crates/redos/src/lib.rs b/crates/redos/src/lib.rs index 2e425d3..9fbcfc2 100644 --- a/crates/redos/src/lib.rs +++ b/crates/redos/src/lib.rs @@ -8,17 +8,17 @@ use fancy_regex::Expr as RegexExpr; use ir::{to_expr, Expr, ExprConditional}; use vulnerability::{Vulnerability, VulnerabilityConfig}; -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -struct RegexInfo { - has_repeat: bool, - has_alternation: bool, +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct RegexInfo { + pub has_repeat: bool, + pub has_alternation: bool, } impl RegexInfo { fn merge(self, other: RegexInfo) -> RegexInfo { RegexInfo { has_repeat: self.has_repeat || other.has_repeat, - has_alternation: self.has_alternation || other.has_alternation, + has_alternation: self.has_alternation || other.has_alternation } } @@ -84,7 +84,7 @@ fn regex_pre_scan(expr: &Expr) -> RegexInfo { } ExprConditional::Condition(condition) => regex_pre_scan(condition.as_ref()) .merge(regex_pre_scan_nested(true_branch.as_ref())) - .merge(regex_pre_scan_nested(false_branch.as_ref())), + .merge(regex_pre_scan_nested(false_branch.as_ref())) } } } @@ -139,6 +139,9 @@ pub struct VulnerabilityResult { /// If this regex can be reduced to a DFA pub dfa: bool, + + /// The information about the regex + pub regex_info: RegexInfo, } /// Returns the list of vulnerabilities in a regex @@ -156,6 +159,7 @@ pub fn vulnerabilities( return Ok(VulnerabilityResult { vulnerabilities: vec![], dfa: can_be_dfa, + regex_info: RegexInfo::empty(), }); } @@ -166,6 +170,7 @@ pub fn vulnerabilities( return Ok(VulnerabilityResult { vulnerabilities: vec![], dfa: can_be_dfa, + regex_info: RegexInfo::empty(), }) } }; @@ -176,6 +181,7 @@ pub fn vulnerabilities( return Ok(VulnerabilityResult { vulnerabilities: vec![], dfa: can_be_dfa, + regex_info, }); } @@ -193,6 +199,7 @@ pub fn vulnerabilities( Ok(VulnerabilityResult { vulnerabilities, dfa: can_be_dfa, + regex_info, }) } } diff --git a/crates/redos/tests/lib.rs b/crates/redos/tests/lib.rs index 01e2362..0aab2b4 100644 --- a/crates/redos/tests/lib.rs +++ b/crates/redos/tests/lib.rs @@ -27,8 +27,8 @@ mod tests { } fn assert_safe(regex: &str, message: &str) { - let vulnerabilities = vulnerabilities(regex, &Default::default()) - .map(|r| r.vulnerabilities); + let vulnerabilities = + vulnerabilities(regex, &Default::default()).map(|r| r.vulnerabilities); assert!( vulnerabilities.is_ok(), diff --git a/website/src/routes/+page.svelte b/website/src/routes/+page.svelte index 7e65aab..4f504ab 100644 --- a/website/src/routes/+page.svelte +++ b/website/src/routes/+page.svelte @@ -1,6 +1,6 @@ @@ -29,6 +31,8 @@

AST

{ast}
+ +

IR

{irValue}
@@ -38,6 +42,12 @@
{vulns}
+
+
+

DFA

+
{dfaInfo}
+
+