Skip to content

fix(pii): Prevent cycles in rule collection - #6344

Open
jjbayer wants to merge 5 commits into
masterfrom
fix/pii-recursion
Open

fix(pii): Prevent cycles in rule collection#6344
jjbayer wants to merge 5 commits into
masterfrom
fix/pii-recursion

Conversation

@jjbayer

@jjbayer jjbayer commented Sep 2, 2026

Copy link
Copy Markdown
Member

When collecting rules from a PII config, temporarily insert non-leaf nodes into the set of seen nodes to prevent cycles.

Fixes INGEST-1127

@jjbayer
jjbayer marked this pull request as ready for review September 2, 2026 10:15
@jjbayer
jjbayer requested a review from a team as a code owner September 2, 2026 10:15
@linear-code

linear-code Bot commented Sep 2, 2026

Copy link
Copy Markdown

INGEST-1127

Comment thread relay-pii/src/compiledconfig.rs
@jjbayer
jjbayer enabled auto-merge September 2, 2026 13:32
Comment thread relay-pii/src/compiledconfig.rs Outdated
Comment on lines 105 to 118
rules.insert(rule.clone()); // insert to break cycles
for rule_id in &m.rules {
collect_rules(config, rules, rule_id, parent.clone());
}
rules.remove(&rule); // don't persist intermediates
}
RuleType::Alias(ref a) => {
let parent = if a.hide_inner {
Some(rule.clone())
} else {
None
};
rules.insert(rule.clone()); // insert to break cycles
collect_rules(config, rules, &a.rule, parent);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collect_rules has a path-only cycle guard and no traversal bound

An attacker-controlled PII rule graph can define nested Multiple nodes that repeatedly reference the same non-leaf child. Because collect_rules removes intermediates after each branch, the cycle set provides no memoization or work bound: a linear-size graph can trigger exponential traversal, while a long Alias chain can exhaust the worker stack and abort processing.

Evidence
  • PiiConfig deserializes attacker-controlled rules and applications (relay-pii/src/config.rs:236-247); production project-event processing compiles the project PII config at relay-server/src/processing/utils/event.rs:424-430, and relay_validate_pii_config also compiles externally supplied JSON at relay-cabi/src/processing.rs:314-316.
  • collect_rules checks rules.contains and inserts each Multiple/Alias only while it is active (relay-pii/src/compiledconfig.rs:95-118), then removes the intermediate at lines 109 and 119; completed non-leaf nodes are not memoized.
  • A graph where each Multiple node contains rules: ["next", "next"] re-walks the same child twice at every level, producing Θ(2^N) traversal from O(N) rule definitions. A linear Alias chain still creates one recursive frame per rule because the path-only set does not bound acyclic depth.
  • Compilation occurs on the shared envelope processor pool (relay-server/src/service.rs:113-127), and PiiConfig::compiled caches only after the first unbounded compilation (relay-pii/src/config.rs:274-283); there is no depth, step, or graph-size guard before the traversal.
Also found at 2 additional locations
  • relay-pii/src/compiledconfig.rs:105-119
  • relay-pii/src/compiledconfig.rs:206-242

Identified by Warden · wrdn-dos-review · Z2S-FSJ

@jjbayer
jjbayer disabled auto-merge September 2, 2026 13:49
Comment thread relay-pii/src/compiledconfig.rs Outdated
} else {
None
};
rules.insert(rule.clone()); // insert to break cycles

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to insert before the match and remove with a drop impl?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See mstange/pdb-addr2line#71 for some prior art for this, though it might be overkill.

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.

3 participants