Skip to content

Commit 81940d1

Browse files
authored
Signature: Check for positive case in host support (#1906)
1 parent 51ce666 commit 81940d1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

includes/class-signature.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public static function sign_request( $args, $url ) {
4343
)
4444
);
4545

46-
if ( '1' === \get_option( 'activitypub_rfc9421_signature' ) && ! self::rfc9421_is_unsupported( $url ) ) {
46+
if ( '1' === \get_option( 'activitypub_rfc9421_signature' ) && self::could_support_rfc9421( $url ) ) {
4747
$signature = new Http_Message_Signature();
4848
\add_filter( 'http_response', array( self::class, 'maybe_double_knock' ), 10, 3 );
4949
} else {
@@ -152,26 +152,26 @@ private static function get_route( $request ) {
152152
}
153153

154154
/**
155-
* Check if RFC-9421 signature is unsupported for a given host.
155+
* Check if RFC-9421 signature could be supported.
156156
*
157157
* @param string $url The URL to check.
158158
*
159-
* @return bool True, if unsupported, false otherwise.
159+
* @return bool True, if RFC-9421 signature could be supported, false otherwise.
160160
*/
161-
private static function rfc9421_is_unsupported( $url ) {
161+
private static function could_support_rfc9421( $url ) {
162162
$host = \wp_parse_url( $url, \PHP_URL_HOST );
163163
$list = \get_option( 'activitypub_rfc9421_unsupported', array() );
164164

165165
if ( isset( $list[ $host ] ) ) {
166166
if ( $list[ $host ] > \time() ) {
167-
return true;
167+
return false;
168168
}
169169

170170
unset( $list[ $host ] );
171171
\update_option( 'activitypub_rfc9421_unsupported', $list );
172172
}
173173

174-
return false;
174+
return true;
175175
}
176176

177177
/**

tests/includes/class-test-signature.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ function () use ( $keys ) {
635635
/**
636636
* Test RFC-9421 signature verification when it is unsupported.
637637
*
638-
* @covers ::rfc9421_is_unsupported
638+
* @covers ::could_support_rfc9421
639639
*/
640640
public function test_rfc9421_is_unsupported() {
641641
\add_option( 'activitypub_rfc9421_unsupported', array( 'sub.www.example.org' => \time() + MINUTE_IN_SECONDS ), '', false );
@@ -689,9 +689,9 @@ public function test_set_rfc9421_unsupported() {
689689
$url = 'https://example.org/wp-json/activitypub/1.0/inbox';
690690

691691
// Test domain is not unsupported.
692-
$rfc9421_is_unsupported = new \ReflectionMethod( Signature::class, 'rfc9421_is_unsupported' );
693-
$rfc9421_is_unsupported->setAccessible( true );
694-
$this->assertFalse( $rfc9421_is_unsupported->invoke( null, $url ) );
692+
$could_support_rfc9421 = new \ReflectionMethod( Signature::class, 'could_support_rfc9421' );
693+
$could_support_rfc9421->setAccessible( true );
694+
$this->assertTrue( $could_support_rfc9421->invoke( null, $url ) );
695695

696696
\add_filter(
697697
'pre_http_request',
@@ -721,7 +721,7 @@ function ( $response, $args, $url ) {
721721
Http::post( $url, '{"type":"Create","actor":"https://example.org/author/admin","object":{"type":"Note","content":"Test content."}}', 1 );
722722

723723
// Domain is set as unsupported.
724-
$this->assertTrue( $rfc9421_is_unsupported->invoke( null, $url ) );
724+
$this->assertFalse( $could_support_rfc9421->invoke( null, $url ) );
725725

726726
// Cleanup.
727727
\delete_option( 'activitypub_rfc9421_signature' );

0 commit comments

Comments
 (0)