Repository navigation
v3.7.0
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()andjwt_checker_verify_detached()reject an"alg":"none"token withUnsigned tokens are not allowedunless the application opts in. To accept unsigned tokens on purpose, listJWT_ALG_NONEinjwt_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, addJWT_ALG_NONEto 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:nonetokens. For a keyed checker with no allowlist, only the error text changes, fromExpected a signature, but JWT has nonetoUnsigned 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->keyNULL (for example, akidlookup that finds nothing) now rejects an unsigned token instead of accepting it. jwt-verifyrun with neither-knor-rnow rejects an unsigned token ([BAD] Unsigned tokens are not allowed, exit1). Add-a noneto 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/-lclustered with other options (#372),jwk2keypartial failures (#374),jwe-decryptstdin and extra arguments (#375), andjwt-generate's new limit of 32-coptions (#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 setconfig->alg = JWT_ALG_NONEused 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 afterjwt_checker_setkey(checker, JWT_ALG_RS256, key)), while the same token in Compact form was rejected.JWT_ALG_NONEfrom the callback now means "the key's ownalg" 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->algalone 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 onlySignature 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>"andNo 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 thejwt-verifyexit 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.
- A one-signature token (Flattened, or Compact via a keyring) reports that signature's own reason. Examples: the backend's verify error,
- EC private JWK consistency check (#368). Loading an EC private JWK now checks that
dis 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. Somed=0andd>=ncases on GnuTLS and MbedTLS still reportError 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.
- OpenSSL, GnuTLS and MbedTLS each perform the check. A key that fails gets
- 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, OKPx) now puts the key in error. - A non-string component never yields a private key. For a non-string
dbeside a valid public key, OpenSSL rejects the whole key, while GnuTLS and MbedTLS load only the public key. - Jansson builds are unchanged.
- A non-string required public member (RSA
- json-c: stricter parsing (#360). Before json-c parses any input (tokens, JWS/JWE JSON,
JWT_VALUE_JSONvalues, 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()andjwks_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()andjwe_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 barenullon both backends.
🧰 CLI tools
jwt-verify- With neither
-knor-r, an unsigned token is rejected unless-a noneis given (#352).--helpand thejwt-verify(1)man page describe this (#395). -hand-lexit0only when given on their own. Clustered forms such as-hv,-lqor-hlnow fail withERROR: --help and --list take no other argumentsand exit1, like the separated forms already did (#372). This tightens the rule introduced in 3.6.3. A bare-h,-l,--helpor--listis unchanged.- A
-rfailure 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).
- With neither
jwt-verifyandjwt-generate--verbose --print CMD: the tool is no longer killed by SIGPIPE (status 141) whenCMDexits 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 truepasses and-p falsefails at any size. - A failed
pipe()orfork(), 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.
- The command's exit status alone decides, so
jwk2keyexits1whenever 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 unsafekid, 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
-ddirectory 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.
- Each unwritten key gets one stderr line:
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 throughtr -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.
- Each of these cases now has its own error and exit
- 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, includingkey2jwk, which used to leak the key set it had built so far when a later input file failed to load (#364).jwt-generatenow accepts at most 32-c/--claimoptions.- In a few error cases (
jwt-generatewith a bad--claimtype,jwt-generateorjwt-verifywith 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 reportsInvalid --claim type [<spec>](wasInvalid --claim format), and the no-alg errors now readERR: No "alg" attribute in key and --algorithm not given(jwt-generate) andERR: 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
-Werrorat-O2/-O3with-fsanitize=address, or at-O2with-fsanitize=undefined(#363). A new Sanitizer (ASan+UBSan+LSan) CI row builds at-O2with-Werrorand runs the suite under LeakSanitizer (#364). ctest -T memchecknow fails when valgrind reports an error or a definite leak (--error-exitcode=1 --errors-for-leak-kinds=definite). Before, it listed the defects but exited0(#366). A newtests/valgrind-bats.supp, set asMEMORYCHECK_SUPPRESSIONS_FILEand overridable at configure time, hides leaks in the system programs the bats test runs. Plainmake checkis unaffected.- The
jwt_clibats test finds its key fixtures through${SRCDIR}, so it passes in a nested build directory (e.g.build/rel).make checkandmake check-code-coveragenow build the CLI tools first, so a fresh build directory no longer needsmake allbeforehand (#367).
Full Changelog: v3.6.4...v3.7.0