Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add `alg` parameter to JWKS (#17363)
Lukasz Ostrowskie71c1f4caef7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 5173e3e8c9..57ae68877e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -61,3 +61,4 @@ All notable, unreleased changes to this project will be documented in this file.- Fixed 'healthcheck' middleware (`/health/` endpoint) not forwarding incoming traffic whenever the protocol wasn't HTTP (such as WebSocket or Lifespan) - #17248 by @NyanKiyoshi- Added support for the AWS_S3_URL_PROTOCOL environment variable - #17305 by @p-febis- Fixed pycurl dependency and required system libraries to fix Celery worker issues when using SQS by @mariobrgomes+- Added [`alg`](https://datatracker.ietf.org/doc/html/rfc7517#section-4.4) key to JWKS available at `/.well-known/jwks.json` - #17363 by @lkostrowskidiff --git a/saleor/core/jwt_manager.py b/saleor/core/jwt_manager.pyindex 6c4b641885..45eae9fa1a 100644--- a/saleor/core/jwt_manager.py+++ b/saleor/core/jwt_manager.py@@ -69,6 +69,7 @@ class JWTManagerBase:class JWTManager(JWTManagerBase):KEY_FILE_FOR_DEBUG = ".jwt_key.pem"+ _ALG = "RS256"@classmethoddef get_domain(cls) -> str:@@ -144,7 +145,7 @@ class JWTManager(JWTManagerBase):@classmethoddef get_jwks(cls) -> dict:jwk_dict = json.loads(RSAAlgorithm.to_jwk(cls.get_public_key()))- jwk_dict.update({"use": "sig", "kid": cls.get_key_id()})+ jwk_dict.update({"use": "sig", "kid": cls.get_key_id(), "alg": cls._ALG})return {"keys": [jwk_dict]}@classmethod@@ -166,7 +167,7 @@ class JWTManager(JWTManagerBase):return api_jwt.encode(payload,cls.get_private_key(),- algorithm="RS256",+ algorithm=cls._ALG,headers={"kid": cls.get_key_id()},)@@ -175,7 +176,7 @@ class JWTManager(JWTManagerBase):return api_jws.encode(payload,key=cls.get_private_key(),- algorithm="RS256",+ algorithm=cls._ALG,headers={"kid": cls.get_key_id(), "crit": ["b64"]},is_payload_detached=is_payload_detached,)@@ -185,11 +186,11 @@ class JWTManager(JWTManagerBase):# `verify_aud` set to false as we decode our own tokens# we can have `aud` defined for app or custom.headers = jwt.get_unverified_header(token)- if headers.get("alg") == "RS256":+ if headers.get("alg") == cls._ALG:return jwt.decode(token,cls.get_public_key(),- algorithms=["RS256"],+ algorithms=[cls._ALG],options={"verify_exp": verify_expiration, "verify_aud": verify_aud},)return jwt.decode(