Missing JWT signature verification

Missing JWT signature verification

Description

Enabling noVerify in jwt-simple reads JWT claims without verifying the signature.

Potential impact

Using those claims to identify a user or grant permissions may expose sensitive data under another user’s account.

Remediation

Use a maintained JWT library to verify the signature and protect the signing or verification key. Enforce the allowed algorithm, issuer, audience and expiration policy on the server, then check the user’s access permissions.

Examples

The excerpts omit token extraction from Authorization and validation of the key configuration. For a standard Bearer header, strip the prefix and pass only the JWT string.

Before

javascript
const jwt = require('jwt-simple');
const secret = process.env.JWT_SECRET;

app.get('/profile', (req, res) => {
  const token = req.headers.authorization;
  // ⚠️ Decode without verifying the signature
  const decoded = jwt.decode(token, secret, true);
  res.json({ user: decoded.username });
});

After

javascript
const jwt = require('jwt-simple');
const secret = process.env.JWT_SECRET;

app.get('/profile', (req, res) => {
  const token = req.headers.authorization;
  try {
    // ✅ Verify the signature
    const decoded = jwt.decode(token, secret, false); // or omit the noVerify argument
    res.json({ user: decoded.username });
  } catch (error) {
    res.status(401).json({ error: 'Unauthorized. Invalid token.' });
  }
});

With its third argument, noVerify, set to false, jwt.decode() verifies the signature. The handler returns HTTP 401 on failure. This call does not pin the allowed algorithm or check issuer and audience. Enforce those separately.

References