Security review fixes: keep pending-capture ids, ship uninstall.php (+verify step), webhook guard, IPv6 /64 + global order throttle, token-safe redirects, honest refund wording, request-id and overlay-token hardening
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
68bd917660
commit
473fe192cd
28 files changed
+747
-34
No files matched your search
@@ -131,7 +131,7 @@ final class PayPalClientTest extends TestCase {
|
||||
|
||||
public function test_verify_webhook_success_and_failure(): void {
|
||||
$headers = array(
|
||||
'paypal_transmission_id' => array( 'T1' ), 'PAYPAL-TRANSMISSION-TIME' => '2026-01-01T00:00:00Z',
|
||||
'paypal_transmission_id' => array( 'T1' ), 'PAYPAL-TRANSMISSION-TIME' => gmdate( 'Y-m-d\TH:i:s\Z' ),
|
||||
'paypal_transmission_sig' => 'SIG', 'paypal_cert_url' => 'https://api.paypal.com/cert', 'paypal_auth_algo' => 'SHA256withRSA',
|
||||
);
|
||||
$raw = '{"id":"WH-1","event_type":"PAYMENT.CAPTURE.COMPLETED"}';
|
||||
@@ -156,10 +156,49 @@ final class PayPalClientTest extends TestCase {
|
||||
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( new TransportException( 'boom' ) );
|
||||
$headers['paypal_cert_url'] = 'x';
|
||||
$headers['paypal_cert_url'] = 'https://api.paypal.com/cert';
|
||||
$this->assertFalse( $c->verifyWebhook( $headers, $raw, 'WHID' ) );
|
||||
}
|
||||
|
||||
/** @return array<string,string> */
|
||||
private function goodWebhookHeaders(): array {
|
||||
return array(
|
||||
'paypal-transmission-id' => 'T1', 'paypal-transmission-time' => gmdate( 'Y-m-d\TH:i:s\Z' ),
|
||||
'paypal-transmission-sig' => 'SIG', 'paypal-cert-url' => 'https://api.paypal.com/v1/notifications/certs/CERT-1', 'paypal-auth-algo' => 'SHA256withRSA',
|
||||
);
|
||||
}
|
||||
|
||||
/** M2: every locally rejectable request must be refused WITHOUT any outbound call (not even the OAuth token). */
|
||||
public function test_verify_webhook_makes_no_outbound_call_for_locally_rejectable_requests(): void {
|
||||
$raw = '{"id":"WH-1","event_type":"PAYMENT.CAPTURE.COMPLETED"}';
|
||||
$cases = array();
|
||||
foreach ( array_keys( $this->goodWebhookHeaders() ) as $missing ) {
|
||||
$h = $this->goodWebhookHeaders();
|
||||
unset( $h[ $missing ] );
|
||||
$cases[ 'missing ' . $missing ] = array( $h, $raw );
|
||||
}
|
||||
foreach ( array( 'http://api.paypal.com/c', 'https://evil.example/c', 'https://paypal.com.evil.example/c', 'https://evilpaypal.com/c', 'https://api.paypal.com@evil.example/c', 'https://user@api.paypal.com/c', 'https://api.paypal.com:8443/c', 'ftp://api.paypal.com/c', 'not a url' ) as $u ) {
|
||||
$cases[ 'cert ' . $u ] = array( array( 'paypal-cert-url' => $u ) + $this->goodWebhookHeaders(), $raw );
|
||||
}
|
||||
foreach ( array( gmdate( 'Y-m-d\TH:i:s\Z', time() - 7200 ), gmdate( 'Y-m-d\TH:i:s\Z', time() + 7200 ), 'yesterday', '', '0' ) as $t ) {
|
||||
$cases[ 'time ' . $t ] = array( array( 'paypal-transmission-time' => $t ) + $this->goodWebhookHeaders(), $raw );
|
||||
}
|
||||
$cases['body too large'] = array( $this->goodWebhookHeaders(), '{"x":"' . str_repeat( 'a', 70000 ) . '"}' );
|
||||
|
||||
foreach ( $cases as $name => [ $headers, $body ] ) {
|
||||
$c = $this->client();
|
||||
$this->assertFalse( $c->verifyWebhook( $headers, $body, 'WHID' ), $name );
|
||||
$this->assertCount( 0, $this->http->calls, "outbound call made for: $name" );
|
||||
}
|
||||
}
|
||||
|
||||
public function test_verify_webhook_still_calls_paypal_for_a_well_formed_request(): void {
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( $this->token(), FakeTransport::json( 200, array( 'verification_status' => 'SUCCESS' ) ) );
|
||||
$this->assertTrue( $c->verifyWebhook( $this->goodWebhookHeaders(), '{"id":"WH-1"}', 'WHID' ) );
|
||||
$this->assertCount( 2, $this->http->calls );
|
||||
}
|
||||
|
||||
public function test_create_webhook_registers_only_completed_event(): void {
|
||||
$c = $this->client();
|
||||
$this->http->queue = array( $this->token(), FakeTransport::json( 201, array( 'id' => 'WH77' ) ) );
|
||||
|
||||
Reference in new issue
Block a user