Browser Trust Boundaries
The rules a browser enforces above HTTP: cross-origin read grants, script-source limits, and defences against forged requests. Interviewers probe them because the server asks but the browser decides.
part ofWeb protocols & securityoverview, primer and where to startread it →on this pageshowhide
explore
- CORS27 questions
- Origin Header Semantics4 questions
- Simple vs Preflight Requests4 questions
- Allow and Expose Headers4 questions
- Credentialed Requests6 questions
- Origin Reflection and Wildcards5 questions
- Diagnosing Preflight Failures4 questions
- CSP26 questions
- Directives & Sources5 questions
- Nonces and Hashes4 questions
- Unsafe Keywords and Bypasses4 questions
- Report-Only and Violations4 questions
- Level 3 Source Keywords3 questions
- Policy Layering and Inheritance2 questions
- Subresource Integrity4 questions
- CSRF24 questions
- Attack Mechanics4 questions
- Synchronizer Tokens4 questions
- SameSite Defence Gaps4 questions
- Double-Submit Pattern4 questions
- Origin & Referer Checks4 questions
- Framework Token Filters4 questions
questions
77 · 3 sectionsWhy does a cross-origin request the browser blocks reach the calling script with no status code and no body?
basics
~20 sA failed CORS check replaces the server's response with a network error before script sees it - type "error", status 0, an empty header list, a null body - so the call rejects with a bare TypeError that carries no protocol detail at all.
A cross-origin lookup shows an OPTIONS request on the wire before the real one - what does the browser put in it?
basics
~10 sA CORS-preflight request: method OPTIONS, the calling page's Origin, Access-Control-Request-Method naming the method the real call will use, Access-Control-Request-Headers listing any CORS-unsafe request-header names, and Accept: /. It carries no body.
A cross-origin response carries a custom X-Gauge-Reported-At header that script cannot read - which response field makes it readable?
basics
~10 sAccess-Control-Expose-Headers, sent by the server on that response, names the extra fields script may read. Without it a cross-origin caller sees only seven names: Cache-Control, Content-Language, Content-Length, Content-Type, Expires, Last-Modified and Pragma.
What exact value does a browser put in the `Origin` request header for a page at `https://board.example.org/embed/arrivals?stop=42`?
basics
~10 sThe Origin request header carries only scheme, host and a non-default port: https://board.example.org. The path, the query, the fragment and any trailing slash are absent, and scheme and host are ASCII-lower-cased.
Your picking API answers its OPTIONS preflight with 401 - why can that cross-origin call never succeed?
basics
~20 sFor two independent reasons. The preflight is sent in credentials mode "same-origin", so cross-origin it carries no cookie and no authentication entry and cannot meet the WWW-Authenticate challenge; and 401 is not an ok status, so the preflight fails regardless.
In a Content-Security-Policy, what does default-src do for the fetch directives you did not write?
basics
~20 sdefault-src supplies the source list for any fetch directive absent from the policy. A directive you do write takes nothing from it - the written list replaces the default wholly for that resource type, and an empty list blocks everything.
In a Content-Security-Policy source list, what do the keyword sources 'self' and 'none' each mean?
basics
~20 s'self' matches the protected document's own origin - same scheme, host and port. 'none' matches nothing, so the directive carrying it permits no source at all. Both are keyword-sources, and the single quotes are part of the grammar.
A Content-Security-Policy sends script-src 'nonce-abc123'; what must an inline script element carry, and how is that value matched?
basics
~10 sThe element needs a nonce content attribute holding exactly the base64-value from the policy: 'nonce-abc123' matches nonce="abc123". The comparison is a literal ASCII case-sensitive string match, with no base64 decoding and no normalisation.
What does the Content-Security-Policy-Report-Only response header do to a resource that the policy it carries would forbid?
basics
~20 sContent-Security-Policy-Report-Only enforces nothing. A conforming browser loads and runs the resource the policy forbids, records the violation, and sends a report to the destination the policy names. It measures a policy; it does not apply one.
What does an external `<script>` element's `integrity` attribute add when the Content-Security-Policy already allows that third-party host?
basics
~20 sSubresource Integrity pins the bytes rather than the origin: a conforming browser digests the fetched file and refuses it unless a hash in the integrity attribute matches. An allowlist only settles where script may come from.
A clinic booking site authenticates owners with a session cookie; why does a form submitted from an unrelated page arrive authenticated?
basics
~20 sA browser attaches a stored cookie according to where a request is going, not according to which document caused it. The hostile page's form is addressed to the clinic, so the clinic's session cookie rides along and the request authenticates.
Your claim upload is rejected by the built-in CSRF token filter - why does answering 401 Unauthorized instead of 403 Forbidden mislead the client?
basics
~20 sA CSRF token mismatch is a provenance failure, not a credential one: the session cookie was valid, so 403 Forbidden fits. A 401 Unauthorized tells the client its credential is bad, so it discards a good session and forces a needless login.
What does the Origin request header tell a server about an incoming POST, and what does it not?
basics
~20 sA conforming user agent, not page script, writes the Origin request header, so a value that is not yours means another document initiated the request. Its absence proves nothing, and a client that is not a browser can send any value.
With no script at all, what requests can a hostile page emit at a clinic's cookie-authenticated booking endpoints?
basics
~20 sPlain markup can emit a GET through any subresource or navigation, and a form POST whose body is one of three encodings: application/x-www-form-urlencoded, multipart/form-data or text/plain. It cannot add a request header field of its own.