📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Your API works perfectly in Postman, and CORS is already configured, but in the browser things still break: the login call returns 200 yet every following request is 401 because the cookie never comes back, and in production some calls fail with "mixed content" while others show stale data. How do you use the browser dev tools to find out what's really happening, and how do you fix each cause?

Diagnosing browser-only API failures beyond CORS with DevTools: cookies not stored or not sent (SameSite, Secure, Domain, credentials mode, third-party blocking), mixed content, HTTP caching and service workers serving stale data, and what Postman does differently from a browser.

Mid-Level Debugging Intermediate browser-devtools cookies debugging frontend http-caching mixed-content

🎯 Key points

  • Postman has no same-origin policy, no SameSite rules, no mixed-content blocking and its own cookie jar
  • Network panel: inspect Set-Cookie on the response and the warning explaining why a cookie was blocked
  • Application → Cookies shows what was stored; missing = rejected (Secure on http, SameSite=None without Secure, bad Domain)
  • Cross-origin cookies need credentials:'include' on fetch AND Access-Control-Allow-Credentials: true with an exact allowed origin
  • SameSite=Lax/Strict cookies aren't sent cross-site; third-party cookies are blocked in Safari/Firefox and restricted in Chrome
  • Mixed content: an https page calling http:// is blocked; use relative or https URLs and UseForwardedHeaders behind proxies
  • Stale data: Size column shows (disk cache)/(ServiceWorker); set Cache-Control: no-store or private, no-cache on user data
  • Fix structurally: same-origin hosting via proxy removes most cookie and CORS problems

⏱ 30-second answer

Postman isn't a browser: it ignores the same-origin policy, SameSite, mixed-content blocking and caching rules, and keeps its own cookie jar. So I reproduce in the browser with DevTools open. In Network, I click the login response and look at Set-Cookie: Chromium shows a warning icon explaining why a cookie was blocked (e.g. Secure over HTTP, SameSite=None without Secure, wrong Domain). In Application → Cookies I check what was actually stored, then check the next request's Cookie header. Typical fixes: credentials: 'include' for cross-origin calls, correct SameSite/Secure, or better, serve SPA and API from one origin. For mixed content, find the http:// URL (often a redirect built behind a proxy without forwarded headers). For stale data, the Size column shows (disk cache) or (ServiceWorker); fix Cache-Control. Trade-off: patching flags per symptom works, but same-origin hosting removes the whole class.

🗣 Full answer (senior)

How I would answer this in an interview

"First I'd stop trusting Postman as evidence. It has no same-origin policy, it doesn't apply SameSite or third-party cookie rules, it doesn't block mixed content, and it doesn't use the browser's HTTP cache or a service worker. So 'it works in Postman' only proves the endpoint works, not that a browser is allowed to use it the way the app does. I reproduce in a clean browser profile with DevTools open, 'Preserve log' ticked, and look at the evidence request by request.

For the cookie problem, I click the login response in the Network panel and open the Cookies tab. Chromium marks rejected Set-Cookie headers with a reason: 'This Set-Cookie was blocked because it had the Secure attribute but came over an insecure connection', or 'SameSite=None without Secure', or 'Domain attribute invalid for the current host'. If it was stored, I check Application → Cookies and then the next request's request headers. If the cookie's there but not sent, it's either credentials missing on a cross-origin fetch, or SameSite: the SPA on myapp.azurestaticapps.net and the API on myapi.azurewebsites.net are different sites, so a Lax cookie is never sent and a None cookie is a third-party cookie that Safari blocks outright. For example, at [company] our [customer portal] login 'worked' for Chrome users and failed for every iPhone user until we put the API behind the same domain; [support tickets dropped by X].

Mixed content shows as a console error naming the http:// URL. Usually the page is HTTPS but the API base URL, or a Location header from a redirect, is HTTP because the app behind a TLS-terminating proxy doesn't know the original scheme; UseForwardedHeaders fixes the generated URLs. Stale data I check in the Size column: (disk cache), (memory cache) or (ServiceWorker) means the server never saw the request. The mistake I see is setting random cookie flags until it works. The structural fix is one origin, correct Cache-Control on user data, and forwarded headers configured once."


Symptom → where to look → likely cause

Symptom DevTools evidence Likely cause Fix
Login 200, next call 401 Set-Cookie has warning icon Secure on http, SameSite=None without Secure, bad Domain Correct attributes; HTTPS locally (dotnet dev-certs https)
Cookie stored, not sent Request has no Cookie header credentials not include; SameSite cross-site credentials:'include' + CORS AllowCredentials, or same origin
Works in Chrome, fails in Safari Safari Web Inspector shows cookie missing Third-party cookie blocked (ITP) Same-site domains or BFF on same origin
"Mixed Content" in console Request shows (blocked:mixed-content) http:// URL from config or redirect HTTPS base URL, UseForwardedHeaders
Old data after update Size: (disk cache) / (ServiceWorker) Missing/long Cache-Control, SW caching API Cache-Control: no-store/private, no-cache; fix SW strategy
Fails only for some users Extensions or corporate proxy Ad blockers block /track, /ads paths Test in clean profile

Postman vs browser

Behaviour Browser Postman
Same-origin policy / CORS Enforced Ignored
SameSite, third-party blocking Enforced Ignored
Mixed content Blocked N/A
HTTP cache, service workers Used Not used
Forbidden headers (Origin, Cookie) Set by browser only You can set anything

Production example

A SPA on Azure Static Apps called an API on a separate azurewebsites.net host with a SameSite=None; Secure session cookie. Chrome worked; Safari and Firefox with strict tracking protection failed, about 31% of logins. Routing /api through the same custom domain (Front Door) and switching the cookie to __Host- with SameSite=Lax brought login failures to zero and removed every preflight.

🔍 What the interviewer is checking

Checks that the candidate can diagnose browser-specific failures methodically with DevTools instead of guessing, and knows what Postman hides.

Green flags

  • Explains why Postman isn't evidence
  • Reads Set-Cookie warnings and the Application panel
  • Distinguishes cookie not stored vs stored but not sent
  • Connects mixed content to proxies and forwarded headers
  • Proposes same-origin hosting as the structural fix

Red flags

  • Sets SameSite=None or disables security to make it work
  • Blames CORS for every browser error
  • Never checks caching layers

📚 Learn in depth

1. The life of a cookie, with checkpoints

login response  -> Set-Cookie: sid=...; Secure; HttpOnly; SameSite=None
                   CHECK 1: is it acceptable? (Secure needs https, None needs Secure,
                            Domain must match, __Host- rules, third-party policy)
                   -> stored in jar (Application > Cookies) or rejected (warning icon)

next fetch      -> CHECK 2: credentials mode allows cookies? (same-origin / include)
                   CHECK 3: domain + path match?
                   CHECK 4: SameSite allows this cross-site context?
                   CHECK 5: third-party cookie allowed / partitioned?
                -> Cookie: sid=...  (visible in request headers)

Each check has a matching DevTools signal. Chromium's Network → Cookies tab has a "show filtered out request cookies" option that lists cookies not sent with the reason.

2. Site vs origin, again

azurewebsites.net and azurestaticapps.net are on the public suffix list, so a.azurewebsites.net and b.azurewebsites.net are different sites, not just different origins. Cookies can't be shared between them and every call is cross-site. A custom domain (app.example.com.au, api.example.com.au) makes them same-site; path routing on one host makes them same-origin.

3. Mixed content

Browsers block active mixed content (scripts, fetch/XHR, iframes) on HTTPS pages and auto-upgrade or block passive content (images). Behind Azure Front Door, App Gateway or a Kubernetes ingress, TLS ends at the proxy and Kestrel sees http. Without ForwardedHeadersOptions, Request.Scheme is http, so Url.Action, CreatedAtRoute, OIDC redirect URIs and UseHttpsRedirection all produce or bounce through http:// URLs.

4. Caches between the code and the server

fetch() -> Service Worker (if registered) -> memory cache -> HTTP disk cache -> network -> CDN -> API

If the API sends no Cache-Control, browsers may apply heuristic caching to GETs with a Last-Modified header. A service worker using cache-first for /api/* will serve yesterday's data forever. DevTools → Application → Service Workers lets you unregister and bypass for network.

5. Reproduce reliably

Use a fresh profile or incognito, tick Disable cache while debugging (and untick it to reproduce caching bugs), Preserve log across redirects, and export a HAR to share (scrub cookies and tokens first: HAR files contain them).

Try it yourself

  1. Run an API on http://localhost:5000 that sets a Secure cookie and watch the blocked-cookie warning.
  2. Call it cross-origin without credentials: 'include' and confirm no Cookie header is sent.
  3. Put the page on https and the API on http to trigger a mixed-content error.
  4. Remove Cache-Control from a GET with Last-Modified and observe (disk cache) on reload navigation.
  5. Write a Playwright test that logs in and asserts the second request has a 200, and run it in WebKit as well as Chromium.

💻 Code

Server fixes for the three browser-only failure types, plus the client call.

// Program.cs (.NET 10)
using Microsoft.AspNetCore.HttpOverrides;

var builder = WebApplication.CreateBuilder(args);

// 1. Behind Front Door / ingress: trust forwarded scheme so generated URLs are https
builder.Services.Configure<ForwardedHeadersOptions>(o =>
{
    o.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
    o.KnownIPNetworks.Clear(); // .NET 10 name; restrict to your proxy ranges in real config
    o.KnownProxies.Clear();
});

// 2. Session cookie that the browser will accept and send (same-origin hosting)
builder.Services.AddAuthentication().AddCookie(o =>
{
    o.Cookie.Name = "__Host-sid";
    o.Cookie.SecurePolicy = CookieSecurePolicy.Always;
    o.Cookie.SameSite = SameSiteMode.Lax; // works because SPA and API share one origin
    o.Cookie.HttpOnly = true;
    o.Events.OnRedirectToLogin = ctx => { ctx.Response.StatusCode = 401; return Task.CompletedTask; }; // API: 401, not 302
});
builder.Services.AddAuthorization();

var app = builder.Build();
app.UseForwardedHeaders(); // first
app.UseAuthentication();
app.UseAuthorization();

// 3. User-specific data must not be cached by browsers or shared caches
app.MapGet("/api/me/orders", (HttpResponse res) =>
{
    res.Headers.CacheControl = "no-store";
    return TypedResults.Ok(new[] { new { Id = 1, Status = "Paid" } });
}).RequireAuthorization();

app.Run();
// Client: relative URL = same origin, no CORS, cookies sent by default, no mixed content risk
const res = await fetch('/api/me/orders', { headers: { Accept: 'application/json' } });

// If you truly must call another origin, cookies need this AND a CORS policy with AllowCredentials
// await fetch('https://api.example.com.au/api/me/orders', { credentials: 'include' });

⚠ Common mistakes

  • Mistake: Treating "works in Postman" as proof the browser should work. Why it is wrong: Postman skips SOP, SameSite, mixed content and caching. Instead: Reproduce in a clean browser profile with DevTools.
  • Mistake: Setting SameSite=None to make cookies flow. Why it is wrong: It's a third-party cookie when sites differ; Safari and Firefox block it, and it weakens CSRF protection. Instead: Same-site domains or same-origin hosting.
  • Mistake: Testing locally over HTTP with Secure cookies. Why it is wrong: Browsers reject them (localhost exceptions vary). Instead: Run HTTPS locally with dotnet dev-certs https --trust.
  • Mistake: Hard-coding http:// API base URLs in frontend config. Why it is wrong: HTTPS pages block them. Instead: Relative URLs or HTTPS per environment.
  • Mistake: Forgetting forwarded headers behind a proxy. Why it is wrong: Generated redirects and Location headers become http://. Instead: UseForwardedHeaders with known proxies configured.
  • Mistake: Cookie auth returning 302 to a login page for API calls. Why it is wrong: fetch follows it and gets HTML, which looks like a JSON parse error. Instead: Return 401/403 for API paths.
  • Mistake: No Cache-Control on user data. Why it is wrong: Heuristic caching or a service worker serves stale or another session's data. Instead: no-store or private, no-cache explicitly.
  • Mistake: Sharing raw HAR files. Why it is wrong: They contain cookies and tokens. Instead: Sanitise before sharing.

🏛 Senior insight: trade-offs

Most browser-only failures come from the deployment topology, not the code: separate hosts on public-suffix domains, TLS termination at a proxy, and a CDN or service worker in front. A senior fixes the topology once (custom domain, path-based routing to the API, forwarded headers, explicit cache policy) and adds a cross-browser smoke test, rather than tuning cookie flags per bug.

Option When it fits Cost When not to
Same origin via Front Door/ingress path routing Your SPA + your API Routing config, one domain Third-party consumers
Same-site subdomains + CORS with credentials Teams own separate hosts Preflights, SameSite=Lax still works Public-suffix default hosts
SameSite=None; Secure cross-site Unavoidable embedded/iframe cases Blocked in Safari/Firefox, CSRF risk Anything else

Measure with Playwright tests across Chromium, Firefox and WebKit in CI, and with Application Insights browser telemetry segmented by browser: a failure rate that's high on Safari only points straight at cookie policy.

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions CORS or credentials:'include' Why: Checks the browser's CORS algorithm and credentialed requests
    How to answer

    The same-origin policy stops JavaScript on one origin (scheme + host + port) from reading responses from another, so a malicious page can't read your bank's API with your cookies. CORS is the server's way to opt in. For a simple request (GET, HEAD or POST with only safelisted headers and a form or text/plain body) the browser sends it and then checks Access-Control-Allow-Origin before handing the response to your code. Anything else, such as a JSON POST, a PUT or an Authorization header, first gets an OPTIONS preflight asking permission for that method and those headers. Sending cookies needs credentials: 'include' and Access-Control-Allow-Credentials: true with an explicit origin. The key trade-off: the browser enforces it but the server's headers decide, and CORS is not security for your API: non-browser clients ignore it.

  2. When: Candidate mentions SameSite or third-party cookie blocking Why: Checks deeper SameSite knowledge and same-site vs same-origin
    How to answer

    SameSite tells the browser whether to send a cookie on cross-site requests. Strict: never cross-site. Lax: cross-site only on top-level GET navigations (clicking a link), not on cross-site POSTs, iframes or fetch. None: always, and it must also be Secure. 'Site' means scheme plus registrable domain, so app.example.com.au and api.example.com.au are the same site.

    Chromium now treats cookies without the attribute as Lax by default, which broke flows that relied on cross-site POSTs, most famously OpenID Connect form_post callbacks: the identity provider POSTs back to /signin-oidc, so the correlation and nonce cookies must be SameSite=None; Secure, which ASP.NET Core sets for you over HTTPS. The trade-off: Strict is safest but hurts UX; None is needed for embedding and federation but loses CSRF protection.

  3. When: Candidate mentions forwarded headers behind a proxy Why: Checks reverse proxy and forwarded-header configuration
    How to answer
    • A forward proxy sits in front of clients (corporate egress proxy): clients send requests through it to the internet. For HTTPS it tunnels with CONNECT. HttpClient picks it up from system settings or HTTP_PROXY/HTTPS_PROXY/NO_PROXY.
    • A reverse proxy sits in front of servers (nginx, Envoy, YARP, App Gateway, ingress): it terminates TLS, routes, load balances, caches and adds headers.

    Behind a reverse proxy, the app sees the proxy's IP and often plain http. The proxy passes the originals in X-Forwarded-For and X-Forwarded-Proto, but ASP.NET Core only applies them via the ForwardedHeaders middleware, and by default only trusts proxies on loopback. So UseHttpsRedirection sees http, redirects to https, the proxy forwards as http again: a loop.

    Fix: UseForwardedHeaders first, configured with the proxy's IPs or network in KnownProxies/known networks. Do not trust all sources, or clients can spoof their IP and scheme.

🛠 Real-world problems: how you handle them

Login works in Chrome but fails for every Safari user
Situation
A [customer self-service portal] with a React SPA on [Azure Static Web Apps default host] and an ASP.NET Core API on [a separate azurewebsites.net host], cookie session auth, about [N] daily users, [X]% on iOS.
Signals
Support tickets from iPhone users stuck on the login screen; Application Insights browser telemetry shows 401s on `/api/me` only for Safari user agents; server logs show successful sign-ins followed by unauthenticated requests from the same IP.
Investigation
Reproduced in Safari with Web Inspector: the `Set-Cookie` arrived but the cookie was never sent on the next cross-site request. Confirmed in Chrome DevTools that the cookie was `SameSite=None; Secure`, i.e. a third-party cookie because both hosts are separate sites on the public suffix list. Ran a Playwright login test in WebKit to reproduce reliably.
Resolution
Immediate: added a custom domain and routed `/api/*` through Azure Front Door to the API so SPA and API share one origin. Then switched the cookie to `__Host-sid` with `SameSite=Lax`, removed the CORS policy and the `credentials: 'include'` calls, and returned 401 instead of 302 for API paths.
Prevention
Playwright smoke tests in Chromium, Firefox and WebKit on every deploy; an ADR stating that browser clients call APIs same-origin; an Application Insights alert on 401 rate by browser; a checklist item for forwarded headers and cookie attributes.

How to tell it (STAR)

**S:** Our [customer portal] had a React SPA and an ASP.NET Core API on two different Azure default hostnames, with cookie sessions. **T:** iPhone users couldn't stay logged in and I was asked to find out why within [a day]. **A:** Postman worked, so I reproduced in Safari with Web Inspector and saw the session cookie was stored but never sent: with two separate sites it was a third-party cookie, which Safari blocks. I routed `/api` through Front Door on our custom domain so everything was same-origin, changed the cookie to `__Host-` with `SameSite=Lax`, deleted the CORS policy, and added WebKit to our Playwright smoke tests. **R:** Safari login failures went from [about 30%] to zero, preflight requests disappeared, and [support tickets about login dropped by X per week].

More in Web Basics

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me