Resolve URL Allow And Block Rules With Most Specific Match
Last updated: November 29, 2026
Quick Overview
Implement a policy engine that stores admin rules like `*.sharepoint.com/*` allow or `login.example.com/oauth/authorize` block, and for any URL returns the action of the most specific matching rule, where an exact host beats a wildcard, a deeper host beats a shallower one, a longer path beats a shorter one, and block wins ties.
Abnormal Security
November 29, 20260
0
0 solved
Implement a policy engine that stores admin rules like `*.sharepoint.com/*` allow or `login.example.com/oauth/authorize` block, and for any URL returns the action of the most specific matching rule, where an exact host beats a wildcard, a deeper host beats a shallower one, a longer path beats a shorter one, and block wins ties.
Links in email are rewritten and checked against tenant and global policies at Abnormal, and admins expect predictable precedence when allow and block rules overlap. The interviewer is looking for a trie over reversed host labels with nested path tries, a precise definition of specificity, and careful handling of wildcard semantics.
What the Interviewer Expects
- Stores hosts as reversed labels in a trie so suffix wildcards become prefix walks
- Separates exact-host rules from wildcard-subdomain rules
- Uses a path-segment trie with both exact and prefix markers
- Defines a total ordering of specificity and applies it consistently
- Resolves duplicate rules deterministically with block winning
- Analyzes lookup cost in terms of labels and segments, not rule count
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you support a wildcard in the middle of a host, such as `login.*.example.com`?
- How would you hot-reload rules for 10,000 tenants without blocking lookups?
- Should query strings ever participate in matching? Why or why not?
- How would you explain to an admin which rule produced a decision?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Rules: host[/path] where host may start with *. (strict subdomains only) and path may end with /* (prefix) or be exact. No path means the whole host. Precedence key: (exact host over wildcard, h...
High-Level Design
Reverse the host labels (acme.sharepoint.com becomes com, sharepoint, acme) and insert them into a trie. Each host node owns two path tries: one for rules on exactly that host and one for *. rul...
Submit Your Answer
Abnormal Security Software Engineer Interview Guide
Interview process, tips, and preparation timeline