Skip to content
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

Fixed #24915 - Added stricter session key validation #4807

Closed
wants to merge 2 commits into from
Closed

Fixed #24915 - Added stricter session key validation #4807

wants to merge 2 commits into from

Conversation

david-bannon
Copy link
Contributor

Changed _session_key attribute to a property and implemented basic
validation in the setter. The session key must be 'truthy' and
at least 8 characters long. Otherwise, the value is set to None.

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

@@ -198,6 +198,20 @@ def test_invalid_key(self):
# session key; make sure that entry is manually deleted
session.delete('1')

def test_session_key_validation(self):
Copy link
Member

Choose a reason for hiding this comment

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

This should be three tests, not one.

@carljm
Copy link
Member

carljm commented Jun 5, 2015

This looks good to me. At first, the double layer of properties seemed like overkill, but on second thought it seems OK to be cautious by maintaining the session_key property as read-only, and avoiding changing the initialization routine, to avoid any issues with third-party session backends.

@david-bannon
Copy link
Contributor Author

@carljm I have split the validation test into three tests as suggested.

The doubly layered properties look a bit weird all right but I figured it was the ideal way to implement the additional functionality without changing the internal API (ostensibly for the reasons you mentioned, realistically because I don't have a good feel for the code base and took the cautious approach :-P).

@carljm
Copy link
Member

carljm commented Jun 6, 2015

Looks good to me! Can you squash the second commit into the first (so there's just one commit with the proper commit message) and force push? Then this looks ready for checkin.

Changed _session_key attribute to a property and implemented basic
validation in the setter. The session key must be 'truthy' and
at least 8 characters long. Otherwise, the value is set to None.

https://code.djangoproject.com/ticket/24915
@david-bannon
Copy link
Contributor Author

@carljm Done

@@ -161,10 +161,25 @@ def _get_or_create_session_key(self):
self._session_key = self._get_new_session_key()
return self._session_key

def _validate_session_key(self, key):
"""Key must be truthy and at least 8 characters long"""
Copy link
Member

Choose a reason for hiding this comment

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

Please include periods in docstrings.

Copy link
Member

Choose a reason for hiding this comment

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

Could you explain why the limit is 8? (or mention it's somewhat arbitrary)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added periods to docstrings.
The 8 character limitation is indeed an arbitrary lower bound to enforce a minimum level of collision security. I went with 8 as it was suggested in the trac ticket.

@david-bannon
Copy link
Contributor Author

New commit in response to @timgraham's comments. Held off on squashing to allow further development if necessary and make diff apparent. Let me know when to re-squash.

@timgraham
Copy link
Member

Looks good. I added a sentence in the release notes and merged in f4416b1, thanks!

@timgraham timgraham closed this Jun 7, 2015
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