Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! |
There was a problem hiding this comment.
Pull request overview
This PR extends Jetpack Sync’s actor metadata to include MCP client details from a request header, so Sync events can be attributed to MCP-based clients when present.
Changes:
- Parse
HTTP_X_WPCOM_MCP(base64 JSON) and addmcp_client_name,mcp_client_version, andis_mcp_agentto the actor payload. - Add a Sync package changelog entry describing the new actor metadata.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
projects/packages/sync/src/class-listener.php |
Adds MCP header decoding and populates MCP-related fields on the Sync actor. |
projects/packages/sync/changelog/update-mcp-actor |
Adds a changelog entry for the MCP actor metadata change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Code Coverage SummaryCoverage changed in 1 file.
Full summary · PHP report · JS report Coverage check overridden by
I don't care about code coverage for this PR
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $raw_mcp_header = ''; | ||
| if ( isset( $_SERVER['HTTP_X_WPCOM_MCP'] ) && is_string( $_SERVER['HTTP_X_WPCOM_MCP'] ) ) { | ||
| $raw_mcp_header = trim( wp_unslash( $_SERVER['HTTP_X_WPCOM_MCP'] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitization happens below. | ||
| } | ||
|
|
||
| if ( ! empty( $raw_mcp_header ) && preg_match( '/^[A-Za-z0-9+\/=]+$/', $raw_mcp_header ) ) { | ||
| // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode -- Decoding MCP header payload. | ||
| $decoded = base64_decode( $raw_mcp_header, true ); | ||
| if ( false !== $decoded ) { | ||
| $mcp_data = json_decode( $decoded, true ); |
There was a problem hiding this comment.
HTTP_X_WPCOM_MCP is fully user-controlled and currently gets preg_match/base64_decode/json_decode applied without any explicit size limit. Even with typical web server header limits, this can still be abused to increase CPU/memory usage during sync-triggering requests. Consider adding a conservative max length check on the raw header (and/or decoded JSON) before attempting regex/decode, and bail out early if it exceeds that limit.
| if ( isset( $mcp_data['mcp_client_name'] ) && is_string( $mcp_data['mcp_client_name'] ) ) { | ||
| $actor['mcp_client_name'] = sanitize_text_field( $mcp_data['mcp_client_name'] ); | ||
| } | ||
| if ( isset( $mcp_data['mcp_client_version'] ) && is_string( $mcp_data['mcp_client_version'] ) ) { | ||
| $actor['mcp_client_version'] = sanitize_text_field( $mcp_data['mcp_client_version'] ); | ||
| } | ||
| if ( ! empty( $actor['mcp_client_name'] ) || ! empty( $actor['mcp_client_version'] ) ) { | ||
| $actor['is_mcp_agent'] = true; | ||
| } |
There was a problem hiding this comment.
sanitize_text_field() removes unsafe characters but doesn’t enforce a maximum length. Since these values are added to every actor payload, a long mcp_client_name/mcp_client_version could bloat sync data and activity logs. Consider truncating these sanitized strings to a reasonable max length before assigning them into $actor.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
ea2712c to
f103263
Compare
Related to https://linear.app/a8c/issue/AI-890/add-user-facing-activity-log-for-mcp-tool-executions
Proposed changes:
X-WPCOM-MCPheader by decoding base64 JSON, sanitizing client name/version, and marking is_mcp_agent when either is present.Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
Changelog