Require the ActivityPub capability for OAuth access tokens - #3592
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR tightens OAuth C2S access control by requiring the activitypub capability for issuing, validating, and refreshing OAuth access tokens, ensuring tokens cannot be obtained or used by users who are not enabled for ActivityPub.
Changes:
- Enforce an
activitypubcapability check inToken::create(),Token::validate(), andToken::refresh()via a shared helper. - Add PHPUnit coverage for capability-gated token issuance/validation/refresh behavior and bearer-token REST authentication behavior.
- Add a changelog entry documenting the behavioral change for end users.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
includes/oauth/class-token.php |
Adds centralized capability enforcement for token create/validate/refresh. |
tests/phpunit/tests/includes/oauth/class-test-token.php |
Adds tests ensuring token operations reject users lacking the activitypub capability, plus blog-only mode coverage. |
tests/phpunit/tests/includes/oauth/class-test-server.php |
Adds test ensuring bearer-token auth rejects users lacking the activitypub capability. |
.github/changelog/oauth-token-capability-check |
Documents the user-facing behavior change in the release notes. |
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.
Proposed changes:
OAuth access tokens are now tied to the
activitypubcapability.create(),validate(), andrefresh()refuse a user who doesn't have it, so a user who was never enabled for ActivityPub, or had it removed, can't get or keep a connected-app token.I check the capability directly instead of
user_can_activitypub()on purpose: that helper also short-circuits on the site's actor mode, so it would have rejected real, capable users on blog-only and single-user sites, where per-user actors aren't exposed but the capability is still the right signal.refresh()runs the check before it deletes the old token, so a failed refresh never destroys a still-valid grant.Other information:
Testing instructions:
activitypubcapability from a user, then run the OAuth flow for them from a client: token issuance returns403, and an existing token stops validating.Changelog entry
A changelog entry is already committed to the branch (
.github/changelog/oauth-token-capability-check), so the "Skip Changelog" label isn't needed.