InterviewTreedInterviewTreed

InterviewTreed Question Bank

Application Security Interview Questions and Answers

Prepare for application security interviews, covering secure coding, authentication, authorization, OWASP vulnerabilities, API security, cryptography, threat modeling, and security best practices for modern applications.

Total Questions

75

Beginner

28

Intermediate

31

Advanced

16

Beginner Questions

Foundational concepts, terminology, and core ideas.

Q1Security fundamentals

What is application security?

Interview answer covering what is application security? with a practical implementation pattern.

Answer

What is application security? is a core application-security concept in security fundamentals. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q2Security fundamentals

Authentication vs authorization

Interview answer covering authentication vs authorization with a practical implementation pattern.

Answer

Authentication vs authorization is a core application-security concept in security fundamentals. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q3Security fundamentals

What is the principle of least privilege?

Interview answer covering what is the principle of least privilege? with a practical implementation pattern.

Answer

What is the principle of least privilege? is a core application-security concept in security fundamentals. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q4Security fundamentals

What is defense in depth?

Interview answer covering what is defense in depth? with a practical implementation pattern.

Answer

What is defense in depth? is a core application-security concept in security fundamentals. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q6Security fundamentals

What is the difference between hashing, encryption, and encoding?

Interview answer covering what is the difference between hashing, encryption, and encoding? with a practical implementation pattern.

Answer

What is the difference between hashing, encryption, and encoding? is a core application-security concept in security fundamentals. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q7Security fundamentals

What is TLS and why is it required?

Interview answer covering what is tls and why is it required? with a practical implementation pattern.

Answer

What is TLS and why is it required? is a core application-security concept in security fundamentals. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Content-Security-Policy: default-src 'self'; object-src 'none'; base-uri 'self'

Example

Use contextual output encoding, avoid unsafe HTML insertion, and set a restrictive Content Security Policy.

Code example

app.use(helmet({
  contentSecurityPolicy: {
    directives: {
      defaultSrc: ["'self'"],
      objectSrc: ["'none'"],
      baseUri: ["'self'"],
    },
  },
}));

Diagram

Untrusted content → Validate/encode → Safe rendering + CSP → Reduced browser attack surface

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q9Security fundamentals

What is a security misconfiguration?

Interview answer covering what is a security misconfiguration? with a practical implementation pattern.

Answer

What is a security misconfiguration? is a core application-security concept in security fundamentals. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q11Authentication and sessions

How should passwords be stored?

Interview answer covering how should passwords be stored? with a practical implementation pattern.

Answer

How should passwords be stored? is a core application-security concept in authentication and sessions. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Set-Cookie: __Host-session=...; Path=/; Secure; HttpOnly; SameSite=Lax

Example

After successful authentication, rotate the session ID and set a secure, HttpOnly cookie.

Code example

// Illustrative session configuration
app.use(session({
  name: "__Host-session",
  secret: process.env.SESSION_SECRET,
  cookie: { secure: true, httpOnly: true, sameSite: "lax", path: "/" },
  resave: false,
  saveUninitialized: false,
}));

Diagram

Credentials + MFA → Verify → Rotate session ID → Secure cookie → Authorized requests

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q12Authentication and sessions

What is multi-factor authentication (MFA)?

Interview answer covering what is multi-factor authentication (mfa)? with a practical implementation pattern.

Answer

What is multi-factor authentication (MFA)? is a core application-security concept in authentication and sessions. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Set-Cookie: __Host-session=...; Path=/; Secure; HttpOnly; SameSite=Lax

Example

After successful authentication, rotate the session ID and set a secure, HttpOnly cookie.

Code example

// Illustrative session configuration
app.use(session({
  name: "__Host-session",
  secret: process.env.SESSION_SECRET,
  cookie: { secure: true, httpOnly: true, sameSite: "lax", path: "/" },
  resave: false,
  saveUninitialized: false,
}));

Diagram

Credentials + MFA → Verify → Rotate session ID → Secure cookie → Authorized requests

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q21OAuth 2.0

What problem does OAuth 2.0 solve?

Interview answer covering what problem does oauth 2.0 solve? with a practical implementation pattern.

Answer

What problem does OAuth 2.0 solve? is a core application-security concept in oauth 2.0. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q22OAuth 2.0

Explain OAuth 2.0 roles

Interview answer covering explain oauth 2.0 roles with a practical implementation pattern.

Answer

Explain OAuth 2.0 roles is a core application-security concept in oauth 2.0. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q23OAuth 2.0

What is an access token?

Interview answer covering what is an access token? with a practical implementation pattern.

Answer

What is an access token? is a core application-security concept in oauth 2.0. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q31OpenID Connect

What is OpenID Connect?

Interview answer covering what is openid connect? with a practical implementation pattern.

Answer

What is OpenID Connect? is a core application-security concept in openid connect. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

ID token validation: signature + iss + aud + exp + nonce (when sent)

Example

After sign-in, the relying party validates the ID token and checks state/nonce before creating its local session.

Code example

// Pseudocode: use a maintained OpenID Connect client library in production
const tokens = await oidcClient.callback(redirectUri, params, {
  state: expectedState,
  nonce: expectedNonce,
});
const claims = tokens.claims();
if (claims.iss !== configuredIssuer || !claims.sub) {
  throw new Error("Invalid identity token");
}

Diagram

Browser → OIDC Provider → Authorization Code → Backend callback → Validate state/nonce/token → App session

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q32OpenID Connect

OAuth 2.0 vs OpenID Connect

Interview answer covering oauth 2.0 vs openid connect with a practical implementation pattern.

Answer

OAuth 2.0 vs OpenID Connect is a core application-security concept in openid connect. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q33OpenID Connect

What is an ID token?

Interview answer covering what is an id token? with a practical implementation pattern.

Answer

What is an ID token? is a core application-security concept in openid connect. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q41JWT

What is a JWT and its structure?

Interview answer covering what is a jwt and its structure? with a practical implementation pattern.

Answer

What is a JWT and its structure? is a core application-security concept in jwt. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

JWT = base64url(header) + '.' + base64url(payload) + '.' + signature

Example

An API accepts a JWT only after validating its signature and expected issuer, audience, and lifetime.

Code example

// Pseudocode: verify with a trusted key and explicit algorithm allow-list
const claims = await jwtVerify(token, trustedJwks, {
  algorithms: ["RS256"],
  issuer: "https://identity.example.com/",
  audience: "orders-api",
});
if (claims.payload.exp === undefined) throw new Error("Missing expiry");

Diagram

JWT received → Parse safely → Verify signature/key/algorithm → Validate iss/aud/exp → Authorize request

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q42JWT

Is a JWT encrypted by default?

Interview answer covering is a jwt encrypted by default? with a practical implementation pattern.

Answer

Is a JWT encrypted by default? is a core application-security concept in jwt. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

JWT = base64url(header) + '.' + base64url(payload) + '.' + signature

Example

An API accepts a JWT only after validating its signature and expected issuer, audience, and lifetime.

Code example

// Pseudocode: verify with a trusted key and explicit algorithm allow-list
const claims = await jwtVerify(token, trustedJwks, {
  algorithms: ["RS256"],
  issuer: "https://identity.example.com/",
  audience: "orders-api",
});
if (claims.payload.exp === undefined) throw new Error("Missing expiry");

Diagram

JWT received → Parse safely → Verify signature/key/algorithm → Validate iss/aud/exp → Authorize request

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q50JWT

What information should never go in a JWT?

Interview answer covering what information should never go in a jwt? with a practical implementation pattern.

Answer

What information should never go in a JWT? is a core application-security concept in jwt. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

JWT = base64url(header) + '.' + base64url(payload) + '.' + signature

Example

An API accepts a JWT only after validating its signature and expected issuer, audience, and lifetime.

Code example

// Pseudocode: verify with a trusted key and explicit algorithm allow-list
const claims = await jwtVerify(token, trustedJwks, {
  algorithms: ["RS256"],
  issuer: "https://identity.example.com/",
  audience: "orders-api",
});
if (claims.payload.exp === undefined) throw new Error("Missing expiry");

Diagram

JWT received → Parse safely → Verify signature/key/algorithm → Validate iss/aud/exp → Authorize request

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q51OWASP risks

What is the OWASP Top 10?

Interview answer covering what is the owasp top 10? with a practical implementation pattern.

Answer

What is the OWASP Top 10? is a core application-security concept in owasp risks. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q52OWASP risks

What is broken access control?

Interview answer covering what is broken access control? with a practical implementation pattern.

Answer

What is broken access control? is a core application-security concept in owasp risks. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q53OWASP risks

What is injection and how do parameterized queries help?

Interview answer covering what is injection and how do parameterized queries help? with a practical implementation pattern.

Answer

What is injection and how do parameterized queries help? is a core application-security concept in owasp risks. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

SELECT * FROM users WHERE email = $1

Example

Treat user input as data, not SQL syntax; bind it as a parameter.

Code example

const result = await db.query(
  "SELECT id, email FROM users WHERE email = $1",
  [email]
);

Diagram

Untrusted input → Parameterized query → Database treats value as data

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q54OWASP risks

What is cross-site scripting (XSS)?

Interview answer covering what is cross-site scripting (xss)? with a practical implementation pattern.

Answer

What is cross-site scripting (XSS)? is a core application-security concept in owasp risks. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Content-Security-Policy: default-src 'self'; object-src 'none'; base-uri 'self'

Example

Use contextual output encoding, avoid unsafe HTML insertion, and set a restrictive Content Security Policy.

Code example

app.use(helmet({
  contentSecurityPolicy: {
    directives: {
      defaultSrc: ["'self'"],
      objectSrc: ["'none'"],
      baseUri: ["'self'"],
    },
  },
}));

Diagram

Untrusted content → Validate/encode → Safe rendering + CSP → Reduced browser attack surface

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q57OWASP risks

What are vulnerable and outdated components?

Interview answer covering what are vulnerable and outdated components? with a practical implementation pattern.

Answer

What are vulnerable and outdated components? is a core application-security concept in owasp risks. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q61Secure API design

How do you secure a REST API?

Interview answer covering how do you secure a rest api? with a practical implementation pattern.

Answer

How do you secure a REST API? is a core application-security concept in secure api design. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q64Secure API design

How should APIs validate input?

Interview answer covering how should apis validate input? with a practical implementation pattern.

Answer

How should APIs validate input? is a core application-security concept in secure api design. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q66Secure API design

How do you prevent SQL injection in an API?

Interview answer covering how do you prevent sql injection in an api? with a practical implementation pattern.

Answer

How do you prevent SQL injection in an API? is a core application-security concept in secure api design. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

SELECT * FROM users WHERE email = $1

Example

Treat user input as data, not SQL syntax; bind it as a parameter.

Code example

const result = await db.query(
  "SELECT id, email FROM users WHERE email = $1",
  [email]
);

Diagram

Untrusted input → Parameterized query → Database treats value as data

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q71Security testing and operations

What is SAST vs DAST vs SCA?

Interview answer covering what is sast vs dast vs sca? with a practical implementation pattern.

Answer

What is SAST vs DAST vs SCA? is a core application-security concept in security testing and operations. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.

Intermediate Questions

Implementation details, practical patterns, and common workflows.

Q5Security fundamentals

What is a threat model?

Interview answer covering what is a threat model? with a practical implementation pattern.

Answer

What is a threat model? is a core application-security concept in security fundamentals. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q8Security fundamentals

What are security headers?

Interview answer covering what are security headers? with a practical implementation pattern.

Answer

What are security headers? is a core application-security concept in security fundamentals. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Content-Security-Policy: default-src 'self'; object-src 'none'; base-uri 'self'

Example

Use contextual output encoding, avoid unsafe HTML insertion, and set a restrictive Content Security Policy.

Code example

app.use(helmet({
  contentSecurityPolicy: {
    directives: {
      defaultSrc: ["'self'"],
      objectSrc: ["'none'"],
      baseUri: ["'self'"],
    },
  },
}));

Diagram

Untrusted content → Validate/encode → Safe rendering + CSP → Reduced browser attack surface

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q10Security fundamentals

How do you manage secrets securely?

Interview answer covering how do you manage secrets securely? with a practical implementation pattern.

Answer

How do you manage secrets securely? is a core application-security concept in security fundamentals. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q13Authentication and sessions

What is brute-force protection?

Interview answer covering what is brute-force protection? with a practical implementation pattern.

Answer

What is brute-force protection? is a core application-security concept in authentication and sessions. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Set-Cookie: __Host-session=...; Path=/; Secure; HttpOnly; SameSite=Lax

Example

After successful authentication, rotate the session ID and set a secure, HttpOnly cookie.

Code example

// Illustrative session configuration
app.use(session({
  name: "__Host-session",
  secret: process.env.SESSION_SECRET,
  cookie: { secure: true, httpOnly: true, sameSite: "lax", path: "/" },
  resave: false,
  saveUninitialized: false,
}));

Diagram

Credentials + MFA → Verify → Rotate session ID → Secure cookie → Authorized requests

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q14Authentication and sessions

What is session fixation?

Interview answer covering what is session fixation? with a practical implementation pattern.

Answer

What is session fixation? is a core application-security concept in authentication and sessions. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Set-Cookie: __Host-session=...; Path=/; Secure; HttpOnly; SameSite=Lax

Example

After successful authentication, rotate the session ID and set a secure, HttpOnly cookie.

Code example

// Illustrative session configuration
app.use(session({
  name: "__Host-session",
  secret: process.env.SESSION_SECRET,
  cookie: { secure: true, httpOnly: true, sameSite: "lax", path: "/" },
  resave: false,
  saveUninitialized: false,
}));

Diagram

Credentials + MFA → Verify → Rotate session ID → Secure cookie → Authorized requests

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q15Authentication and sessions

How should session cookies be configured?

Interview answer covering how should session cookies be configured? with a practical implementation pattern.

Answer

How should session cookies be configured? is a core application-security concept in authentication and sessions. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Set-Cookie: __Host-session=...; Path=/; Secure; HttpOnly; SameSite=Lax

Example

After successful authentication, rotate the session ID and set a secure, HttpOnly cookie.

Code example

// Illustrative session configuration
app.use(session({
  name: "__Host-session",
  secret: process.env.SESSION_SECRET,
  cookie: { secure: true, httpOnly: true, sameSite: "lax", path: "/" },
  resave: false,
  saveUninitialized: false,
}));

Diagram

Credentials + MFA → Verify → Rotate session ID → Secure cookie → Authorized requests

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q16Authentication and sessions

What is CSRF and how do you prevent it?

Interview answer covering what is csrf and how do you prevent it? with a practical implementation pattern.

Answer

What is CSRF and how do you prevent it? is a core application-security concept in authentication and sessions. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

SameSite=Lax; Secure; HttpOnly

Example

For cookie-authenticated state-changing requests, validate a CSRF token and/or use appropriate SameSite cookie protections.

Code example

app.post("/profile", verifyCsrfToken, requireSession, async (req, res) => {
  await updateProfile(req.session.userId, req.body);
  res.sendStatus(204);
});

Diagram

Browser sends request → Server checks session + CSRF token → Mutation allowed/denied

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q17Authentication and sessions

What is CORS and what does it not protect against?

Interview answer covering what is cors and what does it not protect against? with a practical implementation pattern.

Answer

What is CORS and what does it not protect against? is a core application-security concept in authentication and sessions. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Access-Control-Allow-Origin: https://app.example.com

Example

Allow only known front-end origins; CORS is not authentication and does not block server-to-server requests.

Code example

app.use(cors({
  origin: ["https://app.example.com"],
  methods: ["GET", "POST"],
  credentials: true,
}));

Diagram

Browser origin → CORS policy check → Browser permits or blocks script access

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q24OAuth 2.0

What is a refresh token?

Interview answer covering what is a refresh token? with a practical implementation pattern.

Answer

What is a refresh token? is a core application-security concept in oauth 2.0. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q25OAuth 2.0

Authorization Code flow with PKCE

Interview answer covering authorization code flow with pkce with a practical implementation pattern.

Answer

Authorization Code flow with PKCE is a core application-security concept in oauth 2.0. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q26OAuth 2.0

Why should the implicit flow generally be avoided?

Interview answer covering why should the implicit flow generally be avoided? with a practical implementation pattern.

Answer

Why should the implicit flow generally be avoided? is a core application-security concept in oauth 2.0. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q28OAuth 2.0

What is the client-credentials flow?

Interview answer covering what is the client-credentials flow? with a practical implementation pattern.

Answer

What is the client-credentials flow? is a core application-security concept in oauth 2.0. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q34OpenID Connect

What are issuer, audience, and subject claims?

Interview answer covering what are issuer, audience, and subject claims? with a practical implementation pattern.

Answer

What are issuer, audience, and subject claims? is a core application-security concept in openid connect. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

ID token validation: signature + iss + aud + exp + nonce (when sent)

Example

After sign-in, the relying party validates the ID token and checks state/nonce before creating its local session.

Code example

// Pseudocode: use a maintained OpenID Connect client library in production
const tokens = await oidcClient.callback(redirectUri, params, {
  state: expectedState,
  nonce: expectedNonce,
});
const claims = tokens.claims();
if (claims.iss !== configuredIssuer || !claims.sub) {
  throw new Error("Invalid identity token");
}

Diagram

Browser → OIDC Provider → Authorization Code → Backend callback → Validate state/nonce/token → App session

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q35OpenID Connect

What are nonce and state used for?

Interview answer covering what are nonce and state used for? with a practical implementation pattern.

Answer

What are nonce and state used for? is a core application-security concept in openid connect. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

ID token validation: signature + iss + aud + exp + nonce (when sent)

Example

After sign-in, the relying party validates the ID token and checks state/nonce before creating its local session.

Code example

// Pseudocode: use a maintained OpenID Connect client library in production
const tokens = await oidcClient.callback(redirectUri, params, {
  state: expectedState,
  nonce: expectedNonce,
});
const claims = tokens.claims();
if (claims.iss !== configuredIssuer || !claims.sub) {
  throw new Error("Invalid identity token");
}

Diagram

Browser → OIDC Provider → Authorization Code → Backend callback → Validate state/nonce/token → App session

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q36OpenID Connect

What is discovery metadata?

Interview answer covering what is discovery metadata? with a practical implementation pattern.

Answer

What is discovery metadata? is a core application-security concept in openid connect. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

ID token validation: signature + iss + aud + exp + nonce (when sent)

Example

After sign-in, the relying party validates the ID token and checks state/nonce before creating its local session.

Code example

// Pseudocode: use a maintained OpenID Connect client library in production
const tokens = await oidcClient.callback(redirectUri, params, {
  state: expectedState,
  nonce: expectedNonce,
});
const claims = tokens.claims();
if (claims.iss !== configuredIssuer || !claims.sub) {
  throw new Error("Invalid identity token");
}

Diagram

Browser → OIDC Provider → Authorization Code → Backend callback → Validate state/nonce/token → App session

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q39OpenID Connect

What is UserInfo endpoint?

Interview answer covering what is userinfo endpoint? with a practical implementation pattern.

Answer

What is UserInfo endpoint? is a core application-security concept in openid connect. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

ID token validation: signature + iss + aud + exp + nonce (when sent)

Example

After sign-in, the relying party validates the ID token and checks state/nonce before creating its local session.

Code example

// Pseudocode: use a maintained OpenID Connect client library in production
const tokens = await oidcClient.callback(redirectUri, params, {
  state: expectedState,
  nonce: expectedNonce,
});
const claims = tokens.claims();
if (claims.iss !== configuredIssuer || !claims.sub) {
  throw new Error("Invalid identity token");
}

Diagram

Browser → OIDC Provider → Authorization Code → Backend callback → Validate state/nonce/token → App session

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q43JWT

How should JWT signatures be validated?

Interview answer covering how should jwt signatures be validated? with a practical implementation pattern.

Answer

How should JWT signatures be validated? is a core application-security concept in jwt. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

JWT = base64url(header) + '.' + base64url(payload) + '.' + signature

Example

An API accepts a JWT only after validating its signature and expected issuer, audience, and lifetime.

Code example

// Pseudocode: verify with a trusted key and explicit algorithm allow-list
const claims = await jwtVerify(token, trustedJwks, {
  algorithms: ["RS256"],
  issuer: "https://identity.example.com/",
  audience: "orders-api",
});
if (claims.payload.exp === undefined) throw new Error("Missing expiry");

Diagram

JWT received → Parse safely → Verify signature/key/algorithm → Validate iss/aud/exp → Authorize request

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q44JWT

What are exp, nbf, iat, iss, and aud claims?

Interview answer covering what are exp, nbf, iat, iss, and aud claims? with a practical implementation pattern.

Answer

What are exp, nbf, iat, iss, and aud claims? is a core application-security concept in jwt. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

JWT = base64url(header) + '.' + base64url(payload) + '.' + signature

Example

An API accepts a JWT only after validating its signature and expected issuer, audience, and lifetime.

Code example

// Pseudocode: verify with a trusted key and explicit algorithm allow-list
const claims = await jwtVerify(token, trustedJwks, {
  algorithms: ["RS256"],
  issuer: "https://identity.example.com/",
  audience: "orders-api",
});
if (claims.payload.exp === undefined) throw new Error("Missing expiry");

Diagram

JWT received → Parse safely → Verify signature/key/algorithm → Validate iss/aud/exp → Authorize request

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q46JWT

Where should browser applications store tokens?

Interview answer covering where should browser applications store tokens? with a practical implementation pattern.

Answer

Where should browser applications store tokens? is a core application-security concept in jwt. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q49JWT

How do you handle clock skew?

Interview answer covering how do you handle clock skew? with a practical implementation pattern.

Answer

How do you handle clock skew? is a core application-security concept in jwt. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

JWT = base64url(header) + '.' + base64url(payload) + '.' + signature

Example

An API accepts a JWT only after validating its signature and expected issuer, audience, and lifetime.

Code example

// Pseudocode: verify with a trusted key and explicit algorithm allow-list
const claims = await jwtVerify(token, trustedJwks, {
  algorithms: ["RS256"],
  issuer: "https://identity.example.com/",
  audience: "orders-api",
});
if (claims.payload.exp === undefined) throw new Error("Missing expiry");

Diagram

JWT received → Parse safely → Verify signature/key/algorithm → Validate iss/aud/exp → Authorize request

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q55OWASP risks

What is SSRF?

Interview answer covering what is ssrf? with a practical implementation pattern.

Answer

What is SSRF? is a core application-security concept in owasp risks. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q56OWASP risks

What is insecure design?

Interview answer covering what is insecure design? with a practical implementation pattern.

Answer

What is insecure design? is a core application-security concept in owasp risks. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q58OWASP risks

What is security logging and monitoring failure?

Interview answer covering what is security logging and monitoring failure? with a practical implementation pattern.

Answer

What is security logging and monitoring failure? is a core application-security concept in owasp risks. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Content-Security-Policy: default-src 'self'; object-src 'none'; base-uri 'self'

Example

Use contextual output encoding, avoid unsafe HTML insertion, and set a restrictive Content Security Policy.

Code example

app.use(helmet({
  contentSecurityPolicy: {
    directives: {
      defaultSrc: ["'self'"],
      objectSrc: ["'none'"],
      baseUri: ["'self'"],
    },
  },
}));

Diagram

Untrusted content → Validate/encode → Safe rendering + CSP → Reduced browser attack surface

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q59OWASP risks

How do you prevent path traversal?

Interview answer covering how do you prevent path traversal? with a practical implementation pattern.

Answer

How do you prevent path traversal? is a core application-security concept in owasp risks. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q62Secure API design

How do you enforce object-level authorization?

Interview answer covering how do you enforce object-level authorization? with a practical implementation pattern.

Answer

How do you enforce object-level authorization? is a core application-security concept in secure api design. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q63Secure API design

What is mass assignment and how do you prevent it?

Interview answer covering what is mass assignment and how do you prevent it? with a practical implementation pattern.

Answer

What is mass assignment and how do you prevent it? is a core application-security concept in secure api design. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q65Secure API design

How do you rate-limit APIs?

Interview answer covering how do you rate-limit apis? with a practical implementation pattern.

Answer

How do you rate-limit APIs? is a core application-security concept in secure api design. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q67Secure API design

How should API errors be returned?

Interview answer covering how should api errors be returned? with a practical implementation pattern.

Answer

How should API errors be returned? is a core application-security concept in secure api design. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q70Secure API design

How do you version and deprecate APIs securely?

Interview answer covering how do you version and deprecate apis securely? with a practical implementation pattern.

Answer

How do you version and deprecate APIs securely? is a core application-security concept in secure api design. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q73Security testing and operations

How should security audit logs be designed?

Interview answer covering how should security audit logs be designed? with a practical implementation pattern.

Answer

How should security audit logs be designed? is a core application-security concept in security testing and operations. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Content-Security-Policy: default-src 'self'; object-src 'none'; base-uri 'self'

Example

Use contextual output encoding, avoid unsafe HTML insertion, and set a restrictive Content Security Policy.

Code example

app.use(helmet({
  contentSecurityPolicy: {
    directives: {
      defaultSrc: ["'self'"],
      objectSrc: ["'none'"],
      baseUri: ["'self'"],
    },
  },
}));

Diagram

Untrusted content → Validate/encode → Safe rendering + CSP → Reduced browser attack surface

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q75Security testing and operations

How do you manage dependency vulnerabilities?

Interview answer covering how do you manage dependency vulnerabilities? with a practical implementation pattern.

Answer

How do you manage dependency vulnerabilities? is a core application-security concept in security testing and operations. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.

Advanced Questions

Architecture, optimization, and design trade-offs.

Q18Authentication and sessions

How do password-reset flows stay secure?

Interview answer covering how do password-reset flows stay secure? with a practical implementation pattern.

Answer

How do password-reset flows stay secure? is a core application-security concept in authentication and sessions. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Set-Cookie: __Host-session=...; Path=/; Secure; HttpOnly; SameSite=Lax

Example

After successful authentication, rotate the session ID and set a secure, HttpOnly cookie.

Code example

// Illustrative session configuration
app.use(session({
  name: "__Host-session",
  secret: process.env.SESSION_SECRET,
  cookie: { secure: true, httpOnly: true, sameSite: "lax", path: "/" },
  resave: false,
  saveUninitialized: false,
}));

Diagram

Credentials + MFA → Verify → Rotate session ID → Secure cookie → Authorized requests

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q19Authentication and sessions

How do you implement account lockout safely?

Interview answer covering how do you implement account lockout safely? with a practical implementation pattern.

Answer

How do you implement account lockout safely? is a core application-security concept in authentication and sessions. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Set-Cookie: __Host-session=...; Path=/; Secure; HttpOnly; SameSite=Lax

Example

After successful authentication, rotate the session ID and set a secure, HttpOnly cookie.

Code example

// Illustrative session configuration
app.use(session({
  name: "__Host-session",
  secret: process.env.SESSION_SECRET,
  cookie: { secure: true, httpOnly: true, sameSite: "lax", path: "/" },
  resave: false,
  saveUninitialized: false,
}));

Diagram

Credentials + MFA → Verify → Rotate session ID → Secure cookie → Authorized requests

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q20Authentication and sessions

How should logout and token revocation work?

Interview answer covering how should logout and token revocation work? with a practical implementation pattern.

Answer

How should logout and token revocation work? is a core application-security concept in authentication and sessions. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q29OAuth 2.0

How should refresh-token rotation work?

Interview answer covering how should refresh-token rotation work? with a practical implementation pattern.

Answer

How should refresh-token rotation work? is a core application-security concept in oauth 2.0. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q30OAuth 2.0

How do you validate OAuth access tokens?

Interview answer covering how do you validate oauth access tokens? with a practical implementation pattern.

Answer

How do you validate OAuth access tokens? is a core application-security concept in oauth 2.0. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q37OpenID Connect

What is JWKS and key rotation?

Interview answer covering what is jwks and key rotation? with a practical implementation pattern.

Answer

What is JWKS and key rotation? is a core application-security concept in openid connect. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

ID token validation: signature + iss + aud + exp + nonce (when sent)

Example

After sign-in, the relying party validates the ID token and checks state/nonce before creating its local session.

Code example

// Pseudocode: use a maintained OpenID Connect client library in production
const tokens = await oidcClient.callback(redirectUri, params, {
  state: expectedState,
  nonce: expectedNonce,
});
const claims = tokens.claims();
if (claims.iss !== configuredIssuer || !claims.sub) {
  throw new Error("Invalid identity token");
}

Diagram

Browser → OIDC Provider → Authorization Code → Backend callback → Validate state/nonce/token → App session

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q38OpenID Connect

How do you validate an ID token?

Interview answer covering how do you validate an id token? with a practical implementation pattern.

Answer

How do you validate an ID token? is a core application-security concept in openid connect. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Authorization: Bearer <access_token>

Example

A client obtains a short-lived access token from the authorization server and sends it to the API over HTTPS.

Code example

// Express-style bearer-token validation (illustrative; use a vetted OIDC/JWT library)
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith("Bearer ")) {
  return res.status(401).json({ error: "unauthorized" });
}
const token = authHeader.slice("Bearer ".length);
// validate signature, issuer, audience, expiry, and allowed algorithms
const claims = await verifyAccessToken(token);
req.auth = { sub: claims.sub, scopes: claims.scope?.split(" ") ?? [] };

Diagram

Client → Authorization Server → Access Token → Resource API → Validate token + scopes → Response

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q40OpenID Connect

How do you secure a sign-in callback?

Interview answer covering how do you secure a sign-in callback? with a practical implementation pattern.

Answer

How do you secure a sign-in callback? is a core application-security concept in openid connect. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

ID token validation: signature + iss + aud + exp + nonce (when sent)

Example

After sign-in, the relying party validates the ID token and checks state/nonce before creating its local session.

Code example

// Pseudocode: use a maintained OpenID Connect client library in production
const tokens = await oidcClient.callback(redirectUri, params, {
  state: expectedState,
  nonce: expectedNonce,
});
const claims = tokens.claims();
if (claims.iss !== configuredIssuer || !claims.sub) {
  throw new Error("Invalid identity token");
}

Diagram

Browser → OIDC Provider → Authorization Code → Backend callback → Validate state/nonce/token → App session

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q45JWT

How do you prevent algorithm-confusion attacks?

Interview answer covering how do you prevent algorithm-confusion attacks? with a practical implementation pattern.

Answer

How do you prevent algorithm-confusion attacks? is a core application-security concept in jwt. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

JWT = base64url(header) + '.' + base64url(payload) + '.' + signature

Example

An API accepts a JWT only after validating its signature and expected issuer, audience, and lifetime.

Code example

// Pseudocode: verify with a trusted key and explicit algorithm allow-list
const claims = await jwtVerify(token, trustedJwks, {
  algorithms: ["RS256"],
  issuer: "https://identity.example.com/",
  audience: "orders-api",
});
if (claims.payload.exp === undefined) throw new Error("Missing expiry");

Diagram

JWT received → Parse safely → Verify signature/key/algorithm → Validate iss/aud/exp → Authorize request

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q47JWT

How do you revoke a JWT before expiry?

Interview answer covering how do you revoke a jwt before expiry? with a practical implementation pattern.

Answer

How do you revoke a JWT before expiry? is a core application-security concept in jwt. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

JWT = base64url(header) + '.' + base64url(payload) + '.' + signature

Example

An API accepts a JWT only after validating its signature and expected issuer, audience, and lifetime.

Code example

// Pseudocode: verify with a trusted key and explicit algorithm allow-list
const claims = await jwtVerify(token, trustedJwks, {
  algorithms: ["RS256"],
  issuer: "https://identity.example.com/",
  audience: "orders-api",
});
if (claims.payload.exp === undefined) throw new Error("Missing expiry");

Diagram

JWT received → Parse safely → Verify signature/key/algorithm → Validate iss/aud/exp → Authorize request

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q48JWT

What is a JWT key rotation strategy?

Interview answer covering what is a jwt key rotation strategy? with a practical implementation pattern.

Answer

What is a JWT key rotation strategy? is a core application-security concept in jwt. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

JWT = base64url(header) + '.' + base64url(payload) + '.' + signature

Example

An API accepts a JWT only after validating its signature and expected issuer, audience, and lifetime.

Code example

// Pseudocode: verify with a trusted key and explicit algorithm allow-list
const claims = await jwtVerify(token, trustedJwks, {
  algorithms: ["RS256"],
  issuer: "https://identity.example.com/",
  audience: "orders-api",
});
if (claims.payload.exp === undefined) throw new Error("Missing expiry");

Diagram

JWT received → Parse safely → Verify signature/key/algorithm → Validate iss/aud/exp → Authorize request

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q60OWASP risks

How do you reduce deserialization risks?

Interview answer covering how do you reduce deserialization risks? with a practical implementation pattern.

Answer

How do you reduce deserialization risks? is a core application-security concept in owasp risks. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q68Secure API design

How do you secure file uploads?

Interview answer covering how do you secure file uploads? with a practical implementation pattern.

Answer

How do you secure file uploads? is a core application-security concept in secure api design. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q69Secure API design

How do you protect webhooks?

Interview answer covering how do you protect webhooks? with a practical implementation pattern.

Answer

How do you protect webhooks? is a core application-security concept in secure api design. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q72Security testing and operations

How do you threat-model an API endpoint?

Interview answer covering how do you threat-model an api endpoint? with a practical implementation pattern.

Answer

How do you threat-model an API endpoint? is a core application-security concept in security testing and operations. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.
Q74Security testing and operations

How do you handle a suspected credential leak?

Interview answer covering how do you handle a suspected credential leak? with a practical implementation pattern.

Answer

How do you handle a suspected credential leak? is a core application-security concept in security testing and operations. The practical goal is to reduce unauthorized access, data exposure, and abuse by applying a documented policy consistently. Use secure defaults, validate trust boundaries, fail closed, and rely on maintained security libraries rather than custom cryptography. Verify the control with automated tests and review its configuration in the deployment environment.

Syntax

Validate input → Authenticate → Authorize → Execute safely → Audit

Example

A request is validated, authenticated, authorized for the target resource, processed with safe APIs, and logged without secrets.

Code example

app.get("/api/resource/:id", requireAuthentication, async (req, res) => {
  const resource = await repository.findById(req.params.id);
  if (!resource || resource.ownerId !== req.auth.sub) {
    return res.status(404).json({ error: "not_found" });
  }
  res.json({ id: resource.id, name: resource.name });
});

Diagram

Request → Validate → Authenticate → Authorize → Business logic → Safe response + audit

Key Points

  • Define the threat and the security boundary before implementing the control.
  • Use vetted framework/library features; avoid custom cryptography or token parsing.
  • Fail closed and return minimal error details to clients.
  • Add positive and negative tests, including expired, missing, malformed, and unauthorized cases.

Share this question bank

Send this page to someone preparing for an interview.