Your Node.js service uses JWTs, and a tester forged a token with `"alg": "none"`. How do you fix it?
IntermediateScenarioVulnerability Management and OWASP
Answer
Situation read → The verification code accepted whatever algorithm the token declared. Anyone can mint admin tokens.
What I'd do →
- Pin allowed algorithms in verification:
jwt.verify(token, publicKey, { algorithms: ['RS256'], issuer: 'https://auth.example.com', audience: 'api' }); - Upgrade the JWT library; current versions reject
noneby default. - Validate
exp,issandaud, and keep access tokens short-lived (5–15 minutes). - Rotate the signing key and invalidate active sessions if forged tokens were used.
- Look for the related key-confusion bug (RS256 public key used as HS256 secret).
Why → Never let the token tell the server how to verify it.
Interview tip → "Algorithm allowlist" is the key phrase.
More on Vulnerability Management and OWASP
A pentest report shows SQL injection in a search endpoint of a Java service. How do you handle it end to end?BeginnerA scanner reports 4,000 open CVEs across 300 images. The team can fix maybe 100 a month. How do you prioritise?IntermediateA user reports they can see another customer's invoice by changing the ID in the URL. What do you do?BeginnerA webhook feature lets users enter a URL, and a pentester used it to read the cloud metadata endpoint. How do you fix it?AdvancedA team still runs Log4j 2.14 in an internal service and says it is not internet-facing. How do you respond?IntermediateA security review finds passwords stored as unsalted MD5 hashes. How do you migrate without forcing every user to reset?Advanced