Broken Function-level Access Controls#1521
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens function-level access control for the News API token management endpoints so that only requests coming from a valid session belonging to an administrative user can create/update/delete/read tokens.
Changes:
- Added an
is_alloweddecorator that enforces “valid session + admin user” for token management routes. - Applied the new access control to
POST,PATCH,DELETE, andGET/news_api_tokensendpoints (including convertingDELETE/GETto async handlers). - Added tests covering forbidden access for a public user and for requests without a session (currently for
POST).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| tests/core/test_api_tokens.py | Adds negative-path tests for token creation access control (public user + no session). |
| newsroom/news_api/api_tokens/views.py | Introduces and applies an admin-session guard decorator to the token management endpoints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
petrjasek
approved these changes
Jul 15, 2026
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.
Purpose
Ensures that calls to the api token management endpoints require a legitimate session belonging to an administrative user.
What has changed
Checks have been added to the token management endpoints.
Steps to test
Ensure news API access tokens can be added and removed from companies in the company management/API tab.
Checklist
lodash.getwith optional chaining for modified code segmentsResolves: #SDAN-768