CSE723 Study desk
Midterm practice

Web Security

58 questions · 5 topics · Short answers, scenarios & calculations

All questions

Q 1-01Short answer

Define the CIA triad and name one web attack for each property.

Reveal answer

Confidentiality: Keep data secret; e.g., IDOR exposing another user’s records.

Integrity: Prevent unauthorized data changes; e.g., changing an order price.

Availability: Keep services accessible; e.g., a DoS attack.

Q 1-02Short answer

List the six STRIDE categories.

Reveal answer

Spoofing, Tampering, Repudiation, Information Disclosure, Denial of Service, Elevation of Privilege.

Q 1-03Short answer

Why should vulnerable apps like DVWA run in an isolated network?

Reveal answer

DVWA is intentionally insecure. An isolated VM or private network prevents others from reaching the vulnerable application and limits damage if it is compromised.

Q 1-04Short answer

What must be installed in the browser to let Burp intercept HTTPS traffic?

Reveal answer

Install and trust Burp Suite’s CA certificate in the testing browser. Burp’s built-in browser is preconfigured for interception.

Q 1-05Scenario

A teammate bridges the Kali VM to the campus Wi-Fi while Juice Shop is running. What risks does this create, and how would you fix the setup?

Reveal answer

Risk: Bridged networking places the vulnerable Juice Shop service on the campus network, potentially exposing it to other devices.

Fix: Stop external exposure; use a host-only/internal network, bind the app to a private interface, remove external port forwards, and restrict inbound access with a firewall.

Q 1-06Scenario

How should the server handle a login request that includes a client-supplied role?

Reveal answer

Expected behavior: Assign privileges from trusted server-side records. Ignore client-supplied role claims and enforce authorization on each protected operation.

Review evidence: Check the assigned session privileges, access-control decision and audit record.

Q 2-01Short answer

What three parts define an origin in the same-origin policy?

Reveal answer

Scheme + host + port. Example: https://example.com:443. Different paths can share the same origin; changing scheme, host, or port changes it.

Q 2-02Short answer

What do the cookie flags HttpOnly, Secure and SameSite do?

Reveal answer

HttpOnly: Prevents JavaScript from reading the cookie.

Secure: Sends it only over HTTPS.

SameSite: Restricts sending cookies on cross-site requests, helping mitigate CSRF.

Q 2-03Short answer

Name four security headers and the threat each one mitigates.

Reveal answer
  • Content-Security-Policy: Restricts script/resource sources; mitigates XSS.
  • X-Frame-Options: Restricts embedding in frames; mitigates clickjacking.
  • Strict-Transport-Security (HSTS): Enforces HTTPS on future connections; mitigates SSL stripping.
  • X-Content-Type-Options: nosniff: Prevents MIME sniffing for scripts/styles.
Q 2-04Short answer

Passive vs active reconnaissance: what is the difference?

Reveal answer

Passive: Gather information from existing/public sources without probing the target (e.g., search indexes).

Active: Send traffic to the target to inspect it (e.g., checking HTTP headers or enumerating paths).

Q 2-05Scenario

A header audit shows no Content-Security-Policy, no X-Frame-Options and a Server: Apache/2.2.15 banner. List the risks and your recommendations.

Reveal answer

Risks: Missing CSP reduces XSS containment; missing framing protection raises clickjacking risk; the banner reveals an apparently obsolete Apache 2.2 release.

Fix: Configure a suitable CSP (including frame-ancestors), use X-Frame-Options where needed, verify the installed Apache version/patches, upgrade to a supported release, and minimize version disclosure.

Q 2-06Scenario

ffuf finds /backup/, /admin/ and /.git/. Explain the risk of each and what you would report.

Reveal answer

/backup/ may expose dumps or credentials; /admin/ may expose protected functions if authorization is weak; /.git/ may leak source code and secrets. Report the discovered paths, HTTP responses, and confirmed exposure. Remove sensitive files from the web root and enforce server-side admin authorization.

Q 2-07Calculation

Base64: Encode the string Hi in Base64.

Reveal answer

H = 01001000, i = 01101001 → 6-bit groups 010010 000110 100100 → SGk, then add one = padding character.

Answer: SGk=

Q 2-08Calculation

Base64: Decode YWRtaW4=. Why is Base64 in a cookie not a security control?

Reveal answer

Decoded: admin. Base64 is reversible encoding, not encryption or signing; anyone can decode or modify it. It provides neither confidentiality nor integrity.

Q 2-09Calculation

Base64: How many Base64 characters (including padding) does a 10-byte value produce?

Reveal answer

Base64 uses 3 input bytes → 4 output characters. 4 × ceil(10 / 3) = 4 × 4 = 16.

Answer: 16 characters, including 2 = padding characters.

Q 3-01Short answer

What does HSTS prevent, and what is the "first visit" problem?

Reveal answer

HSTS makes the browser upgrade HTTP requests to HTTPS, helping prevent SSL stripping. First-visit problem: Before receiving the policy, the browser may try HTTP. HSTS preloading lets browsers enforce HTTPS from the first visit.

Q 3-02Short answer

What is forward secrecy?

Reveal answer

Compromise of a server’s long-term private key must not reveal past recorded TLS sessions. Ephemeral key exchange such as ECDHE creates temporary secrets that are discarded after use.

Q 3-03Short answer

Name two weak protocol versions or cipher types that testssl.sh should flag.

Reveal answer

SSL 3.0 (obsolete protocol) and RC4 (weak cipher). TLS 1.0/1.1 and legacy CBC suites are other findings to review.

Q 3-04Short answer

What is the role of an intermediate CA in a certificate chain?

Reveal answer

An intermediate CA is signed by a trusted root CA and can issue website certificates. It connects the site’s certificate to a trusted root. Servers usually send the site and intermediate certificates; browsers/OSes already trust the root.

Q 3-05Scenario

testssl.sh reports TLS 1.0 enabled and a CBC cipher. Explain the risk and write the nginx directives to fix it.

Reveal answer

Risk: TLS 1.0 is obsolete; legacy CBC suites can be vulnerable to padding/timing attacks. Allow TLS 1.2/1.3 and AEAD suites such as AES-GCM.

ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256';

Test config, reload nginx, then rescan. ssl_ciphers controls TLS 1.2 and earlier suites, not TLS 1.3 suites.

Q 3-06Scenario

Users get a certificate warning on your site. Give four possible causes and how you would diagnose each.

Reveal answer
  1. Expired/not-yet-valid: Compare certificate validity with client clock.
  2. Hostname mismatch: Check Subject Alternative Names (SANs).
  3. Incomplete chain: Inspect missing intermediate certificates.
  4. Untrusted issuer: Check whether the chain reaches a root trusted by the client.
Q 3-07Scenario

Why does a valid certificate alone leave a first-visit risk on public Wi-Fi?

Reveal answer

A certificate authenticates the HTTPS connection once it starts. An initial HTTP request has no transport protection. HSTS upgrades future visits after the browser learns the policy over HTTPS. Preloading can also protect the first visit.

Q 3-08Calculation

RSA: Given p = 3, q = 11, e = 3, calculate n, φ(n) and the private key d.

Reveal answer

n = p × q = 3 × 11 = 33

φ(n) = (p−1)(q−1) = 2 × 10 = 20

Find d such that 3d mod 20 = 1. Since 3 × 7 = 21, d = 7.

Public key: (33, 3); private key: (33, 7).

Q 3-09Calculation

RSA: Encrypt the message m = 4 using the key above. Then show how to decrypt the result.

Reveal answer

Encrypt: c = m^e mod n = 4^3 mod 33 = 64 mod 33 = 31.

Decrypt: m = c^d mod n = 31^7 mod 33 = 4. Since 31 ≡ −2 (mod 33), (-2)^7 = -128 ≡ 4 (mod 33).

Result: 4 → 31 → 4.

Q 3-10Calculation

RSA signature: Sign m = 5 with d = 7 (n = 33) and show how the receiver verifies it.

Reveal answer

Sign: s = m^d mod n = 5^7 mod 33 = 14.

Verify using public exponent e = 3: s^e mod n = 14^3 mod 33 = 5. The result equals the message, so the signature verifies. *(Textbook RSA example.)*

Q 3-11Calculation

Diffie-Hellman: With p = 23, g = 5, Alice's secret a = 6 and Bob's secret b = 15, compute both public values and the shared secret.

Reveal answer

Alice public: A = 5^6 mod 23 = 8.

Bob public: B = 5^15 mod 23 = 19.

Shared secret: Alice computes 19^6 mod 23 = 2; Bob computes 8^15 mod 23 = 2. Both get 2.

Q 3-12Calculation

AES: How many rounds do AES-128, AES-192 and AES-256 use? What is the block size?

Reveal answer

AES-128: 10 rounds; AES-192: 12 rounds; AES-256: 14 rounds.

All three use the same 128-bit (16-byte) block size; their key lengths differ.

Q 3-13Calculation

AES: How many 16-byte blocks does a 100-byte plaintext need under PKCS#7 padding? How many padding bytes are added?

Reveal answer

100 = 6 × 16 + 4, so the final block has 4 data bytes. Add 16 − 4 = 12 padding bytes (each 0x0C).

Padded length: 112 bytes; total: 7 blocks.

Q 3-14Calculation

AES: Why does ECB mode leak patterns, and why is GCM preferred?

Reveal answer

ECB: Identical 16-byte plaintext blocks encrypted with the same key produce identical ciphertext blocks, exposing patterns.

GCM: Uses a unique nonce and provides authenticated encryption (confidentiality + integrity). Never reuse a nonce with the same key.

Q 3-15Calculation

HSTS: max-age=31536000 equals how many days?

Reveal answer

31,536,000 / (60 × 60 × 24) = 365.

Answer: 365 days.

Q 4-01Short answer

Why is plain SHA-256 unsuitable for password storage?

Reveal answer

SHA-256 is too fast: stolen hashes can be tested against massive numbers of offline guesses. Use Argon2id or bcrypt with unique salts and appropriate work factors.

Q 4-02Short answer

Compare brute force, password spraying and credential stuffing.

Reveal answer

Brute force: Many password guesses against one account.

Password spraying: One/few common passwords tried across many accounts.

Credential stuffing: Reuse leaked username-password pairs on other services.

Q 4-03Short answer

What is a salt, and what does it stop?

Reveal answer

A salt is a unique random value used for each password hash. It makes identical passwords produce different hashes and defeats reusable precomputed/rainbow-table attacks. It does not stop individual offline guesses by itself.

Q 4-04Short answer

How does TOTP generate a code?

Reveal answer

The authenticator and server share a secret. Both compute a time counter (usually 30-second intervals), apply HMAC, and derive the same short numeric code (usually 6 digits). The server compares the submitted code with its expected value.

Q 4-05Scenario

A login page says "user not found" for bad usernames and "wrong password" for bad passwords. What is the problem, and how do you fix it?

Reveal answer

Problem: Account/username enumeration: different errors reveal valid usernames.

Fix: Use a generic error such as Invalid username or password, with consistent status codes and comparable response times.

Q 4-06Scenario

You discover a database of unsalted MD5 password hashes. Describe your incident response and migration plan to a modern hash.

Reveal answer

Respond: Restrict access, preserve logs, investigate exposure; if compromise is suspected, force affected password resets, revoke sessions, and notify users appropriately.

Migrate: Use Argon2id with unique salts for new/reset passwords. For accounts without suspected compromise, rehash after successful login; require resets for accounts not yet migrated.

Q 4-07Scenario

Design a secure password-reset flow and list three common mistakes.

Reveal answer

Flow: Generic response + rate limiting → random, short-lived, single-use reset token → email a link to the verified address → verify and consume token → hash new password securely, invalidate sessions, notify user. Store only the reset-token hash.

Three mistakes: Revealing account existence, predictable tokens, and reusable tokens.

Q 4-08Scenario

A session ID does not change after login. Name the attack and the fix.

Reveal answer

Attack: Session fixation. An attacker who knows a pre-login session ID may reuse it after the victim logs in.

Fix: Regenerate the session ID at login (and privilege changes) and invalidate the old ID.

Q 4-09Calculation

Entropy: An 8-character password uses [A-Za-z0-9]. How many combinations are possible, roughly how many bits of entropy is that, and how long would an offline attack at 10 billion guesses per second take to exhaust the space?

Reveal answer

Alphabet size 26 + 26 + 10 = 62.

Combinations: 62^8 = 218,340,105,584,896.

Entropy: log2(62^8) ≈ 47.63 bits.

Exhaustive time: 62^8 / 10^10 ≈ 21,834 seconds ≈ 6 h 4 min (uniform-random assumption).

Q 4-10Calculation

bcrypt: With cost factor 12, how many iterations of the key-setup loop run? How much slower is cost 14?

Reveal answer

Cost 12 → 2^12 = 4,096 iterations. Cost 14 → 2^14 = 16,384 iterations.

Cost 14 is approximately 4× slower on the same hardware.

Q 4-11Calculation

TOTP: With a 30-second step and Unix time 1,700,000,000, what is the counter value?

Reveal answer

T = floor(1,700,000,000 / 30) = floor(56,666,666.666…).

Counter: 56,666,666.

Q 4-12Calculation

Lockout: A policy allows 5 attempts per account per 15 minutes. How many passwords can an attacker try per account per day?

Reveal answer

24 × 60 / 15 = 96 windows/day; 96 × 5 = 480.

Answer: 480 attempts per account per day, assuming the limit resets each 15-minute window.

Q 5-01Short answer

Authentication vs authorization: what is the difference?

Reveal answer

Authentication (AuthN): Verifies who you are (e.g., login).

Authorization (AuthZ): Checks what resources or actions you are allowed to access (e.g., own order vs someone else’s).

Q 5-02Short answer

What does OIDC add on top of OAuth 2.0?

Reveal answer

OIDC adds an authentication and identity layer to OAuth 2.0. It provides an ID Token with verified user claims, while OAuth 2.0 supplies delegated authorization and token/redirect flows.

Q 5-03Short answer

What are IDOR and BOLA?

Reveal answer

IDOR: A direct object identifier (e.g., /orders/1002) lets a user access an unauthorized object.

BOLA: Broader failure to enforce permissions on individual objects. IDOR is a common form of BOLA.

Q 5-04Short answer

Why use PKCE, and why is the Implicit flow discouraged?

Reveal answer

PKCE: Binds an authorization code to a one-time code_verifier, so a stolen code alone cannot be redeemed.

Implicit flow: Returns access tokens through the browser front channel, increasing leakage/replay risk. Prefer Authorization Code + PKCE.

Q 5-05Short answer

What are the three parts of a JWT, and is it encrypted by default?

Reveal answer

A typical signed JWT is Header.Payload.Signature. Header/payload are Base64url-encoded and readable; the signature detects unauthorized changes. It is not encrypted by default (JWE adds encryption).

Q 5-06Short answer

What are the purposes of state and nonce?

Reveal answer

state: Correlates the OAuth callback with the original browser login request; helps prevent login CSRF.

nonce: Correlates an OIDC ID Token with the original authentication request; helps prevent token replay/substitution.

Q 5-07Scenario

Changing /api/orders/1001 to /api/orders/1002 shows another user's order. Classify the issue (OWASP and CWE), rate the severity and write the fix.

Reveal answer

Classification: IDOR/BOLA; OWASP API1:2023 Broken Object Level Authorization; CWE-639 Authorization Bypass Through User-Controlled Key.

Severity: High if sensitive orders are accessible across users.

Fix: On every request, verify server-side that the authenticated user owns or is permitted to access the selected order.

Q 5-08Scenario

What risk does an overly broad OAuth redirect policy create, and how should it be fixed?

Reveal answer

Authorization codes can reach an unintended callback. Require exact matching against registered redirect URIs, eliminate open redirects on callbacks and use PKCE.

Q 5-09Scenario

Why is accepting unsigned JWTs unsafe, and what should a JWT API enforce?

Reveal answer

Unsigned tokens provide no evidence of who issued their claims. Pin the expected signing algorithm and trusted key, verify the signature, and validate issuer, audience and expiry before using any claims.

Q 5-10Scenario

A user's role is stored in a JWT that lasts 30 days. The user is demoted. Discuss the problem and revocation strategies.

Reveal answer

Problem: The existing signed JWT still says role: admin and can retain old privileges for up to 30 days if the API trusts stale claims.

Strategies: Short-lived access tokens; verify current role when refreshing; revoke refresh tokens. For immediate enforcement, check current server-side role/token version or use a JWT denylist.

Q 5-11Scenario

An attacker changes role=user to role=admin in a cookie and gets admin access. What is the root cause, and how would you redesign it?

Reveal answer

Root cause: The server trusts a client-editable cookie for authorization.

Fix: Put only an unpredictable session ID in the cookie, keep role/permission data on the server, and authorize every protected request using trusted data.

Q 5-12Calculation

Base64url: Decode the JWT header eyJhbGciOiJIUzI1NiJ9.

Reveal answer

Decoded JSON: {"alg":"HS256"}.

HS256 means HMAC-SHA256 signing.

Q 5-13Calculation

Base64url: Encode {"user":"bob"} and explain why Base64url differs from Base64.

Reveal answer

Unpadded Base64url: eyJ1c2VyIjoiYm9iIn0.

Base64url replaces + with - and / with _ for URL safety; JWTs omit trailing = padding.

Q 5-14Calculation

JWT: An HS256 signature is 256 bits. How many Base64url characters does it take without padding?

Reveal answer

HS256 = HMAC-SHA256, producing a 256-bit signature. Each Base64url character holds 6 bits. 256 = 42 × 6 + 4: 42 full groups plus one group for the remaining 4 bits.

Answer: 43 characters without = padding.

Q 5-15Calculation

JWT expiry: A token has iat = 1700000000 and exp = 1700003600. What is its lifetime in minutes?

Reveal answer

exp − iat = 1,700,003,600 − 1,700,000,000 = 3,600 seconds. 3,600 / 60 = 60.

Answer: 60 minutes.

Q 5-16Calculation

HMAC: A JWT secret is a 6-character lowercase word. How many possibilities are there, and why does this make cracking easy?

Reveal answer

26^6 = 308,915,776 possible lowercase strings. Attackers can try guesses offline against a captured HS256 JWT, and real dictionary words shrink the likely search space. Use a random HS256 key of at least 32 bytes.