-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Fixed #36874 -- Optimized CSRF token generation a bit. #20566
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello! Thank you for your contribution 💪
As it's your first contribution be sure to check out the patch review checklist.
If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!
If you have any design or process questions then you can ask in the Django forum.
Welcome aboard ⛵️!
���� Coverage Report for Changed FilesNote: Missing lines are warnings only. Some lines may not be covered by SQLite tests as they are database-specific. For more information about code coverage on pull requests, see the contributing documentation. |
jacobtylerwalls
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR 👍
| CSRF_SESSION_KEY = "_csrftoken" | ||
|
|
||
|
|
||
| def _make_xlat(chars: str): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the annotation.
| return xlat | ||
|
|
||
|
|
||
| CSRF_XLAT = _make_xlat(CSRF_ALLOWED_CHARS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's find another name without mentioning XLAT.
|
|
||
|
|
||
| def _make_xlat(chars: str): | ||
| xlat = [0 for _ in range(1 + max((ord(x) for x in chars)))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By populating the table with zeroes, this silences ValueErrors. Can you keep this performance tweak from introducing any behavior changes by ensuring some error is still emitted?
(I acknowledge the responsibility for checking for valid characters is in _check_token_format().)
Trac ticket number
ticket-36874
Branch description
The functions _mask_cipher_secret and _unmask_cipher_secret now use pre-built translation table to get character indices.
AI Assistance Disclosure (REQUIRED)
Checklist
mainbranch.