Home
All articles
Web SecuritySecurityInterview PrepOWASP

100 Web Security Interview Questions & Answers

August 19, 202660 min read

Web security interviews test whether you actually understand the attack and the defense, not just the vocabulary — why parameterized queries stop SQL injection, why a bearer token is immune to CSRF in a way a cookie isn't. This covers the full spread, organized by topic, with code, a couple of diagrams, and a mock test at the end.

0 / 100 blocks read

Web Security Fundamentals

Q1. What is web security, and why is it important?

Web security is the practice of protecting websites and web applications from attacks that steal data, hijack sessions, or disrupt service — it matters because the web is the most exposed attack surface most organizations have: publicly reachable, constantly probed, and a single vulnerability (an unpatched dependency, an unvalidated input) can expose user data or compromise an entire system.

Q2. Can you explain what HTTPS is and how it differs from HTTP?

HTTPHTTPS
EncryptionNone — plaintextTLS-encrypted
IntegrityData can be modified in transit undetectedTampering is detectable
AuthenticationNo server identity verificationCertificate proves the server's identity
Port80443

HTTPS is HTTP layered over TLS — the same request/response semantics, but encrypted, tamper-evident, and backed by a certificate that lets the browser verify it's actually talking to the real server, not an impostor.

Q3. What are SSL and TLS, and what role do they play in web security?

SSL (Secure Sockets Layer) is the predecessor protocol, now considered insecure and deprecated everywhere; TLS (Transport Layer Security) is its modern successor and what "SSL" almost always actually means in practice today. Both provide encryption (confidentiality), integrity (detecting tampering), and authentication (verifying server identity via certificates) for data in transit.

Q4. How do SSL certificates work, and what is the purpose of a Certificate Authority (CA)?

Browser
Server (+ CA-signed cert)

A certificate binds a public key to a domain name, digitally signed by a Certificate Authority the browser already trusts — during the TLS handshake, the server presents its certificate, the browser verifies the CA's signature and the domain match, and only then do the two sides establish an encrypted session. The CA's whole job is vouching for that identity binding so a browser doesn't have to trust every server blindly.

Q5. What is the difference between encryption and hashing?

EncryptionHashing
Reversible?Yes — with the right key, ciphertext decrypts back to plaintextNo — one-way by design, no key can reverse it
PurposeConfidentiality — hide data, retrievable laterIntegrity/verification — a fixed-size fingerprint of data
Example useEncrypting a database column, TLS trafficStoring password hashes, verifying file integrity

Q6. Define the concept of a secure session and explain how it is established.

csharp
// Cookie flags that make a session cookie meaningfully more secure:
Set-Cookie: sessionId=abc123; Secure; HttpOnly; SameSite=Strict

A secure session ties a series of requests to an authenticated identity using a token/session ID that's hard to steal or forge — established after successful authentication, transmitted only over HTTPS (Secure flag), inaccessible to JavaScript (HttpOnly, blocking XSS-based theft), and restricted from being sent on cross-site requests (SameSite, mitigating CSRF).

Q7. What are some common web security vulnerabilities?

VulnerabilityIn short
XSS (Cross-Site Scripting)Injecting malicious script into pages viewed by other users
SQL InjectionInjecting SQL through unsanitized input
CSRFTricking a browser into making an unwanted authenticated request
Broken AuthenticationWeak session/credential handling
Security MisconfigurationDefault credentials, verbose errors, open admin panels

These map closely to the OWASP Top 10 — the industry's regularly-updated, evidence-based list of the most impactful web application security risks, which is worth naming explicitly in an interview as the standard reference point for prioritizing security work.

Q8. Can you explain the Cross-Site Scripting (XSS) attack and how to prevent it?

javascript
// Vulnerable: raw user input rendered directly as HTML
element.innerHTML = userComment;   // if userComment contains <script>, it executes

// Safe: render as text, or encode before inserting as HTML
element.textContent = userComment;

XSS injects malicious script into a page that other users then load and execute in their own browser session — stored (persisted in a database, e.g. a comment field), reflected (echoed back in a URL parameter), or DOM-based (client-side JS unsafely inserting untrusted data). Prevent it by encoding/escaping all output by default, using a framework that auto-escapes (React/Angular do by default unless you deliberately bypass it), and setting a Content-Security-Policy as a defense-in-depth backstop.

Q9. What is SQL Injection and how can you defend against it?

sql
-- Vulnerable: string-concatenated input becomes part of the query text
-- "SELECT * FROM users WHERE username = '" + input + "'"

-- Safe: a parameterized querythe value is bound, never parsed as SQL
SELECT * FROM users WHERE username = @username;

SQL injection exploits unsanitized input concatenated directly into a SQL query, letting an attacker alter the query's actual logic (bypass a login check, exfiltrate other tables' data, or worse). Parameterized queries/prepared statements are the real fix — the input is bound as data, never parsed as part of the SQL syntax, so no amount of clever input can change the query's structure.

Q10. Describe what Cross-Site Request Forgery (CSRF) is and how to prevent it.

CSRF tricks a logged-in user's browser into submitting an unwanted authenticated request to a site they're already logged into — it works because browsers automatically attach cookies to requests, even ones initiated by a malicious third-party page. Prevent it with anti-CSRF tokens (a per-session/per-form token the server verifies), SameSite=Strict/Lax cookies (blocking the browser from sending the cookie on a cross-site request in the first place), and checking the Origin/Referer header on state-changing requests.

Page110