-
Notifications
You must be signed in to change notification settings - Fork 81
Signature: Prevent double knock if signing data is missing #1985
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
Conversation
Adds a check in maybe_double_knock to return early if key_id, private_key, or Date header are not set in the response, avoiding processing for unrelated requests.
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.
Pull Request Overview
This PR prevents potential errors when unrelated HTTP requests are processed by the double-knock signature fallback mechanism. The fix adds early return checks to ensure only relevant requests with proper signing data are processed.
- Adds validation in
maybe_double_knock
to skip processing when signing data is missing - Includes unit test to verify the fix prevents errors with unrelated requests
- Refactors parameter name for consistency
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
includes/class-signature.php | Adds missing validation checks and renames parameter for clarity |
tests/includes/class-test-signature.php | Adds unit test to verify unrelated requests don't cause errors |
Comments suppressed due to low confidence (1)
tests/includes/class-test-signature.php:459
- The nested HTTP request in the test filter doesn't clearly demonstrate the issue being tested. Consider simplifying the test to focus on the specific scenario where signing data is missing from the request arguments.
\wp_safe_remote_get( 'https://example.org/wp-json/activitypub/1.0/actors/0/inbox' );
* | ||
* @return array The HTTP response. | ||
*/ | ||
public static function maybe_double_knock( $response, $parsed_args, $url ) { | ||
public static function maybe_double_knock( $response, $args, $url ) { | ||
// Remove this filter to prevent infinite recursion. | ||
\remove_filter( 'http_response', array( self::class, 'maybe_double_knock' ) ); | ||
|
||
$response_code = \wp_remote_retrieve_response_code( $response ); | ||
|
||
// Fall back to Draft Cavage signature for any 4xx responses. | ||
if ( $response_code >= 400 && $response_code < 500 ) { |
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.
The condition lacks validation to ensure the request contains signing data before processing. Add checks for required headers like key_id, private_key, or Date to prevent processing unrelated requests that happen to return 4xx status codes.
Copilot uses AI. Check for mistakes.
…/wordpress-activitypub into update/sig-keys-check
Proposed changes:
maybe_double_knock
to return early if key_id, private_key, or Date header are not set in the response, avoiding processing for unrelated requests.Other information:
Testing instructions:
Changelog entry
Changelog Entry Details
Significance
Type
Message
Fixed potential errors when unrelated requests get caught in double-knocking callback.