Hardening: Remove User.api_v2_token property (returns plaintext API token)#3057
Open
hanu-14 wants to merge 1 commit into
Open
Hardening: Remove User.api_v2_token property (returns plaintext API token)#3057hanu-14 wants to merge 1 commit into
hanu-14 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens credential handling by removing the User.api_v2_token convenience property that could expose a plaintext DRF API token key, reducing the risk of accidental leakage via templates/serialization.
Changes:
- Removed
User.api_v2_tokenproperty (and its DRFTokenimport) from the user model. - Updated the one test that referenced
api_v2_tokento fetch a DRF token key directly.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/users/models.py | Removes the api_v2_token property that returned a plaintext DRF token key. |
| apps/downloads/tests/test_views.py | Updates API auth header construction in tests to no longer rely on the removed model property. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
18
to
20
| from pydotorg.drf import BaseAPITestCase | ||
| from rest_framework.authtoken.models import Token | ||
|
|
| is_staff=True, | ||
| ) | ||
| self.Authorization = f"Token {self.staff_user.api_v2_token}" | ||
| self.Authorization = f"Token {Token.objects.get(user=self.staff_user).key}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3047
Removes the User.api_v2_token property that returns the plaintext DRF Token.key, and updates the one test that referenced it.