Your team keeps server-only code out of the browser by convention alone. How would you decide what enforcement to add?
answer
- blast radius first
- guard chokepoints, not every file
- prevent, detect, recover
- silent and expensive failures deserve build gates
basics
~20 sRank by blast radius. Put a build-time guard on the few modules holding credentials or privileged access, leave conventions for the rest, and keep output scanning and key rotation as the detection and recovery layers.
solid answer
~50 sStart from what leaks and what each leak costs: a formatting library crossing the boundary costs bytes, a credential reader crossing it costs a rotation and an incident. Enforcement should follow that distribution rather than the file count. Practically that means three layers — **prevent** with a build-time guard that fails when a protected module is reachable from client code, **detect** with a pipeline step that searches the built client output for a planted canary and obvious credential shapes, and **recover** with a rehearsed rotation path — because each layer covers a blind spot of the one before it. The leverage is architectural: if privileged access funnels through a few modules, a guard on each covers the whole surface and stays small enough that nobody routes around it. Where the worst outcome is only extra download weight, convention plus the team's performance controls is genuinely enough.
go deeper
Understand that conventions are not enforcement, and that a build check is what turns an agreement into a guarantee. Know which categories of code are worth that check.
Be able to describe the guard, the output scan and the rotation path, and say which failure each one actually catches rather than treating them as interchangeable safety measures.
Argue for proportionality: enforce where a mistake is silent and expensive, and show you have thought about the friction the gate creates and how teams behave when a build fails for a reason they cannot fix.
Own the tradeoff end to end — inventory privileged access, consolidate it into auditable chokepoints so enforcement stays small, then layer prevention, detection and recovery, and revisit whenever the architecture or the team changes.
## Start from blast radius, not from coverage The instinct when a convention feels fragile is to enforce it everywhere. That is the wrong first move, because the cost of a boundary violation is wildly uneven. A formatting library crossing the line costs bytes. A credential reader crossing the line costs a rotation, an incident review, and possibly a disclosure. Enforcement effort should follow that distribution, not the file count. So the first question is not "how do we check this?" but "**what leaks, and what does each leak cost us?**" Enumerate the categories actually present in the codebase — credentials, privileged access code, internal topology, rules that must not be readable, heavy render-only dependencies — and rank them. The ranking is the design input for everything below. ## Three layers, each covering what the previous cannot | Layer | Mechanism | Catches | Blind spot | |---|---|---|---| | Prevent | build-time guard on a module: client-reachable import fails the build and names the chain | every transitive import into a guarded module, on every build | anything not guarded; values already handed to client code | | Detect | pipeline step searching built client output for canaries and credential shapes | leaks through modules nobody guarded | says a value leaked, not which import caused it | | Recover | rotation, exposure scoping, use auditing | the leaks that shipped anyway | costs incident time; some leaks (topology) cannot be rotated | A strategy that stops at prevention is betting that the guard was applied everywhere it mattered — which is precisely the assumption that convention-only already failed at. A strategy that stops at detection ships defects and finds them late. The argument for all three is that each layer's blind spot is the next layer's job. ## Guard chokepoints, not files The highest-leverage decision is architectural. If every privileged operation has to pass through a small set of modules — one data-access layer, one credential reader, one internal client — then a guard on each of them covers the whole surface, and the guarded set is small enough to review as a unit. If privilege is scattered across a hundred files, no enforcement scheme will be cheap, and the right project is the consolidation rather than the checking. This also produces a better failure message. When someone violates the boundary, the build points at a named, deliberate module with an obvious server-side alternative, instead of at an arbitrary file. ## Budget for friction, and spend it once Enforcement that people route around is worse than none, because it converts an unknown risk into a believed-safe one. The practical controls: - **Keep the guarded set small** so failures are rare and meaningful rather than routine. - **Make the error actionable** — the chain plus the sanctioned alternative. - **Provide the alternative before you add the gate.** Most violations are someone doing something reasonable with no server-side route available. - **Treat suppressions as posture changes**, reviewed by whoever owns the boundary. ## A rollout that does not stop the team 1. **Inventory** what privileged access exists and where it lives; this alone usually surfaces surprises. 2. **Consolidate** it into as few modules as the codebase will tolerate in one pass. 3. **Guard the consolidated modules.** Fix the violations this exposes; they are real. 4. **Add output scanning to the pipeline** with a canary planted in a server-only module, so the detector itself is proven to work rather than assumed to. 5. **Write the rotation runbook** while nothing is on fire, and rehearse it once. 6. **Revisit when the shape changes** — a new integration, a new deployment target, a new team. ## When convention genuinely is enough Not every boundary deserves a gate. Where the reachable set holds nothing secret and the worst outcome is extra download weight, the failure is loud, cheap and self-correcting; that belongs to the team's performance controls, not a security gate. The criterion is the same one that justifies any build-time check: **enforce where the failure is silent and expensive; leave conventions where it is visible and cheap.** ## What the judgment call really is There is no single correct answer, and an interviewer is listening for whether you can price the options. The strong version reasons about what leaks and what that costs, picks enforcement proportional to that cost, funnels privilege through auditable chokepoints so enforcement stays small, and keeps recovery capability regardless of how good prevention looks — because the one thing that is certain about a boundary is that something will eventually cross it.
- How do you keep the guard from becoming a rule people route around?Keep the guarded set small so failures stay rare and meaningful, make the error name both the import chain and the sanctioned alternative, and make sure that alternative exists before the gate does — most violations are someone doing something reasonable with no server-side route available. Then review suppressions as changes to the security posture.
- How do you know the detection layer works before you need it?Plant a canary: a distinctive string in a server-only module that must never appear in client output, and a deliberately violating build in a test that the scanner is expected to fail. A detector nobody has ever seen fire is an assumption, not a control.
- When is convention genuinely enough?When nothing in the reachable set is secret and the worst outcome is extra bytes. That failure is visible, cheap and self-correcting, and it belongs to the team's performance controls rather than a security gate. Enforce where the failure is silent and expensive; leave conventions where it is loud and cheap.
saying these in an interview costs you the question
- Adds a build gate to every file and calls it defence in depth.
- Relies on developer discipline for a property the build can check.
- Assumes prevention removes the need for a rotation path.
- Buys a scanning tool without fixing the chokepoints that leak.
- Treats every boundary violation as equally serious regardless of what crossed.