Skip to content

Commit 7566856

Browse files
committed
[HttpKernel] Ensure HttpCache::getTraceKey() does not throw exception
1 parent b815547 commit 7566856

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace Symfony\Component\HttpKernel\HttpCache;
1919

20+
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
2021
use Symfony\Component\HttpFoundation\Request;
2122
use Symfony\Component\HttpFoundation\Response;
2223
use Symfony\Component\HttpKernel\HttpKernelInterface;
@@ -715,7 +716,11 @@ private function getTraceKey(Request $request): string
715716
$path .= '?'.$qs;
716717
}
717718

718-
return $request->getMethod().' '.$path;
719+
try {
720+
return $request->getMethod().' '.$path;
721+
} catch (SuspiciousOperationException) {
722+
return '_INVALID_ '.$path;
723+
}
719724
}
720725

721726
/**

src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ public function testPassesOnNonGetHeadRequests()
6161
$this->assertFalse($this->response->headers->has('Age'));
6262
}
6363

64+
public function testPassesSuspiciousMethodRequests()
65+
{
66+
$this->setNextResponse(200);
67+
$this->request('POST', '/', ['HTTP_X-HTTP-Method-Override' => '__CONSTRUCT']);
68+
$this->assertHttpKernelIsCalled();
69+
$this->assertResponseOk();
70+
$this->assertTraceNotContains('stale');
71+
$this->assertTraceNotContains('invalid');
72+
$this->assertFalse($this->response->headers->has('Age'));
73+
}
74+
6475
public function testInvalidatesOnPostPutDeleteRequests()
6576
{
6677
foreach (['post', 'put', 'delete'] as $method) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy