Skip to content

Conversation

@petrkalos
Copy link
Contributor

Feature or Bugfix

  • Bugfix

Detail

Currently when access is denied we raise exceptions which have 2 side effects

  • APIGW returns 500 Internal Server Error to the user which is confusing
  • Deny cache is not populated hence increasing the traffic that IdP is receiving

In this change we return an explicit Deny policy for all known scenarios and raise an exception otherwise.
The known scenarios include

  • We receive 401 from Cognito which means invalid access token (unauthorized access)
  • We receive 403 from Cognito which means throttling
  • We fail to validate the jwt token returned by Cognito

Relates

Security

Please answer the questions below briefly where applicable, or write N/A. Based on
OWASP 10.

  • Does this PR introduce or modify any input fields or queries - this includes
    fetching data from storage outside the application (e.g. a database, an S3 bucket)?
    • Is the input sanitized?
    • What precautions are you taking before deserializing the data you consume?
    • Is injection prevented by parametrizing queries?
    • Have you ensured no eval or similar functions are used?
  • Does this PR introduce any functionality or component that requires authorization?
    • How have you ensured it respects the existing AuthN/AuthZ mechanisms?
    • Are you logging failed auth attempts?
  • Are you using or adding any cryptographic features?
    • Do you use a standard proven implementations?
    • Are the used keys controlled by the customer? Where are they stored?
  • Are you introducing any new policies/roles/users?
    • Have you used the least-privilege principle? How?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@petrkalos petrkalos force-pushed the fix/custom_auth_500 branch 2 times, most recently from 692a4e0 to 13dd794 Compare March 26, 2025 14:31
@petrkalos petrkalos force-pushed the fix/custom_auth_500 branch 2 times, most recently from 0fe32c0 to b1a038b Compare March 26, 2025 14:42
@petrkalos petrkalos force-pushed the fix/custom_auth_500 branch from b1a038b to ba3714f Compare March 26, 2025 14:43

@staticmethod
def generate_deny_policy(incoming_resource_str: str):
return AuthServices.generate_policy({'sub': None, EMAIL_CLAIM: None}, 'Deny', incoming_resource_str)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to add USER_ID: None to this dict too? - i.e. {'sub': None, EMAIL_CLAIM: None, USER_ID: None}

Otherwise do we run the risk of getting KeyError when updating context as 'user_id': verified_claims[USER_ID_CLAIM],?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could yes but currently it's working (I tested it) because both email and user_id env variables are equal to email

Copy link
Contributor

@dlpzx dlpzx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. As commented offline there other exceptions that could go wrong but those are things on Cognito that we would want to raise

@petrkalos petrkalos merged commit 0212f6d into main Mar 27, 2025
14 checks passed
@petrkalos petrkalos deleted the fix/custom_auth_500 branch April 4, 2025 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants