Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate authorizer context response to better mimic API Gateway (resubmit) #1376

Merged
merged 1 commit into from Apr 13, 2022

Conversation

paulhbarker
Copy link
Contributor

Description

When successfully returning a policy from an Authorizer function, if the returned policy contains a context object containing values that are not of type string, number, or boolean, it will cause the endpoint to return 500, with the header: x-amzn-ErrorType: AuthorizerConfigurationException. In addition, string, number, and boolean values returned in the authorizer context are all coerced to string values when supplied to the downstream method implementation lambda.

None of this behavior is currently accounted for in the serverless-offline authorizer handling logic. This change fixes that issue, and makes serverless-offline authorizers behave near exactly like those of ApiGateway.

Motivation and Context

This change helps prevent developers from returning invalid types of authorizer contexts that work in serverless-offline but do not work on AWS. This change also helps developers understand exactly what the event.requestContext.authorizer property will contain in the cloud.

fixes #826

How Has This Been Tested?

I began by experimenting with the authorizer context response in ApiGateway with a pair of lambdas, one authorizer, and one downstream method implementation. I confirmed the string coercion behavior as described in this developer guide. I used the current authorizer integration tests as a starting point and added four context validation tests, ensuring that each type of valid and invalid context mimicked the behavior of ApiGateway authorizers as closely as possible.

Copy link
Owner

@dherault dherault left a comment

Choose a reason for hiding this comment

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

Looks great, clean and everything. Shall I merge?

@paulhbarker
Copy link
Contributor Author

Yessir! Thanks for the review.

@dherault dherault merged commit c97e2a6 into dherault:master Apr 13, 2022
@dherault
Copy link
Owner

Published in v8.7.0

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.

[BUG] Context of the Policy returned by an Authorizer function must be a dictionary of strings
2 participants