-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[SECUR-104] fix: Arbitrary Modification of API Token Rate Limits #8612
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
[SECUR-104] fix: Arbitrary Modification of API Token Rate Limits #8612
Conversation
|
Linked to Plane Work Item(s) This comment was auto-generated by Plane |
📝 WalkthroughWalkthroughAPI token serializer now exposes three additional read-only fields (is_active, last_used, user_type). Contract tests updated to validate the detail endpoint and enforce immutability constraints on token properties during PATCH operations. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/api/plane/app/serializers/api.py (1)
15-24:⚠️ Potential issue | 🔴 CriticalAdd
allowed_rate_limitandis_servicetoread_only_fields.The serializer is used for PATCH updates (apps/api/plane/app/views/api.py), and
allowed_rate_limitis currently writable. This allows authenticated users to modify their own API token rate limits, keeping the SECUR-104 vector open. Additionally,is_serviceshould also be protected. Add both toread_only_fields:🔒 Proposed fix
read_only_fields = [ "token", "expired_at", "created_at", "updated_at", "workspace", "user", + "allowed_rate_limit", + "is_service", "is_active", "last_used", "user_type", ]
🧹 Nitpick comments (1)
apps/api/plane/tests/contract/app/test_api_token.py (1)
336-385: Add a PATCH immutability test forallowed_rate_limit.Given SECUR-104, this is the most important field to lock down; adding a test here will prevent regressions.
✅ Suggested test
`@pytest.mark.django_db` def test_patch_cannot_modify_user_type(self, session_client, create_user, create_api_token_for_user): """Test that user_type cannot be modified via PATCH""" # Arrange session_client.force_authenticate(user=create_user) url = reverse("api-tokens-details", kwargs={"pk": create_api_token_for_user.pk}) update_data = {"user_type": 1} # Act response = session_client.patch(url, update_data, format="json") # Assert assert response.status_code == status.HTTP_200_OK create_api_token_for_user.refresh_from_db() assert create_api_token_for_user.user_type == 0 + `@pytest.mark.django_db` + def test_patch_cannot_modify_allowed_rate_limit(self, session_client, create_user, create_api_token_for_user): + """Test that allowed_rate_limit cannot be modified via PATCH""" + # Arrange + session_client.force_authenticate(user=create_user) + url = reverse("api-tokens-details", kwargs={"pk": create_api_token_for_user.pk}) + original_rate_limit = create_api_token_for_user.allowed_rate_limit + update_data = {"allowed_rate_limit": "9999/min"} + + # Act + response = session_client.patch(url, update_data, format="json") + + # Assert + assert response.status_code == status.HTTP_200_OK + create_api_token_for_user.refresh_from_db() + assert create_api_token_for_user.allowed_rate_limit == original_rate_limit
Description
Update the patch endpoint for the Personal Access token endpoint with right permissions.
Summary by CodeRabbit
New Features
Bug Fixes