liveBook · Manning

Alg:none vulnerability

As explained in Software Security for Developers

alg:none is a JWS algorithm identifier indicating that no digital signature or message authentication code is applied.

alg:none is a JWS algorithm identifier meaning that no digital signature or message authentication code is applied. If a verifier accepts it, an attacker can alter the header and payload while bypassing signature validation. section 11.4.2

A production failure mode

An attacker could intercept a JWS, change its alg field to none, modify the payload, and forward the request. The United Kingdom’s NHS COVID-19 Android contact-tracing app was reported affected in October 2020. section 11.4.2

Avoid the vulnerability by:

  • Rejecting alg:none explicitly in JWS or JWT library configuration. section 11.4.2
  • Parsing the compact JWS, verifying it with the expected secret or key, and treating exceptions or failed verification as invalid. section 11.4.2
Listing 11.3 Verifying a JWS object using Nimbus
public final class JwsUtil {

  private static final byte[] HMAC_SECRET = 
     Base64.getDecoder().decode(
       "VGhpc0lzQS1EZW1vLVNlY3JldC1LZXktR
       ➥m9yLUhTMjU2LUF0TGVhc3QtMzJCeXRlcyE="
    );

  public static boolean verifyJws(String compactJws) {
    try {
      JWSObject parsed = JWSObject.parse(compactJws);   #1
      return parsed.verify(new MACVerifier(HMAC_SECRET));   #2
    } catch (ParseException | JOSEException e) {
      return false;
    }
  }
}

Nimbus verification parses the JWS and checks it with MACVerifier; its verifier rejects alg:none rather than accepting an unsigned token. section 11.4.2

How Software Security for Developers covers it

How deep it goes
Explains the tampering sequence and defensive configuration, but does not descend into cryptographic internals.
Examples
Uses the NHS contact-tracing app incident and Nimbus MACVerifier code as concrete security examples.
What it assumes
Assumes basic awareness of JWS headers, payloads, signatures, and verification while defining the vulnerability directly.
What you can do after
Diagnose alg:none acceptance and configure JWS or JWT verification to reject unsigned tokens.
How it connects
Connects JWS verification with JWT, HMAC, digital signatures, and JOSE library configuration.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Security for Developers. The section links point to the parts of the book it draws on.