Skip to content

v3.7.0

Choose a tag to compare

@benmcollins benmcollins released this 20 Nov 16:52
· 18 commits to master since this release
1ec7775

LibJWT 3.7.0 is a feature and hardening release. A jwt_checker_t now rejects unsigned ("alg":"none") tokens by default. The JWS JSON and keyring verify paths now pin the algorithm the same way the Compact path does, and they report why a signature failed. EC private JWKs are checked against their public key when loaded. The json-c backend now rejects malformed JSON that Jansson already rejected. The CLI tools have stricter exit statuses and stricter input handling. Read the behavior changes below before upgrading.

This release is ABI-compatible with 3.6.4. An nm diff shows the same 155 exported symbols, so per the libtool rules only the SONAME revision advances (18:4:4 → 18:5:4). The SONAME stays libjwt.so.14 and existing binaries keep working. No API was added. Some of the behavior changes below may still need application or script changes.

⚠️ Behavior changes

  • Unsigned tokens are rejected by default (#352, RFC 8725 §3.2). jwt_checker_verify() and jwt_checker_verify_detached() reject an "alg":"none" token with Unsigned tokens are not allowed unless the application opts in. To accept unsigned tokens on purpose, list JWT_ALG_NONE in jwt_checker_setalgs(), alone or alongside signed algorithms:
    const jwt_alg_t algs[] = { JWT_ALG_NONE };
    jwt_checker_setalgs(checker, algs, 1);
    • jwt_checker_setalgs() replaces any existing allowlist. If you already set one, add JWT_ALG_NONE to that same list.
    • Affected: applications that verify unsigned tokens on purpose, with a checker that has no key or keyring, or with jwt_checker_setkey(checker, JWT_ALG_NONE, NULL).
    • Unaffected verdicts: keyed, keyring and embedded-JWK checkers already rejected alg:none tokens. For a keyed checker with no allowlist, only the error text changes, from Expected a signature, but JWT has none to Unsigned tokens are not allowed.
    • With no allowlist, every signed algorithm is still accepted. A non-empty allowlist decides, as before.
    • A keyless checker whose verify callback leaves config->key NULL (for example, a kid lookup that finds nothing) now rejects an unsigned token instead of accepting it.
    • jwt-verify run with neither -k nor -r now rejects an unsigned token ([BAD] Unsigned tokens are not allowed, exit 1). Add -a none to decode it as before.
  • Algorithm pinning when a callback sets config->alg = JWT_ALG_NONE (#353). On the JWS JSON and keyring paths, a key with no "alg" now verifies nothing in this case. Give the key an "alg", or set a concrete algorithm in the callback.
  • Error text on the JWS JSON and keyring paths (#354). Code or scripts that match Signature policy not met (...) must be updated. A single-signature failure now reports its own reason. A multi-signature failure keeps the summary and appends ; signature N: <reason>.
  • Inconsistent EC private JWKs no longer load (#368). Regenerate or fix any such key.
  • json-c backend: non-standard JSON and non-string JWK key members are rejected, as on Jansson (#359, #360). On both backends, passing "null" to the five *_add_*_json() header setters now fails (#358).
  • CLI exit statuses and input rules: jwt-verify -h/-l clustered with other options (#372), jwk2key partial failures (#374), jwe-decrypt stdin and extra arguments (#375), and jwt-generate's new limit of 32 -c options (#364). Details are under CLI tools below.

🔐 Library

  • Consistent algorithm pinning (#353). The JWS JSON verify path covers Flattened and General tokens, and also Compact tokens checked against a keyring (jwt_checker_setkeyring()). On that path, a verify callback that set config->alg = JWT_ALG_NONE used to drop the algorithm pin. With a key that has no "alg", any algorithm of the right key type then verified (for example RS512 or PS256 after jwt_checker_setkey(checker, JWT_ALG_RS256, key)), while the same token in Compact form was rejected.
    • JWT_ALG_NONE from the callback now means "the key's own alg" on every path. An explicit key with an "alg" is pinned to it, and a key without one verifies nothing. During a keyring scan, keys without an "alg" are skipped.
    • Compact, Flattened and General forms of a token now get the same verdict.
    • Callbacks that leave config->alg alone or set a concrete algorithm, and checkers with no callback, behave exactly as before.
  • Specific failure reasons on the JWS JSON and keyring paths (#354). jwt_checker_error_msg() no longer reports only Signature policy not met (N of M verified).
    • A one-signature token (Flattened, or Compact via a keyring) reports that signature's own reason. Examples: the backend's verify error, Key type does not match JWT alg, Config alg does not match JWT, Key has no "alg" to verify the signature, No signature key with "kid" "<kid>" in the keyring, No keyring key can verify "<ALG>" and No keyring key verified the signature (N tried).
    • A General token with several signatures keeps the summary and appends the first unverified signature's 0-based index and reason, e.g. Signature policy not met (1 of 2 verified); signature 1: Config alg does not match JWT.
    • Only the text changes. Verdicts, return values, the jwt_checker_sig_*() accessors and the jwt-verify exit codes are unchanged. Some cases still word things differently on the JSON path and the Compact single-key path, and the backend's verify-failure text varies by crypto backend.
  • EC private JWK consistency check (#368). Loading an EC private JWK now checks that d is the private key for the JWK's (x, y) point (RFC 7518 §6.2.2.1).
    • OpenSSL, GnuTLS and MbedTLS each perform the check. A key that fails gets jwks_item_error() set and is not used, while the rest of the set still loads.
    • The error is EC private key does not match its public key. Some d=0 and d>=n cases on GnuTLS and MbedTLS still report Error importing EC private key.
    • Before, depending on the backend, such a key could load and then sign tokens that nothing could verify.
    • The check covers EC JWKs only. PEM/DER input is unchanged.
  • json-c: non-string key members (#359). A JWK member that should be a string but holds a number, boolean, array or object is no longer read as its JSON text. For example, {"kty":"RSA","n":12345678,"e":"AQAB"} used to load as a bogus 48-bit RSA key with OpenSSL.
    • A non-string required public member (RSA n, OKP x) now puts the key in error.
    • A non-string component never yields a private key. For a non-string d beside a valid public key, OpenSSL rejects the whole key, while GnuTLS and MbedTLS load only the public key.
    • Jansson builds are unchanged.
  • json-c: stricter parsing (#360). Before json-c parses any input (tokens, JWS/JWE JSON, JWT_VALUE_JSON values, JWKS), libjwt now scans it and rejects a raw control character (U+0000–U+001F) inside a string or member name, single-quoted strings, and // or /* */ comments, as Jansson does.
    • For example, an HS256 token whose payload holds a raw TAB inside a string no longer verifies on json-c.
    • jwks_load_fromfile() and jwks_load_fromfp() on json-c now parse the whole file by its length, so data after an embedded NUL counts as trailing data instead of being silently ignored.
    • json-c is still more lenient than Jansson in some cases (trailing commas, NaN/Infinity, case-insensitive literals, leading zeros, lone surrogate escapes, invalid UTF-8).
  • JSON header setters (#358). jwt_signature_add_protected_json(), jwt_signature_add_header_json(), jwe_builder_add_protected_json(), jwe_builder_add_unprotected_json() and jwe_recipient_add_header_json() now accept a bare number or boolean (1, -1, 1.5, true, false) on json-c, as on Jansson. They refuse a bare null on both backends.

🧰 CLI tools

  • jwt-verify
    • With neither -k nor -r, an unsigned token is rejected unless -a none is given (#352). --help and the jwt-verify(1) man page describe this (#395).
    • -h and -l exit 0 only when given on their own. Clustered forms such as -hv, -lq or -hl now fail with ERROR: --help and --list take no other arguments and exit 1, like the separated forms already did (#372). This tightens the rule introduced in 3.6.3. A bare -h, -l, --help or --list is unchanged.
    • A -r failure now prints the specific reason (e.g. Token failed verification) instead of the policy count (#354).
    • Reading tokens from stdin (-) is faster where stdio locks the stream on every byte, mainly macOS. The stdin lock is now taken once per line, which cut bulk-input runs by about 37–86% in the issue's benchmarks, with little change on glibc/Linux. Results are unchanged (#373).
  • jwt-verify and jwt-generate --verbose --print CMD: the tool is no longer killed by SIGPIPE (status 141) when CMD exits or stops reading before it has consumed a header or payload larger than the pipe buffer (#371).
    • The command's exit status alone decides, so -p true passes and -p false fails at any size.
    • A failed pipe() or fork(), or a write error other than a broken pipe, now fails only that token instead of ending the whole run.
    • Both man pages note that the command need not read all of its input.
  • jwk2key exits 1 whenever it did not write every key it was given (#374). That includes an input file that cannot be read or parsed (Error reading <file>: <reason>), a key set with no keys (<file>: No keys found), a key that fails to load, a key with an unsafe kid, an existing output file without -r, and a failed write. Keys that do convert are still written.
    • Each unwritten key gets one stderr line: <file>: key <index> (kid "<kid>"): <reason>. Keys that failed to load used to be dropped silently.
    • A partly written file is deleted.
    • The -d directory is checked before any input is read and must be writable (<dir>: not an existing writable directory).
    • A key the active backend cannot export as PEM (e.g. Ed25519 under MbedTLS) is now reported as no PEM available for this key .... Before, the tool wrote (null) or crashed.
    • jwk2key(1) has a new EXIT STATUS section, and the usage text describes the exit status. Scripts that parsed the old messages need updating.
  • jwe-decrypt (#375). With no token argument, it reads all of stdin as exactly one token. One trailing LF, CRLF or CR is dropped.
    • Each of these cases now has its own error and exit 1: a NUL byte, input of 1 MiB or more, a Compact token with a CR or LF left inside it (a second token, or a token split over lines), empty stdin, and a read error.
    • Blank lines before or after a Compact token (more than one trailing line end) are now rejected too, reported as stdin has more than one token. Strip them, e.g. pipe through tr -d '\r\n'.
    • A JSON-serialized token may still span lines (e.g. pretty-printed with jq .).
    • On the command line, more than one token argument is now a usage error. Before, the extra arguments were ignored.
  • All tools (jwt-generate, jwt-verify, jwe-encrypt, jwe-decrypt, jwk2key, key2jwk) free everything on every path. They no longer leak or fail under LeakSanitizer, including key2jwk, which used to leak the key set it had built so far when a later input file failed to load (#364).
    • jwt-generate now accepts at most 32 -c/--claim options.
    • In a few error cases (jwt-generate with a bad --claim type, jwt-generate or jwt-verify with a key that has no "alg" and no -a), the tools print only a reworded error instead of the error followed by the usage text. A bad claim type now reports Invalid --claim type [<spec>] (was Invalid --claim format), and the no-alg errors now read ERR: No "alg" attribute in key and --algorithm not given (jwt-generate) and ERR: Key does not contain an "alg" attribute and no --algorithm given (jwt-verify), where they used to say --alg.
    • Exit statuses are unchanged.

🏗️ Build, CI & tests

  • libjwt builds again with gcc 15 under -Werror at -O2/-O3 with -fsanitize=address, or at -O2 with -fsanitize=undefined (#363). A new Sanitizer (ASan+UBSan+LSan) CI row builds at -O2 with -Werror and runs the suite under LeakSanitizer (#364).
  • ctest -T memcheck now fails when valgrind reports an error or a definite leak (--error-exitcode=1 --errors-for-leak-kinds=definite). Before, it listed the defects but exited 0 (#366). A new tests/valgrind-bats.supp, set as MEMORYCHECK_SUPPRESSIONS_FILE and overridable at configure time, hides leaks in the system programs the bats test runs. Plain make check is unaffected.
  • The jwt_cli bats test finds its key fixtures through ${SRCDIR}, so it passes in a nested build directory (e.g. build/rel). make check and make check-code-coverage now build the CLI tools first, so a fresh build directory no longer needs make all beforehand (#367).

Full Changelog: v3.6.4...v3.7.0