generateXssTestCases(); $blocked = 0; $failed = []; foreach ($testCases as $testCase) { $request = $this->createAttackRequest( uri: '/search', method: Method::GET, queryParams: ['q' => $testCase['payload']] ); $decision = $this->wafEngine->analyzeRequest($request); if ($decision->shouldBlock()) { $blocked++; } else { $failed[] = $testCase['description']; } } if (!empty($failed)) { throw new \RuntimeException( "WAF failed to block " . count($failed) . " XSS attacks in query params:\n" . implode("\n", array_slice($failed, 0, 5)) ); } echo "✅ Blocked {$blocked}/" . count($testCases) . " XSS attacks in query params\n"; } /** * Test WAF blocks XSS attacks in POST data */ public function testBlocksXssInPostData(): void { $testCases = $this->generateXssTestCases(); $blocked = 0; $failed = []; foreach ($testCases as $testCase) { $request = $this->createAttackRequest( uri: '/api/comments', method: Method::POST, postData: [ 'comment' => $testCase['payload'], 'author' => 'Test User' ] ); $decision = $this->wafEngine->analyzeRequest($request); if ($decision->shouldBlock()) { $blocked++; } else { $failed[] = $testCase['description']; } } if (!empty($failed)) { throw new \RuntimeException( "WAF failed to block " . count($failed) . " XSS attacks in POST data:\n" . implode("\n", array_slice($failed, 0, 5)) ); } echo "✅ Blocked {$blocked}/" . count($testCases) . " XSS attacks in POST data\n"; } /** * Test WAF blocks event handler-based XSS */ public function testBlocksEventHandlerXss(): void { $eventHandlerAttacks = [ '', '', '', '