CustomAuthorizer fails when querystring params contain : or /
- Dominant language
- Python
- Stars
- 11.1k
- Forks
- 1k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 2
Description
The _generate_arn function in AuthResponse assumes there all pathParameters are urlencoded and do not contain `:` or `/`
This is the code snippet from /chalice/app.py that contains the code where that is affected:
```
def _generate_arn(self, route, request, method='*'):
incoming_arn = request.method_arn
parts = incoming_arn.rsplit(':', 1)
# "arn:aws:execute-api:us-west-2:123:rest-api-id/dev/GET/needs/auth"
# Then we pull out the rest-api-id and stage, such that:
# base = ['rest-api-id', 'stage']
base = parts[-1].split('/')[:2]
# Now we add in the path components and rejoin everything
# back together to make a full arn.
# We're also assuming all HTTP methods (via '*') for now.
# To support per HTTP method routes the API will need to be updated.
# We also need to strip off the leading ``/`` so it can be
# '/'.join(...)'d properly.
base.extend([method, route[1:]])
last_arn_segment = '/'.join(base)
if route in ['/', '*']:
# We have to special case the '/' case. For whatever
# reason, API gateway adds an extra '/' to the method_arn
# of the auth request, so we need to do the same thing.
# We also have to handle the '*' case which is for wildcards
last_arn_segment += route
final_arn = '%s:%s' % (parts[0], last_arn_segment)
return final_arn
```
The 2 lines:
```
parts = incoming_arn.rsplit(':', 1)
```
and
```
base = parts[-1].split('/')[:2]
```
are where the issue lies. These lines are malformed if the user passes pathParams that contain `:` or `/` and the Chalice app uses a CustomAuthorizer
This can be fixed by modifying the following line:
```
incoming_arn = request.method_arn
```
to become
```
incoming_arn = request.method_arn.split('?')[0]
```
This removes the problematic pathParameters that are not used in this function.
I'll put this in a PR now.
Contributor guide
Research direction
Start in /chalice/app.py at AuthResponse._generate_arn and inspect how request.method_arn is split into ARN components. Reproduce the CustomAuthorizer case with querystring parameters containing ':' or '/', then verify that the generated ARN excludes the query string while preserving the expected route and method structure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100