1313 AuthorizeResponsePayload ,
1414 ResponseMode ,
1515)
16+ from pyeudiw .jwt .utils import decode_jwt_header
1617
1718
1819_S = TypeVar ('_S' , str , list [str ])
@@ -117,8 +118,15 @@ class DirectPostJwtJweParser(AuthorizationResponseParser):
117118 https://openid.net/specs/openid-4-verifiable-presentations-1_0.html#name-response-mode-direct_postjw
118119 """
119120
120- def __init__ (self , jwe_decryptor : JWEHelper ):
121+ def __init__ (
122+ self ,
123+ jwe_decryptor : JWEHelper ,
124+ enc_alg_supported : list [str ] = [],
125+ enc_enc_supported : list [str ] = []
126+ ) -> None :
121127 self .jwe_decryptor = jwe_decryptor
128+ self .enc_alg_supported = enc_alg_supported
129+ self .enc_enc_supported = enc_enc_supported
122130
123131 def parse_and_validate (
124132 self , context : satosa .context .Context
@@ -131,6 +139,19 @@ def parse_and_validate(
131139 raise AuthRespParsingException (
132140 "invalid data in direct_post.jwt request body" , e
133141 )
142+
143+ header = decode_jwt_header (resp_data .response )
144+
145+ if not header .get ("alg" ) in self .enc_alg_supported :
146+ raise AuthRespValidationException (
147+ "invalid data in direct_post.jwt: alg not supported"
148+ )
149+
150+ if not header .get ("enc" ) in self .enc_enc_supported :
151+ raise AuthRespValidationException (
152+ "invalid data in direct_post.jwt: enc not supported"
153+ )
154+
134155 try :
135156 payload = self .jwe_decryptor .decrypt (resp_data .response )
136157 except JWEDecryptionError as e :
0 commit comments