SachinyadavAug20 opened a new issue, #77364:
URL: https://github.com/apache/airflow/issues/77364

   ### Under which category would you file this issue?
   
   Providers
   
   ### Apache Airflow version
   
   main (Airflow 3.0+)
   
   ### Apache Airflow Provider(s)
   
   amazon
   
   ### What happened and how to reproduce it?
   
   In `AwsAuthManager.deserialize_user()` 
(`providers/amazon/src/airflow/providers/amazon/aws/auth_manager/aws_auth_manager.py`):
   
   ```python
   def deserialize_user(self, token: dict[str, Any]) -> AwsAuthManagerUser:
       return AwsAuthManagerUser(
           user_id=token.pop("sub"),
           groups=token.get("groups", []),
           username=token.get("username"),
           email=token.get("email"),
       )
   ```
   
   Notice that `token.pop("sub")` mutates the caller's input dictionary 
in-place by removing the `"sub"` key.
   
   If `deserialize_user()` is called multiple times on the same claims 
dictionary, or if the decoded JWT dictionary is accessed by downstream 
authentication handlers or middleware that expect `"sub"` to remain intact, the 
in-place mutation can lead to unexpected `KeyError: 'sub'` or lost claims.
   
   In contrast, other auth managers access `"sub"` non-destructively:
   - `SimpleAuthManager`: `username=token["sub"]`
   - `FabAuthManager`: `user_id=int(token["sub"])`
   - `KeycloakAuthManager`: `user_id=token["user_id"]`
   
   ### What you think should happen instead?
   
   `AwsAuthManager.deserialize_user()` should access `"sub"` without mutating 
the input dictionary in place (i.e. `user_id=token["sub"]`).
   
   Additionally, unit tests should cover both `deserialize_user()` and 
`serialize_user()` in `test_aws_auth_manager.py`, asserting that the input 
dictionary is not modified in-place.
   
   ### Operating System
   
   Linux
   
   ### Deployment
   
   Other
   
   ### Are you willing to submit PR?
   
   [✓] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   [✓] I agree to follow this project's Code of Conduct
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to