Skip to content

Bug: equal sign in path breaks lambda dynamic URL paths #1736

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

Closed
baraksalomon opened this issue Nov 21, 2022 · 7 comments · Fixed by #1737
Closed

Bug: equal sign in path breaks lambda dynamic URL paths #1736

baraksalomon opened this issue Nov 21, 2022 · 7 comments · Fixed by #1737
Assignees
Labels
bug Something isn't working event_handlers

Comments

@baraksalomon
Copy link

Expected Behaviour

When having an path like: /token/bXl0b2tlbg==
And a decorator like:
@app_rest.post("/token/")
def post_token(token: str):
..

The resolve should find this function and token parameter should be populated with "bXl0b2tlbg=="

Current Behaviour

When having an path like: /token/bXl0b2tlbg==
And a decorator like:
@app_rest.post("/token/")
def post_token(token: str):
..

The resolve returns 404.

Code snippet

from aws_lambda_powertools.event_handler import APIGatewayRestResolver

app = APIGatewayRestResolver()

minimal_event = {
    "path": "/token/bXl0b2tlbg==",
    "httpMethod": "POST"
}


@app.post("/token/<token>")
def post_token(token: str):
    return {"token": token}


def lambda_handler(event, context):
    return app.resolve(event, context)


if __name__ == "__main__":
    print(lambda_handler(minimal_event, None))

Possible Solution

Didn't test it but maybe the equal sign is missing from:
SAFE_URI = "-.~()'!*:@,;" # https://www.ietf.org/rfc/rfc3986.txt

https://github.com/awslabs/aws-lambda-powertools-python/blob/118f3e995f35808cc3e4edbc70c33e6769e2506e/aws_lambda_powertools/event_handler/api_gateway.py#L43

Steps to Reproduce

Run the snipper code.
returns 404 instead of 200

AWS Lambda Powertools for Python version

latest

AWS Lambda function runtime

3.9

Packaging format used

PyPi

Debugging logs

No response

@baraksalomon baraksalomon added bug Something isn't working triage Pending triage from maintainers labels Nov 21, 2022
@boring-cyborg
Copy link

boring-cyborg bot commented Nov 21, 2022

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our AWS Lambda Powertools Discord: Invite link

@heitorlessa heitorlessa self-assigned this Nov 21, 2022
@heitorlessa
Copy link
Contributor

@baraksalomon thank you for flagging it - I've just tested an exact route and works (API GW decodes the =) but fails as a dynamic argument.

Creating a test and a fix shortly.

Thanks!

@heitorlessa
Copy link
Contributor

Done - triple tested with an endpoint deployed with the fix just in case. Waiting CI to complete and will kick off a patch release to unblock you and prevent others from failures.

Endpoint - GET: https://p7bquief72.execute-api.eu-west-1.amazonaws.com/Prod/token/bXl0b2tlbg==

Snippet

from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.utilities.typing import LambdaContext

app = APIGatewayRestResolver()

@app.get("/token/<token>")
def get_token(token: str):
    return {"received": f"{token}"}


def lambda_handler(event: dict, context: LambdaContext) -> dict:
    return app.resolve(event, context)

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Nov 21, 2022
@heitorlessa heitorlessa linked a pull request Nov 21, 2022 that will close this issue
7 tasks
@baraksalomon
Copy link
Author

Wow, that was super fast.
Thanks you!

@heitorlessa
Copy link
Contributor

Fix available as 2.3.1 in PyPi - Compiling Lambda Layer and deploying the next version (15) across all regions.

@github-actions
Copy link
Contributor

This is now released under 2.3.1 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Nov 21, 2022
@heitorlessa
Copy link
Contributor

All complete now (PyPi+Layers+Docs) - let us know if this somehow doesn't fix it for you @baraksalomon.

Thank you for the great bug report one more time ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working event_handlers
Projects
None yet
2 participants