Your service returns cookies no application code writes; where do these framework-emitted cookies come from and what do they break?
answer
- nobody wrote it, something did
- session touch, not session write
- each component configures its own
- a cookie on a response defeats shared caches
- proxies add cookies the app cannot see
basics
~20 sFramework components write them as a side effect - session, request-forgery protection, locale, flash - as do proxies ahead of it. Each carries its own scope and flags, so app-wide defaults and delete helpers miss it, and shared caches stop storing the response.
solid answer
~50 sCookies appear without a handler asking because several parts of a framework write them as a side effect: the session subsystem issues an identifier the first time anything touches the session, request-forgery protection may place a token, locale resolution and flash messaging keep their state in cookies, and reverse proxies or load balancers in front of the application add affinity cookies of their own. Three things break. First, each component has **its own** cookie configuration, so application-wide defaults and hardening may not reach it. Second, your delete helper does not match a scope you never chose, so these cookies are the stubborn ones. Third, a response that carries a cookie is generally not stored by shared caches, so an anonymous page that starts emitting a session cookie quietly loses its edge caching and sends traffic to the origin.
go deeper
Know that cookies can appear without any handler writing one, most often the session identifier, and that the framework issues it as a side effect of something touching the session.
Explain that each emitting component has its own cookie configuration, so application defaults and delete helpers built on them can miss the cookie entirely.
Show the production instinct: an unexpected Set-Cookie on a cacheable route is a caching regression, and you can bisect the component chain to find the author rather than guessing.
Treat the emitted-cookie set as an owned inventory with a policy - which routes may emit cookies at all, who configures each one's scope and flags, and a test that keeps anonymous routes cookie-free.
## Who writes a cookie nobody asked for Several layers can add a `Set-Cookie` to a response that no handler touched: - **The session subsystem.** The identifier cookie is created the first time anything in the request touches the session - including code that only *reads* it, or a component that stores something incidental such as a redirect target or a locale choice. One stray touch on an otherwise anonymous route gives every visitor a session. - **Request-forgery protection.** Some designs hand the token to the client in a cookie so page scripts can send it back on writes. - **Locale and time-zone resolution.** A resolver that remembers a choice generally remembers it in a cookie. - **Flash or one-shot messaging.** Where there is no server-side session, the message rides in a cookie that is written on one response and cleared on the next. - **Infrastructure in front of the application.** Reverse proxies, load balancers and edge caches add affinity or routing cookies that never pass through framework code at all, which is why the application cannot find them in its own configuration. ## Why they resist your cookie policy Each of these components carries **its own** cookie settings - name, path, domain, lifetime, security flags - resolved from its own configuration rather than from the application-level defaults your call sites inherit. Consequences worth stating in an interview: 1. **Hardening misses them.** Turning on the security flags for application cookies does not necessarily change a cookie a component emits; you have to find and set that component's own configuration. 2. **Deletions do not match.** Removing the cookie needs the name, domain and path that component chose, not the application defaults your delete helper fills in - which is why these are the cookies that keep coming back. 3. **Ownership is unclear.** The name gives no hint of which layer produced it, and a cookie added by infrastructure is invisible to every search through the application's source. ## The failure that actually costs money A response carrying `Set-Cookie` is, as a rule, not stored by shared caches - the cookie is per-client state, and a cache that served that response to a second client would hand over someone else's state. So the moment an anonymous, cacheable page begins emitting a session cookie: | Before | After | |---|---| | Edge serves most requests | Edge stores nothing for that route | | Origin sees a fraction of traffic | Origin sees all of it | | No per-visitor server state | One session entry per visitor, including crawlers | The change that causes it is usually tiny and unrelated - a new component added to the chain that reads the session, a template helper that touches it, an error handler that stores a message. Nothing fails, latency creeps up, the session store grows, and the cause is several deploys back. ## How to investigate 1. **Look at raw response headers per route.** Use a client that prints every `Set-Cookie` line, on an anonymous request with no cookie jar, for a route that should emit none. 2. **Compare routes.** A route that emits nothing and a route that emits a session cookie differ by whichever component runs on one and not the other. 3. **Bisect the chain.** Disable or reorder the components that can write cookies and re-request; the one whose removal silences the header is the author. 4. **Ask whether the session was touched at all**, rather than whether anything wrote to it - creation is triggered by access in many designs, not by mutation. 5. **If nothing in the application accounts for it**, request the origin directly and compare with the response through the proxy; a cookie that appears only through the proxy was added there. ## Controlling them - Keep anonymous, cacheable routes off any component that touches session state, and assert it: a test that requests such a route and fails if the response carries any `Set-Cookie` is cheap and catches the regression at the commit that introduces it. - Configure each emitting component explicitly - name, scope, flags - rather than assuming it inherits application defaults. - Record the full inventory of cookies your service can emit, with the owner of each. It is the document that makes a later deletion, a scope change or a security review possible. - Keep application cookies and component cookies on the same small set of scopes, so one deletion routine can cover both.
- How do you confirm which component emitted a particular cookie?Request the route anonymously with a client that prints every response header, then compare routes that do and do not emit it. Bisect by disabling or reordering the components that can write cookies. If the application never emits it, compare a direct origin request with one through the proxy - infrastructure cookies never appear in application code.
- Why does a page that starts creating sessions raise origin load rather than just memory use?Because the response now carries a cookie, and shared caches decline to store per-client responses. The route stops being served from the edge and every request reaches the origin. The session store growing by one entry per visitor is the second cost, not the first one you notice.
- You set application-wide cookie security flags, yet one framework-emitted cookie still lacks them. Why?Because that component resolves its cookie attributes from its own configuration, not from the application defaults your write helper applies. Find the component's own settings and set them there. If the cookie comes from a proxy in front of the application, no application setting will ever reach it.
saying these in an interview costs you the question
- Assumes every cookie on a response came from application code
- Thinks a session is created only when something writes to it
- Believes application cookie defaults cover framework-emitted cookies
- Does not connect a Set-Cookie header to losing shared-cache hits
- Never considers a proxy or load balancer as the cookie's author