Port user permission privilege escalation protections#72
Open
sergei-maertens wants to merge 5 commits into
Open
Port user permission privilege escalation protections#72sergei-maertens wants to merge 5 commits into
sergei-maertens wants to merge 5 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #72 +/- ##
==========================================
+ Coverage 99.27% 99.33% +0.06%
==========================================
Files 34 36 +2
Lines 826 908 +82
Branches 92 98 +6
==========================================
+ Hits 820 902 +82
Misses 4 4
Partials 2 2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
52bc726 to
ca33888
Compare
sergei-maertens
commented
May 13, 2026
Comment on lines
+33
to
+48
| @pytest.fixture | ||
| def unregister_user_model(): | ||
| _original = type(admin.site.get_model_admin(User)) | ||
| admin.site.unregister(User) | ||
| yield | ||
| admin.site.register(User, _original) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def revert_useradmin_patch(unregister_user_model): | ||
| """ | ||
| Restore the default, unpatched user admin. | ||
| """ | ||
| admin.site.register(User, UserAdmin) | ||
| yield | ||
| admin.site.unregister(User) |
Member
Author
There was a problem hiding this comment.
Onions are tasty
Member
|
Good that this is tackled, but I'll let you two do the first review together |
2534eac to
494510d
Compare
* Verify that standard admin pages still work * Verify that users cannot make themselves superuser * Verify that users cannot give themselves or other more permissions than they currently have * Verify that you cannot change passwords of users with more permissions than the current user This also wires up the custom admin that will hold our implementation. It was checked that the smoke tests fail when only the user model is unregistered, and they pass again when the custom admin class is registered.
Ported from default-project, but rewritten to be more explicit and a tad more ✨ magic ✨ for easy integration in existing projects. The code is now heavily annotated with types and hopefully a bit easier to read and maintain.
Ensure that a warning is emitted if we notice the mixin is missing on the user admin. Users can silence this warning if it's deliberate. For projects that have the protections via default-project, this can be a nice signal to replace that code with the equivalent from maykin-common. Additionally, this adds a missing period for the end of the sentence to the existing check.
494510d to
2dcd602
Compare
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 #18
Ported the tests and code, and cleaned them up + added type annotations.