tinyhumansai/openhuman · error
keyword rule regex is well-formed
Error message
keyword rule regex is well-formed
What it means
Static-invariant panic in keyword_rule(): the rule table builds case-insensitive, word-boundaried alternations from hardcoded term lists, so Regex::new can only fail on a developer mistake (unescaped regex metacharacter in a term, or an empty list producing an invalid pattern). It fires at PII-rule-table initialization, before any user data is scanned.
Source
Thrown at src/openhuman/security/pii/rules.rs:37
/// A single detection rule: matches [`regex`](Rule::regex), attributes hits to
/// [`category`](Rule::category), and — if present — only counts a match when
/// [`validator`](Rule::validator) confirms it.
pub(crate) struct Rule {
pub category: PiiCategory,
pub regex: Regex,
/// Optional structural check applied to each raw match before it counts.
pub validator: Option<fn(&str) -> bool>,
}
/// Build a keyword rule: a case-insensitive, word-boundaried alternation over
/// `terms`, all attributed to `category`.
fn keyword_rule(category: PiiCategory, terms: &[&str]) -> Rule {
let alternation = terms.join("|");
let pattern = format!(r"(?i)\b(?:{alternation})\b");
Rule {
category,
regex: Regex::new(&pattern).expect("keyword rule regex is well-formed"),
validator: None,
}
}
/// Build a pattern rule from a raw regex string.
fn pattern_rule(category: PiiCategory, pattern: &str, validator: Option<fn(&str) -> bool>) -> Rule {
Rule {
category,
regex: Regex::new(pattern).expect("pattern rule regex is well-formed"),
validator,
}
}
/// Luhn checksum validation for candidate payment-card numbers. Strips
/// separators first; requires 13–19 digits.
pub(crate) fn is_luhn_valid(raw: &str) -> bool {
let digits: Vec<u8> = raw
.bytes()View on GitHub (pinned to 7491200858)
Solutions
- Escape each term with regex::escape before joining with '|'
- Add a unit test per rule asserting compilation so a bad term fails CI, not boot
- Guard against empty term lists producing '(?i)\b(?:)\b'
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at src/openhuman/security/pii/rules.rs:37 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tinyhumansai/openhuman@7491200858 (2026-08-17).
Data as JSON: /api/errors/12e0628c5774a697.
Report an issue: GitHub.