Skip to content

Cookie class MaxAge produces invalid attribute, resulting to browser defaulting to session. #4730

Closed

Description

@Connorcee

Expected Behaviour

When using the Cookie class from aws_lambda_powertools.shared.cookies the resulting Set-Cookie header when passed to the Response class will contain a cookie that has the attribute of Max-Age.

Current Behaviour

The Cookie class from aws_lambda_powertools.shared.cookies says it follows the RFC of https://tools.ietf.org/html/rfc6265, however when passing in the max_age argument, the final Set-Cookie string that is produced is MaxAge instead of Max-Age resulting in the browser defaulting to session length for the cookie expiration.

Code snippet

from aws_lambda_powertools.shared.cookies import Cookie
from aws_lambda_powertools.event_handler import Response
cookie = Cookie(name="Test", value="Test", max_age=60)
str(cookie)

Possible Solution

Within the aws_lambda_powertools.shared.cookies.py add a - to the max age section that performs serialisation.

Steps to Reproduce

Running the below code snippet will reproduce the issue.

from aws_lambda_powertools.shared.cookies import Cookie
from aws_lambda_powertools.event_handler import Response
cookie = Cookie(name="Test", value="Test", max_age=60)
str(cookie)
>>> 'Test=Test; MaxAge=60; Secure'

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.12

Packaging format used

PyPi

Debugging logs

No response

Activity

  1. added
    bug
    triage
    on Jul 10, 2024
  2. boring-cyborg commented on Jul 10, 2024

    @boring-cyborg

    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 Powertools for AWS Lambda Discord: Invite link

  3. leandrodamascena commented on Jul 10, 2024

    @leandrodamascena
    Contributor

    Hi @Connorcee! Thank you so much for reporting this bug. We must follow the RFC and MaxAge is actually wrong.
    I sent a PullRequest to resolve this bug and we will release it tomorrow.

  4. removed
    triage
    on Jul 10, 2024
  5. github-actions commented on Jul 11, 2024

    @github-actions
    Contributor

    ⚠️COMMENT VISIBILITY WARNING⚠️

    This issue is now closed. Please be mindful that future comments are hard for our team to see.

    If you need more assistance, please either tag a team member or open a new issue that references this one.

    If you wish to keep having a conversation with other community members under this issue feel free to do so.

  6. added
    pending-release
    on Jul 11, 2024
  7. github-actions commented on Jul 11, 2024

    @github-actions
    Contributor

    This is now released under 2.41.0 version!

  8. removed
    pending-release
    on Jul 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions