|
14 | 14 |
|
15 | 15 | import jwt |
16 | 16 | import time |
17 | | -from typing import Dict, List |
| 17 | +from typing import Any, Dict, List, Tuple |
18 | 18 |
|
19 | 19 | import planet_auth.logging.auth_logger |
20 | 20 | from planet_auth.auth_exception import AuthException, InvalidTokenException |
@@ -181,7 +181,7 @@ def validate_token( |
181 | 181 | """ |
182 | 182 | # PyJWT should enforce this, but we have unit tests in case... |
183 | 183 | if not token_str: |
184 | | - raise InvalidArgumentException(message="Cannot validate empty string as a token") |
| 184 | + raise InvalidArgumentException(message="Cannot decode empty string as a token") |
185 | 185 | if not issuer: |
186 | 186 | # PyJWT does not seem to raise if the issuer is explicitly None, even when |
187 | 187 | # verify_iss was selected. |
@@ -257,9 +257,18 @@ def validate_token( |
257 | 257 | return validated_claims |
258 | 258 |
|
259 | 259 | @staticmethod |
260 | | - def hazmat_unverified_decode(token_str): |
261 | | - # WARNING: Treat unverified token claims like toxic waste. |
262 | | - # Nothing can be trusted until the token is verified. |
| 260 | + @InvalidArgumentException.recast(jwt.exceptions.DecodeError) |
| 261 | + def hazmat_unverified_decode(token_str) -> Tuple[Dict, Dict, Any]: |
| 262 | + """ |
| 263 | + Decode a JWT without verifying the signature or any claims. |
| 264 | +
|
| 265 | + !!! Warning |
| 266 | + Treat unverified token claims with extreme caution. |
| 267 | + Nothing can be trusted until the token is verified. |
| 268 | +
|
| 269 | + Returns: |
| 270 | + Returns the decoded JWT header, payload, and signature |
| 271 | + """ |
263 | 272 | unverified_complete = jwt.decode_complete(token_str, options={"verify_signature": False}) # nosemgrep |
264 | 273 | return unverified_complete["header"], unverified_complete["payload"], unverified_complete["signature"] |
265 | 274 |
|
|
0 commit comments