-
-
Notifications
You must be signed in to change notification settings - Fork 1
test: add coverage for domain_security wildcard-to-regex pattern compilation #3217
Description
Context
Discovered during code review of PR #3204 (CodeQL fixes for #3164).
Problem
In autobot-backend/security/domain_security.py, PR #3204 fixed a regex-injection vulnerability in _compile_patterns() by replacing:
regex_pattern = pattern.replace("*", ".*").replace(".", "\\.")with:
parts = pattern.split("*")
regex_pattern = ".*".join(re.escape(p) for p in parts)This also silently corrected a latent double-escaping bug in the original code: the old code replaced * with .* first, then replaced ALL . with \\. — including the . in the just-inserted .*, producing \\..* instead of .*. This means wildcard domain patterns (e.g., *.example.com) were being compiled incorrectly in production.
The fix is correct, but there are no tests covering this behavioral change. Any production config patterns that accidentally relied on the broken regex behavior will now match differently.
Expected behavior
Add unit tests for _compile_patterns() covering:
*.example.commatchesfoo.example.combut notexample.comexample.*matchesexample.combut notfoo.example.com- Literal dots are escaped (e.g.,
example.comdoesn't matchexampleXcom) - Multiple wildcards work (e.g.,
*.example.*)
Files
autobot-backend/security/domain_security.py—_compile_patterns()