fix(local-apigw): treat authorizer resource ARNs as literals, not regex - #9155
Open
devteamaegis wants to merge 1 commit into
Open
fix(local-apigw): treat authorizer resource ARNs as literals, not regex#9155devteamaegis wants to merge 1 commit into
devteamaegis wants to merge 1 commit into
Conversation
_is_resource_authorized built a regular expression straight from the
Lambda authorizer's Resource ARN, escaping nothing but the wildcards.
Any regex metacharacter in the ARN was therefore interpreted as syntax.
The common case is the HTTP API '$default' stage: '$' is an end-of-string
anchor, so an Allow statement for
'arn:aws:execute-api:...:api/$default/*' never matched the method ARN and
sam local start-api returned 403 for a request that succeeds when
deployed - even when the authorizer echoed back the exact methodArn it
was handed. A '[' or '(' in the path raised re.PatternError outright.
Escape the ARN first, then translate the '*' and '?' wildcards.
Signed-off-by: devteamaegis <devteam.aegis@gmail.com>
devteamaegis
marked this pull request as ready for review
August 3, 2026 16:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's broken
sam local start-apireturns 403 for requests a Lambda authorizer explicitly allows, whenever the resource ARN contains a regex metacharacter. The everyday case is the HTTP API$defaultstage:It fails even when the authorizer echoes back the exact
methodArnit was handed — the most common example in AWS's own docs. Deployed API Gateway allows the same request, so this is a pure local/deployed divergence.A
[or(in the path is worse — the request dies withre.PatternError: unterminated character set.Why it happens
_is_resource_authorizedbuilds a regex directly from the ARN, escaping nothing but the wildcards:So
$becomes an end-of-string anchor,.matches any character, and[/(are unbalanced syntax.The fix
re.escape()the ARN first, then translate the two IAM wildcards:*and?keep working; everything else in the ARN is matched literally. This also stops.from over-matching —.../GET/a.cno longer authorizes.../GET/abc.The test
test_is_resource_authorized_treats_arn_as_literalintests/unit/local/apigw/test_lambda_authorizer.py— six cases covering$default, an echoed method ARN,[,(, literal., and a stage that should still be denied. Five of six fail ondevelop:black --checkclean on both files.