@@ -658,6 +658,22 @@ int jwt_builder_setb64(jwt_builder_t *builder, int b64);
658658JWT_EXPORT
659659int jwt_builder_set_detached (jwt_builder_t * builder , int detached );
660660
661+ /**
662+ * @brief Set the token media type ("typ" header)
663+ *
664+ * A convenience setter for the ``"typ"`` header parameter, naming the token's
665+ * media type — e.g. ``"at+jwt"`` (RFC 9068), ``"dpop+jwt"``, ``"secevent+jwt"``.
666+ * Equivalent to setting the ``"typ"`` header directly. Pair it with
667+ * jwt_checker_expect_typ() on the verifying side.
668+ *
669+ * @param builder Pointer to a builder object
670+ * @param typ The media type string, or NULL to clear it
671+ * @return 0 on success, non-zero otherwise with error set in the builder
672+ * @since 3.6.0
673+ */
674+ JWT_EXPORT
675+ int jwt_builder_settyp (jwt_builder_t * builder , const char * typ );
676+
661677/**
662678 * @brief Set IssuedAt usage on builder
663679 *
@@ -985,6 +1001,42 @@ JWT_EXPORT
9851001int jwt_checker_setkeyring (jwt_checker_t * checker , const jwk_set_t * keyring ,
9861002 jwt_verify_policy_t policy );
9871003
1004+ /**
1005+ * @brief Require a specific token media type ("typ" header)
1006+ *
1007+ * When set, jwt_checker_verify() rejects a token whose ``"typ"`` header does not
1008+ * match @p typ. The comparison is case-insensitive and tolerates the optional
1009+ * ``application/`` prefix (RFC 6838), so ``expect_typ(c, "at+jwt")`` accepts both
1010+ * ``"at+jwt"`` and ``"application/at+jwt"``. This is the standardized
1011+ * cross-JWT-confusion defense (@rfc{8725} §3.11).
1012+ *
1013+ * @param checker Pointer to a checker object
1014+ * @param typ The required media type, or NULL to clear the requirement
1015+ * @return 0 on success, non-zero otherwise with error set in the checker
1016+ * @since 3.6.0
1017+ */
1018+ JWT_EXPORT
1019+ int jwt_checker_expect_typ (jwt_checker_t * checker , const char * typ );
1020+
1021+ /**
1022+ * @brief Set an allowlist of acceptable algorithms
1023+ *
1024+ * Restricts the algorithms jwt_checker_verify() will accept to the given set,
1025+ * checked before any signature work (@rfc{8725}). Useful when verifying against
1026+ * a keyring (jwt_checker_setkeyring()) where several algorithms are acceptable,
1027+ * e.g. ``{JWT_ALG_RS256, JWT_ALG_ES256}``. A token whose ``"alg"`` is not in the
1028+ * set is rejected, which also blocks an ``alg:none`` downgrade. Passing @p n as
1029+ * 0 (or @p algs as NULL) clears the allowlist.
1030+ *
1031+ * @param checker Pointer to a checker object
1032+ * @param algs An array of acceptable ::jwt_alg_t values (copied)
1033+ * @param n The number of entries in @p algs
1034+ * @return 0 on success, non-zero otherwise with error set in the checker
1035+ * @since 3.6.0
1036+ */
1037+ JWT_EXPORT
1038+ int jwt_checker_setalgs (jwt_checker_t * checker , const jwt_alg_t * algs , size_t n );
1039+
9881040/**
9891041 * @brief Set a callback for generating tokens
9901042 *
0 commit comments