Skip to content

fix: match content.body push rules on word boundaries#234

Merged
sufforest merged 2 commits into
mainfrom
wzy/push-content-body-word-boundary
Jul 3, 2026
Merged

fix: match content.body push rules on word boundaries#234
sufforest merged 2 commits into
mainfrom
wzy/push-content-body-word-boundary

Conversation

@sufforest

Copy link
Copy Markdown
Owner

A content.body event_match — and the content keyword-highlight rules — matched against the whole body value via the whole-value glob matcher. So a bare keyword rule (pattern: "alice") only fired when the message body equalled "alice"; keyword and mention notifications essentially never worked in a sentence.

Per spec, content.body is a special case: the pattern must match a substring that starts and ends at a word boundary (the start/end of the body, or any character outside [A-Za-z0-9_] — ASCII, per the spec). So alice now fires on "hi alice" but not "malice" or "aliceb".

  • Literal keywords (no */?) use the existing whole-word search — no regex.
  • Glob patterns compile to a word-boundary-anchored regex. The regex crate is linear-time (RE2-style), so an attacker-set push-rule pattern can't cause catastrophic backtracking on the synchronous /sync eval path.
  • An absent or non-string body never matches, even for * (spec), in both the event_match and content-kind paths.
  • Existing *keyword* "contains" rules still match (the outer stars reach the string-end boundaries); the change is a strict superset of what matched before.

Adds regex as a vela-core dependency (already a workspace dep). Tests cover word boundaries, glob patterns, ?, escaped metacharacters, the *keyword* idiom, absent/non-string body, and the keyword-highlight path.

sufforest added 2 commits July 3, 2026 09:21
A content.body event_match (and the content keyword-highlight rules)
matched the whole body value, so a bare keyword rule only fired when the
message equalled the keyword — keyword and mention notifications almost
never worked. Per spec, content.body matches a substring delimited by word
boundaries: `alice` now fires on "hi alice" but not "malice".

Literal keywords use a whole-word search; glob patterns compile to a
word-boundary-anchored, linear-time regex (ReDoS-safe). An absent or
non-string body never matches, even for `*`.
smoketest-rs has its own --locked Cargo.lock; adding regex to vela-core
left it stale. Add the dependency edge.
@sufforest sufforest merged commit 59fd342 into main Jul 3, 2026
11 checks passed
@sufforest sufforest deleted the wzy/push-content-body-word-boundary branch July 3, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant