Check Client IPs Against a CIDR Allowlist at an Internal Gateway
Last updated: November 29, 2026
Quick Overview
An internal admin gateway for ByteDance tools must only accept requests from approved office and VPN ranges written in CIDR notation; implement the membership check and explain how a prefix like /22 maps to a bitmask.
ByteDance
November 29, 20260
0
0 solved
An internal admin gateway for ByteDance tools must only accept requests from approved office and VPN ranges written in CIDR notation; implement the membership check and explain how a prefix like /22 maps to a bitmask.
Networking basics come up in ByteDance phone screens for backend and SRE-leaning roles, and gateways that restrict internal consoles are a realistic setting. The interviewer checks that you understand CIDR prefixes as bit masks and know pitfalls like trusting forwarded headers.
What the Interviewer Expects
- Explain that /n means the first n bits must match
- Convert dotted quads to a 32-bit integer and mask
- Handle edge prefixes /0 and /32
- Use the standard library for IPv6 and validation in production
- Mention not trusting X-Forwarded-For unless set by your own proxy
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- The list has 100,000 ranges: how do you make lookups fast?
- How would you support deny rules that override allow rules?
- Where should this check live: app, gateway, or network ACL?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Input: a list of allowed CIDR blocks (IPv4 and IPv6) and a client IP string. Output: True if the IP lies in any block. Invalid IPs should raise or be rejected, never treated as allowed....
High-Level Design
A CIDR block a.b.c.d/n covers every address whose first n bits equal the base's first n bits. Build a mask of n leading ones, AND both the client address and the base with it, and compare. For product...