-
Notifications
You must be signed in to change notification settings - Fork 739
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
fix construction of cookie using user supplied input #12808 #13029
base: develop
Are you sure you want to change the base?
fix construction of cookie using user supplied input #12808 #13029
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.
I manually changed my visitor ID in my cookies and navigated and the cookie was refreshed as expected.
Code changes LGTM!
Great work, thank you @KumarVivekPathak
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.
One small tweak to streamline the code.
kolibri/core/auth/api.py
Outdated
if not request.COOKIES.get("visitor_id"): | ||
try: | ||
existing_visitor_id = request.COOKIES.get("visitor_id") | ||
if existing_visitor_id: |
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.
One small tweak - no need to add this if
/else
here - if you pass None
to the UUID
constructor it will also throw a TypeError
so we can handle all cases where the uuid is not a valid v4 UUID in the except
block.
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.
yes I got that I'll change it.
Build Artifacts
|
Summary
This PR addresses the code scanning alert in issue #12808 by ensuring that the
visitor_id
cookie value is validated before use.The validation ensures:
visitor_id
cookie is a valid hex UUID by attempting to parse it withUUID(visitor_id, version=4)
.visitor_id
is generated usinguuid4().hex
.visitor_id
is then set in the response.