Before your interview: what happens when you type a URL, security edition
The classic interview question, answered the way a security interviewer wants to hear it: every hop from the address bar to the rendered page is a trust decision. DNS, TLS, HSTS, cookies, the same-origin policy and response headers, what breaks at each step, and the follow-up questions to expect.
“What happens when you type a URL into the browser and press Enter?” is the most common open question in web security interviews, for pentester, AppSec and security engineer roles alike. It sounds like a networking quiz. It isn’t one.
The interviewer wants to see two things. First, whether you can hold a whole system in your head, from a keystroke to pixels. Second, and this is what separates a security answer from a networking answer, whether you notice that every hop is a trust decision: something tells the browser where to go, something proves who is on the other end, and something decides what the page is allowed to do. Each of those can lie, and each has a control with a known limit.
This is the first part of a series on security topics that come up in interviews. Every part has the same shape: the mechanism, the questions with short and deep answers, the wrong answers that cost points, and a few questions to test yourself.
TL;DR#
- DNS tells the browser where to go, and by default nobody authenticates the answer. The real protection against a DNS lie is TLS: a wrong server cannot present a valid certificate for the name. Unless the attacker can get one, which DNS control makes possible.
- The first request may still be plain HTTP. HSTS stops that, but only from the second visit on, unless the domain is on the browser’s preload list.
- The padlock means “encrypted, to a server that proved it controls this name”. It says nothing about whether the site is honest. And certificate revocation mostly doesn’t work in browsers.
- Cookies are sent automatically. Their attributes (
Secure,HttpOnly,SameSite) decide whether they leak, can be stolen by script, or ride along on a forged cross-site request. - The same-origin policy stops a page from reading another origin’s responses, not from sending requests to it. CORS relaxes that policy; it never adds protection.
The mechanism, hop by hop#
A compressed view of the path. Every line is a place where an attacker can sit and a control that has to hold:
address bar → URL parsing, HSTS/preload lookup, Safe Browsing
DNS → name → IP address (unauthenticated by default)
TCP / QUIC → connection to that IP
TLS → key exchange, certificate (proves the name, encrypts)
HTTP → request + cookies (redirects, first plain-HTTP hop)
server side → CDN / load balancer / app (where TLS actually ends)
response → headers, HTML, subresources (CSP, SOP, mixed content, SRI)
1. The address bar#
Before anything goes on the network, the browser parses the input. Is it a URL or a search? Which scheme? If the user typed bank.example without a scheme, older behavior was to try http:// first. Modern browsers increasingly try HTTPS first (HTTPS-First or HTTPS-Only modes), but as a defender you can’t assume every user has that.
Two security checks happen here already. The browser looks up the host in its HSTS list (the built-in preload list and any HSTS policy it remembers from earlier visits) and, if it is there, rewrites http:// to https:// locally, before a single packet is sent. It may also check the URL against a malware/phishing blocklist such as Google Safe Browsing. Internationalized domain names are shown in punycode (xn--...) when they mix scripts suspiciously, which is the browser’s defense against homograph attacks, look-alike domains such as a Cyrillic “а” in place of a Latin “a”.
2. DNS: where is it?#
The browser needs an IP address. It asks its own cache, then the operating system (which also reads the hosts file), then a recursive resolver, usually the ISP’s, the company’s, or a public one. The resolver walks the hierarchy (root → .example TLD → the domain’s authoritative server) and caches the answer for its TTL.
Classic DNS runs over UDP port 53, in plaintext, with no authentication of the answer. That opens several attacks:
- On-path spoofing: anyone on the network path (hostile Wi-Fi, a compromised router) can answer first with a fake IP.
- Cache poisoning: an off-path attacker races fake answers into a resolver’s cache, so everyone using that resolver gets them. Dan Kaminsky’s 2008 attack made this practical; the fix was randomizing source ports, which makes guessing much harder but not impossible.
- Registrar or DNS-provider takeover: the attacker doesn’t fake answers, they change the real records. A stolen registrar login is the cheapest route.
- Subdomain takeover: a
CNAMEstill points to a cloud resource (a storage bucket, a deleted app) that the company no longer owns, and the attacker claims it.
Two controls are often confused. DNSSEC signs DNS records, so a validating resolver can detect forged answers. It provides integrity, not privacy, and it only helps if the domain signs and the resolver validates. DNS over HTTPS / over TLS (DoH, DoT) encrypts the hop from your device to the resolver. That gives privacy and stops tampering on the local network, but the resolver still sees every query, and it does nothing about a poisoned or hijacked answer upstream.
3. The connection#
The browser opens a TCP connection to port 443 (or, for HTTP/3, a QUIC connection over UDP). From a security perspective this step matters less than the ones around it. The IP address is visible to everyone on the path, so anyone watching knows which server you connect to, even if not which page.
4. TLS: who is on the other end?#
In TLS 1.3, the client sends a ClientHello with its supported cipher suites, a key share, and the SNI (Server Name Indication), the host name it wants. The SNI is in plaintext unless both sides support Encrypted Client Hello (ECH), so HTTPS alone does not hide which site you visit.
The server answers with its key share, its certificate chain, and a signature over the handshake that proves it holds the certificate’s private key. Both sides derive session keys from an ephemeral Diffie-Hellman exchange, which gives forward secrecy: stealing the server’s private key later does not decrypt recorded traffic.
The browser then decides whether to trust the certificate:
- The chain leads to a root certificate in the browser’s or OS’s trust store.
- The name in the certificate’s Subject Alternative Name matches the host.
- The dates: the certificate is valid now.
- Certificate Transparency (CT): Chrome and Safari require proof (SCTs) that the certificate was logged in public, append-only CT logs. That doesn’t stop mis-issuance, but it makes it visible: a domain owner can monitor the logs for certificates they didn’t request.
- Revocation: in theory, a revoked certificate is rejected. In practice, browsers don’t do live OCSP checks by default (they would fail open anyway when the check times out, because blocking would break too many sites). Chrome uses a curated list (CRLSets), Firefox a compressed list of all revocations (CRLite), and Let’s Encrypt, the largest CA, stopped running OCSP in 2025. Short certificate lifetimes are the industry’s real answer to revocation.
If any check fails, the browser shows a full-page warning. If the site uses HSTS, the user can’t click through it, which matters, because users click through warnings.
TLS 1.3 also offers 0-RTT resumption, where the client sends data in its first message. That data can be replayed by an attacker, so servers should only accept it for idempotent requests.
5. The HTTP request#
Now the browser sends the request: method, path, Host header, other headers, and every cookie that matches the domain and path. That last part is automatic, and it is the root of a whole class of attacks.
If the first request went over plain HTTP (no HSTS, no preload, no HTTPS-First), it can be intercepted and modified. SSL stripping, shown by Moxie Marlinspike in 2009, does exactly that: the attacker keeps the victim on HTTP and talks HTTPS to the real server. HSTS (Strict-Transport-Security) closes the gap, but it is trust on first use: the browser only knows about it after a successful HTTPS visit. The HSTS preload list, shipped inside browsers, covers the first visit too.
Cookie attributes decide what a stolen or forged request can do:
Secure: only sent over HTTPS, so it doesn’t leak on a plain-HTTP hop.HttpOnly: not readable from JavaScript, so an XSS bug can’t simply read the session cookie (it can still use the session from the victim’s browser).SameSite=LaxorStrict: not sent on cross-site subrequests, which blocks most CSRF. Chrome treats cookies without the attribute asLax; other browsers don’t all do the same, so set it explicitly.- The
__Host-prefix: the browser only accepts such a cookie if it isSecure, hasPath=/and noDomain, so a sibling subdomain can’t overwrite it.
6. The server side#
In real deployments, TLS usually ends at a CDN or load balancer, not at the application. Traffic behind it may be plain HTTP inside a “trusted” network, which is a common finding in internal pentests. When front-end and back-end servers disagree on where a request ends, HTTP request smuggling becomes possible, and when the application trusts the Host header, Host header attacks such as password-reset poisoning. These are worth naming in an interview, not explaining in depth.
7. The response and rendering#
The response carries the headers that tell the browser how to protect this page:
Content-Security-Policy: which sources scripts, styles, frames and connections may come from. The strongest second line of defense against XSS.Strict-Transport-Security: HSTS, as above.X-Content-Type-Options: nosniff: don’t guess content types, so an uploaded “image” isn’t run as a script.frame-ancestors(a CSP directive) or the olderX-Frame-Options: who may embed this page in a frame, against clickjacking.Referrer-Policy: how much of the URL leaks to other sites in theRefererheader.
Then the browser parses the HTML and fetches subresources. Each new host repeats DNS, TLS and the rest. HTTPS pages can’t load active content over HTTP (mixed content is blocked), and Subresource Integrity (integrity="sha384-...") lets a page pin the exact hash of a script from a third-party CDN.
Finally, the same-origin policy (SOP) governs what this page’s scripts may do. An origin is scheme + host + port. A script from https://evil.example can make the browser send a request to https://bank.example, but it can’t read the response. That asymmetry is why CSRF exists (sending is enough) and why reading needs CORS: a server opts in with Access-Control-Allow-Origin to let specific other origins read its responses.
The questions, and what they really want to hear#
“Walk me through what happens when you type a URL and press Enter.”#
What it tests: whether you see the whole system and spot the trust decisions, not whether you remember TCP flags.
30-second answer: “The browser checks HSTS and its caches, resolves the name through DNS, opens a connection, and does a TLS handshake where the server proves it owns the name with a certificate. Then it sends the HTTP request with matching cookies, gets the response with its security headers, and renders the page under the same-origin policy. From a security view, the critical points are that DNS is unauthenticated, that the very first request may be plain HTTP, that TLS is what actually authenticates the server, and that cookie attributes and response headers decide what an attacker can do with the page.”
Deeper: go hop by hop as above, and at each hop name one attack and one control with its limit: DNS spoofing → TLS stops it, unless the attacker can get a certificate; SSL stripping → HSTS, but only after the first visit, unless preloaded; certificate validation → revocation is soft-fail; cookies → SameSite and HttpOnly, which limit but don’t remove CSRF and XSS impact.
Follow-ups to expect:
- Junior: “What is the difference between HTTP and HTTPS?” “What does a certificate contain?”
- Mid: “What is HSTS and what’s its weakness?” “What does
SameSiteprotect against?” - Senior: “How would you get a valid certificate for a domain you don’t own?” “Where does TLS terminate in your architecture, and what does that mean for the internal network?”
“DNS isn’t authenticated. Why doesn’t a DNS spoof let an attacker read my bank session?”#
What it tests: whether you understand which layer actually provides the guarantee.
30-second answer: “Because TLS authenticates the server by name, independently of DNS. The fake server can’t present a valid certificate for the bank’s domain, so the browser refuses the connection, and with HSTS the user can’t click through the warning.”
Deeper: list the cases where the answer breaks down. The site isn’t on HSTS and the user clicks through the warning. The client isn’t a browser and skips certificate validation (a classic bug in mobile apps and scripts: verify=False). The attacker controls DNS long enough to pass a CA’s domain validation and get a real certificate. Defenses for the last one: a registrar lock and strong registrar account security, CAA records (which CAs may issue for the domain, and with RFC 8657 extensions, through which account and validation method), DNSSEC (CAs validate it when performing domain validation), and CT monitoring to detect a certificate you didn’t request.
Follow-ups: “What is a CAA record?” “What would you monitor to detect a mis-issued certificate?”
“What does HSTS do, and what is its weakness?”#
What it tests: a concrete control and its edge cases.
30-second answer: “The server tells the browser to use only HTTPS for this host for a given time, and the browser then upgrades every request itself and blocks clicking through certificate errors. Its weakness is the first visit: the browser hasn’t seen the header yet. The preload list fixes that.”
Deeper: max-age should be long (a year or more), includeSubDomains protects cookies scoped to the parent domain but will break any subdomain that still needs HTTP, and preloading is effectively a one-way door: removal from browser lists takes months. That is why you roll it out with a short max-age first and increase it.
“How does the browser decide whether to trust a certificate?”#
30-second answer: “The chain must lead to a trusted root, the name must match, the certificate must be within its validity dates, and in Chrome and Safari it must have been logged in Certificate Transparency. Revocation is checked too, but in a way that mostly fails open.”
Deeper: explain why revocation checking is soft-fail (an attacker who can intercept traffic can also block the OCSP request), what browsers use instead (CRLSets, CRLite), and why the industry is moving to short-lived certificates instead of making revocation work.
“What is the same-origin policy, and does CORS make a site more secure?”#
What it tests: the most common misconception in browser security.
30-second answer: “The SOP stops a page from reading responses from another origin: scheme, host and port. It doesn’t stop sending requests. CORS is a way for a server to relax the SOP for specific origins. It never adds protection; a misconfigured CORS policy, for example one that reflects any Origin and allows credentials, removes it.”
Follow-ups: “So what stops CSRF?” (SameSite cookies, anti-CSRF tokens, checking Origin or Sec-Fetch-Site headers.) “What is a CORS preflight, and which requests skip it?”
“Where does TLS end in a real deployment?”#
What it tests: whether you think past the browser to the architecture.
30-second answer: “Usually at a CDN or load balancer. Behind it, traffic may be plain HTTP, so anyone inside that network segment can read it. Whether that is acceptable depends on the threat model; for sensitive data, re-encrypt to the back end or use mutual TLS between services.”
Answers that cost points#
- “HTTPS hides which site I’m visiting.” The DNS query, the IP address and the SNI all reveal it, unless DoH and ECH are in use.
- “DNSSEC encrypts DNS.” It signs it. Encryption is DoH/DoT.
- “The padlock means the site is safe.” It means the connection is encrypted to a server that proved control of the name. Phishing sites have valid certificates too.
- “HSTS protects the first visit.” Only with preloading.
- “Browsers check certificate revocation.” Mostly soft-fail, or through curated lists.
- “CORS protects against CSRF.” CORS controls reading, not sending. A plain HTML form POST needs no CORS at all.
- "
HttpOnlyprevents XSS." It prevents reading the cookie from script. The injected script can still act as the user.
The same question in different interviews#
- Pentester: expect to be asked what you would test at each hop: subdomain takeover through dangling DNS records, missing HSTS or preload, weak TLS configuration (
testssl.sh), cookie flags and scope, CORS that reflects arbitrary origins with credentials, missing or weak security headers, Host header handling. - AppSec: the focus is on what the application controls: cookie attributes, CSP, CORS policy, HSTS rollout,
SameSiteand CSRF defense, safe redirects. - Security engineer: the focus is the infrastructure: registrar security and locks, CAA and CT monitoring, certificate automation and lifetimes, where TLS terminates, DNSSEC as a decision with operational cost, internal service-to-service encryption.
Practice#
Do the walk yourself on a real site; it sticks better than reading:
dig +trace example.com: the DNS resolution from the root down.openssl s_client -connect example.com:443 -servername example.com: the TLS handshake and certificate chain.curl -sv https://example.com -o /dev/null: the request and the response headers, including HSTS.- Your browser’s developer tools: the Network tab for headers and cookies, the Security tab (Chrome) for the certificate and connection.
- crt.sh: every certificate logged in CT for a domain. Try your own.
- hstspreload.org: whether a domain is preloaded, and the requirements.
- The free PortSwigger Web Security Academy labs on CORS, CSRF, clickjacking and HTTP Host header attacks.
This site’s colophon describes its own Content Security Policy, and what GitHub Pages does not allow it to set.
Test yourself#
A site sends Strict-Transport-Security: max-age=31536000 but is not on the preload list. A new user’s first visit happens on hostile café Wi-Fi, and they type the domain without https://. What can go wrong, and what fixes it?
Answer
The browser has never seen the HSTS header, so its first request may go over plain HTTP. An attacker on the Wi-Fi can intercept it and keep the user on HTTP (SSL stripping), proxying to the real HTTPS site. HSTS never gets a chance to arrive. The fix is to get the domain on the HSTS preload list (which requires HTTPS on every subdomain, includeSubDomains and a long max-age), so the browser upgrades to HTTPS before the first request. HTTPS-First modes in browsers help, but you can’t rely on users having them.
An attacker controls DNS answers for your domain for ten minutes. Can they get a valid TLS certificate for it? What reduces the risk?
Answer
Very likely, yes. Domain-validated certificates are issued after an automated check through DNS (a TXT record) or HTTP (a file served from the IP that DNS returns), and the attacker controls both answers. Defenses: CAA records to restrict which CAs (and, with RFC 8657, which account and validation method) may issue; DNSSEC, which CAs validate, so spoofed answers toward the CA fail; registrar lock and strong registrar account security against the more likely route of a hijacked account; and Certificate Transparency monitoring, which won’t prevent issuance but tells you within hours.
A page on evil.example auto-submits a form that POSTs to https://bank.example/transfer in the victim’s browser. Which mechanism stops the attack: the same-origin policy, CORS, or SameSite cookies?
Answer
Not the SOP: it stops reading responses, not sending requests. Not CORS: a plain form POST is a “simple” request with no preflight, and the attacker doesn’t need to read the response. SameSite cookies do: with SameSite=Lax or Strict, the browser doesn’t send the session cookie on a cross-site POST, so the request arrives unauthenticated. One caveat for a senior answer: if the cookie has no SameSite attribute, Chrome treats it as Lax but still sends it on top-level POSTs within two minutes of the cookie being set, a compatibility exception. Set SameSite explicitly and keep an anti-CSRF token or an Origin check for state-changing requests.
Further reading#
- What happens when…: the community’s exhaustive answer to the same question, down to keyboard interrupts.
- RFC 8446: TLS 1.3.
- RFC 6797: HTTP Strict Transport Security.
- RFC 8659 and RFC 8657: CAA records and their account and method extensions.
- MDN: Same-origin policy and MDN: Set-Cookie.
- Adam Langley: Revocation checking and Chrome’s CRL (2012): why online revocation checking doesn’t work, from one of the people who replaced it in Chrome.