Skip to content

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

Merged
merged 5 commits into from
Jul 22, 2025

Conversation

obenland
Copy link
Member

Proposed changes:

  • 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.
  • Adds unit test.

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Not sure there's a good way to manually test this. Unit tests should be enough.

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Fixed potential errors when unrelated requests get caught in double-knocking callback.

obenland added 2 commits July 22, 2025 14:55
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.
@obenland obenland requested a review from pfefferle July 22, 2025 20:16
@obenland obenland self-assigned this Jul 22, 2025
@Copilot Copilot AI review requested due to automatic review settings July 22, 2025 20:16
Copy link

@Copilot Copilot AI left a 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 ) {
Copy link
Preview

Copilot AI Jul 22, 2025

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.

@obenland obenland merged commit d0a5bf5 into trunk Jul 22, 2025
11 checks passed
@obenland obenland deleted the update/sig-keys-check branch July 22, 2025 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants