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.