Skip to content

Escape special characters in Varnish::banPath() host patterns #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
3.x
===

3.1.1
-----

### Varnish Cache

* Fixed `banPath` to escape array of host names to be a correct regular expression.

3.1.0
-----

Expand Down
2 changes: 1 addition & 1 deletion src/ProxyClient/Varnish.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function banPath(string $path, ?string $contentType = null, array|string|
if (!count($hosts)) {
throw new InvalidArgumentException('Either supply a list of hosts or null, but not an empty array.');
}
$hosts = '^('.implode('|', $hosts).')$';
$hosts = '^('.implode('|', array_map(preg_quote(...), $hosts)).')$';
}

$headers = [
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ProxyClient/VarnishTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function testBanPath(): void
\Mockery::on(
function (RequestInterface $request) {
$this->assertEquals('BAN', $request->getMethod());
$this->assertEquals('^(fos.lo|fos2.lo)$', $request->getHeaderLine('X-Host'));
$this->assertEquals('^(fos\.lo|fos2\.lo)$', $request->getHeaderLine('X-Host'));
$this->assertEquals('/articles/.*', $request->getHeaderLine('X-Url'));
$this->assertEquals('text/html', $request->getHeaderLine('X-Content-Type'));

Expand Down
Loading