Skip to content
/ django Public

Fixed #27775 -- Respect custom expiry in signed cookies.#7885

Closed
pelme wants to merge 1 commit intodjango:masterfrom
pelme:signed-cookie-expiry
Closed

Fixed #27775 -- Respect custom expiry in signed cookies.#7885
pelme wants to merge 1 commit intodjango:masterfrom
pelme:signed-cookie-expiry

Conversation

@pelme
Copy link
Member

@pelme pelme commented Jan 19, 2017

The custom expiry value _session_expiry is stored in the session
itself. The signed cookie needs to first be loaded, and then the value
needs to be checked for validity.

This PR calls signing.loads() twice which may incur a small performance
penalty. The proper solution would be to refactor the session expiry
as discussed in #19201. However, this fix should not really make that
refactor any harder an may be an acceptable fix in the meantime.

Refs #19200, #19201.

@pelme pelme force-pushed the signed-cookie-expiry branch from eb49825 to 32dfc4f Compare January 19, 2017 10:56
Copy link
Member

@timgraham timgraham left a comment

Choose a reason for hiding this comment

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

Is there a ticket for this? All non-trivial PRs need one, otherwise, they don't appear in the review queue.

Copy link
Member

Choose a reason for hiding this comment

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

Please don't make unrelated whitespace changes.

@pelme pelme force-pushed the signed-cookie-expiry branch from 32dfc4f to 687d15a Compare January 25, 2017 14:11
The custom expiry value `_session_expiry` is stored in the session
itself. The signed cookie needs to first be loaded, and then the value
needs to be checked for validity.

This PR calls `signing.loads()` twice which may incur a small performance
penalty. The proper solution would be to refactor the session expiry
as discussed in django#19201. However, this fix should not really make that
refactor any harder an may be an acceptable fix in the meantime.

Refs django#19200, django#19201.
@pelme pelme force-pushed the signed-cookie-expiry branch from 687d15a to b2fa2c7 Compare January 25, 2017 14:13
@pelme pelme changed the title Make signed_cookies session respect custom session expiry. Fixed #27775 -- Respect custom expiry in signed cookies. Jan 25, 2017
@pelme
Copy link
Member Author

pelme commented Jan 25, 2017

@timgraham now there is a proper ticket for this and I've described the motivation for this patched in the ticket:

https://code.djangoproject.com/ticket/27775

max_age = max_age - timezone.now()

# Handle None and 0
if not max_age:
Copy link
Member

Choose a reason for hiding this comment

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

Test coverage seems lacking. For example, commenting this if-block out doesn't result in any failures. Could you add some tests as needed for all the changes?

@virtuallight
Copy link

@pelme I could add some tests to it if you like?

@timgraham
Copy link
Member

@virtuallight, feel free to add tests and send a new PR. Closing this one due to inactivity.

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.

3 participants