Repository navigation
Fix: Enforce media ownership verification for activity and comment attachments - #2379
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Several paths still permit unauthorized rendering or metadata mutation, and one guard can bypass privacy inheritance.
3 open findings
What changed in this PR
Adds ownership validation to prevent unauthorized rtMedia attachments in activities and comments.
Changes:
- Introduces a reusable media ownership helper.
- Guards attachment rendering and metadata updates.
- Restricts activity linkage SQL by media author.
| File | Description |
|---|---|
RTMediaTemplate.php |
Checks ownership for media comments. |
rtmedia-functions.php |
Adds the ownership helper. |
rtmedia-ajax-actions.php |
Guards AJAX comment processing. |
RTMediaBuddyPressActivity.php |
Protects activity rendering and linkage. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Contributor
|
Unable to PHPCS or SVG scan one or more files due to error running PHPCS/SVG scanner:
The error may be temporary. If the error persists, please contact a human (commit-ID: 6fd5cb7). |
Contributor
Author
|
The flagged reviews by Copilot are correct, they are followups to the fixes and I have resolved them with the newly pushed commits. |
the-hercules
approved these changes
Oct 12, 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.


Description
Prior to this fix, an authenticated user could submit someone else's media ID inside
rtMedia_attached_fileswhen posting a status update or replying to a comment. This resulted in two security issues:activity_idin the relevant table could be reassigned to the attacker's activity post or comment.This PR introduces an explicit media ownership check across all entry points where
rtMedia_attached_filesis processed, ensuring that only media authored by the posting user can be linked or embedded.Details
app/main/controllers/template/rtmedia-functions.phprtmedia_is_media_owner( $media_id, $user_id = 0 ).RTMediaModeland verifymedia_author === $user_idwas needed across multiple controllers and callbacks. Centralizing it here keeps the codebase DRY, avoids duplicate database query logic and safely handles default user ID fallbacks.app/main/controllers/activity/RTMediaBuddyPressActivity.phpbp_activity_content_before_save(): Addedrtmedia_is_media_owner()check before calling$obj_activity->create_activity_html(). This prevents unauthorized media HTML from being injected into the content before saving.bp_activity_posted_update(): Addedand media_author = %dto the raw batch SQLUPDATEstatement linking media to the newly posted activity ID.bp_activity_comment_posted_update(): Checked ownership usingrtmedia_is_media_owner( ..., $user_id )before building the comment media HTML and updating comments.app/main/controllers/template/rtmedia-ajax-actions.phprtmedia_bp_activity_after_save_callback(): Added an early return if! rtmedia_is_media_owner( $rtmedia_attached_files[0] ), this prevents unauthorized updates to the media row'sactivity_idon AJAX replies.rtmedia_bp_activity_comment_content_callback(): Added ownership verification before generating comment media HTML.app/main/controllers/template/RTMediaTemplate.phpsave_single_edit(): Verified media ownership before constructing comment media HTML when commenting on single media pages.