Skip to content
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
19 changes: 19 additions & 0 deletions .github/workflows/backend-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,25 @@ jobs:
- name: Run test suite
run: composer run-script --timeout=600 test

varnish-vcl-tests:
name: Varnish VCL tests
runs-on: "ubuntu-26.04"
timeout-minutes: 10

steps:
- uses: actions/checkout@v7

- name: Build varnishtest images
run: |
docker build -t ibexa-varnishtest:7 tests/varnish
docker build -t ibexa-varnishtest:9 -f tests/varnish/Dockerfile-9 tests/varnish

- name: Run varnishtest suite
env:
IMAGE_VARNISH7: ibexa-varnishtest:7
IMAGE_VARNISH9: ibexa-varnishtest:9
run: tests/varnish/run.sh varnish7.vcl varnish9.vcl

integration-tests:
name: "REST integration tests"
uses: ibexa/rest/.github/workflows/integration-tests-callable.yaml@5.0
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/browser-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ jobs:
test-suite: '--mode=standard --profile=httpCache --suite=varnish7'
test-setup-phase-1: '--mode=standard --profile=httpCache --suite=setup'
secrets: inherit
varnish7-trusted-proxy:
name: "Varnish 7 integration tests (trusted proxy)"
uses: ibexa/gh-workflows/.github/workflows/browser-tests.yml@main
with:
project-edition: 'oss'
setup: "doc/docker/base-dev.yml:doc/docker/varnish7.yml:doc/docker/varnish-trusted-proxy.yml:doc/docker/selenium.yml"
test-suite: '--mode=standard --profile=httpCache --suite=varnish-trusted-proxy'
test-setup-phase-1: '--mode=standard --profile=httpCache --suite=setup'
secrets: inherit
varnish6-trusted-proxy:
name: "Varnish 6 integration tests (trusted proxy)"
uses: ibexa/gh-workflows/.github/workflows/browser-tests.yml@main
with:
project-edition: 'oss'
setup: "doc/docker/base-dev.yml:doc/docker/varnish.yml:doc/docker/varnish-trusted-proxy.yml:doc/docker/selenium.yml"
test-suite: '--mode=standard --profile=httpCache --suite=varnish-trusted-proxy'
test-setup-phase-1: '--mode=standard --profile=httpCache --suite=setup'
secrets: inherit
varnish6-translation-aware:
name: "Varnish integration tests (translation-aware)"
uses: ibexa/gh-workflows/.github/workflows/browser-tests.yml@main
Expand Down Expand Up @@ -83,6 +101,15 @@ jobs:
test-suite: '--mode=standard --profile=httpCache --suite=varnish9'
test-setup-phase-1: '--mode=standard --profile=httpCache --suite=setup'
secrets: inherit
varnish9-trusted-proxy:
name: "Varnish 9 integration tests (trusted proxy)"
uses: ibexa/gh-workflows/.github/workflows/browser-tests.yml@main
with:
project-edition: 'oss'
setup: "doc/docker/base-dev.yml:doc/docker/varnish9.yml:doc/docker/varnish-trusted-proxy.yml:doc/docker/selenium.yml"
test-suite: '--mode=standard --profile=httpCache --suite=varnish-trusted-proxy'
test-setup-phase-1: '--mode=standard --profile=httpCache --suite=setup'
secrets: inherit
varnish9-translation-aware:
name: "Varnish 9 integration tests (translation-aware)"
uses: ibexa/gh-workflows/.github/workflows/browser-tests.yml@main
Expand Down
34 changes: 28 additions & 6 deletions behat_suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ httpCache:
paths:
- '%paths.base%/vendor/ibexa/http-cache/features/varnish'
filters:
tags: '@varnish6&&~@translationAware'
tags: '@varnish6&&~@translationAware&&~@trustedProxy'
contexts:
- Ibexa\Behat\API\Context\TestContext
- Ibexa\Behat\API\Context\ContentTypeContext
Expand All @@ -28,11 +28,12 @@ httpCache:
- Ibexa\Behat\Browser\Context\AuthenticationContext
- Behat\MinkExtension\Context\MinkContext
- Ibexa\Behat\Browser\Context\ContentPreviewContext
- Ibexa\HttpCache\Behat\Context\ProxyHeaderContext
varnish6-translation-aware:
paths:
- '%paths.base%/vendor/ibexa/http-cache/features/varnish'
filters:
tags: '@varnish6&&~@translationNotAware'
tags: '@varnish6&&~@translationNotAware&&~@trustedProxy'
contexts:
- Ibexa\Behat\API\Context\TestContext
- Ibexa\Behat\API\Context\ContentTypeContext
Expand All @@ -43,11 +44,12 @@ httpCache:
- Ibexa\Behat\Browser\Context\AuthenticationContext
- Behat\MinkExtension\Context\MinkContext
- Ibexa\Behat\Browser\Context\ContentPreviewContext
- Ibexa\HttpCache\Behat\Context\ProxyHeaderContext
varnish7:
paths:
- '%paths.base%/vendor/ibexa/http-cache/features/varnish'
filters:
tags: '@varnish7&&~@translationAware'
tags: '@varnish7&&~@translationAware&&~@trustedProxy'
contexts:
- Ibexa\Behat\API\Context\TestContext
- Ibexa\Behat\API\Context\ContentTypeContext
Expand All @@ -58,11 +60,28 @@ httpCache:
- Ibexa\Behat\Browser\Context\AuthenticationContext
- Behat\MinkExtension\Context\MinkContext
- Ibexa\Behat\Browser\Context\ContentPreviewContext
- Ibexa\HttpCache\Behat\Context\ProxyHeaderContext
varnish-trusted-proxy:
paths:
- '%paths.base%/vendor/ibexa/http-cache/features/varnish'
filters:
tags: '@trustedProxy'
contexts:
- Ibexa\Behat\API\Context\TestContext
- Ibexa\Behat\API\Context\ContentTypeContext
- Ibexa\Behat\Core\Context\TimeContext
- Ibexa\Behat\Core\Context\ConfigurationContext
- Ibexa\Behat\API\Context\ContentContext
- Ibexa\Behat\Browser\Context\BrowserContext
- Ibexa\Behat\Browser\Context\AuthenticationContext
- Behat\MinkExtension\Context\MinkContext
- Ibexa\Behat\Browser\Context\ContentPreviewContext
- Ibexa\HttpCache\Behat\Context\ProxyHeaderContext
varnish7-translation-aware:
paths:
- '%paths.base%/vendor/ibexa/http-cache/features/varnish'
filters:
tags: '@varnish7&&~@translationNotAware'
tags: '@varnish7&&~@translationNotAware&&~@trustedProxy'
contexts:
- Ibexa\Behat\API\Context\TestContext
- Ibexa\Behat\API\Context\ContentTypeContext
Expand All @@ -73,11 +92,12 @@ httpCache:
- Ibexa\Behat\Browser\Context\AuthenticationContext
- Behat\MinkExtension\Context\MinkContext
- Ibexa\Behat\Browser\Context\ContentPreviewContext
- Ibexa\HttpCache\Behat\Context\ProxyHeaderContext
varnish9:
paths:
- '%paths.base%/vendor/ibexa/http-cache/features/varnish'
filters:
tags: '@varnish9&&~@translationAware'
tags: '@varnish9&&~@translationAware&&~@trustedProxy'
contexts:
- Ibexa\Behat\API\Context\TestContext
- Ibexa\Behat\API\Context\ContentTypeContext
Expand All @@ -88,11 +108,12 @@ httpCache:
- Ibexa\Behat\Browser\Context\AuthenticationContext
- Behat\MinkExtension\Context\MinkContext
- Ibexa\Behat\Browser\Context\ContentPreviewContext
- Ibexa\HttpCache\Behat\Context\ProxyHeaderContext
varnish9-translation-aware:
paths:
- '%paths.base%/vendor/ibexa/http-cache/features/varnish'
filters:
tags: '@varnish9&&~@translationNotAware'
tags: '@varnish9&&~@translationNotAware&&~@trustedProxy'
contexts:
- Ibexa\Behat\API\Context\TestContext
- Ibexa\Behat\API\Context\ContentTypeContext
Expand All @@ -103,6 +124,7 @@ httpCache:
- Ibexa\Behat\Browser\Context\AuthenticationContext
- Behat\MinkExtension\Context\MinkContext
- Ibexa\Behat\Browser\Context\ContentPreviewContext
- Ibexa\HttpCache\Behat\Context\ProxyHeaderContext
setup:
paths:
- '%paths.base%/vendor/ibexa/http-cache/features/setup/setup.feature'
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"require-dev": {
"guzzlehttp/psr7": "^2.7",
"ibexa/behat": "~5.0.x-dev",

@vidarl vidarl Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed one thing when merging up. In 4.6 it is currently this in this repo :
"ibexa/behat": "~4.6.0",

While it seems like other repos on 4.6 also uses -dev, ie https://github.com/ibexa/page-builder/blob/4.6/composer.json#L50 :

    "require-dev": {
(...)
        "ibexa/behat": "~4.6.0@dev",

I should change this in 4.6 then, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's incorrect on 4.6, but unrelated ATM. You can do it whenever you're free.

"ibexa/code-style": "~2.3.1",
"ibexa/doctrine-migrations": "~5.0.x-dev",
"ibexa/doctrine-schema": "~5.0.x-dev",
Expand Down
14 changes: 14 additions & 0 deletions docs/varnish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ For Varnish to work properly with eZ, you'll need to use the provided configurat

* [eZ Platform 2.5LTs optimized Varnish 5.1+ VCL](vcl/varnish5.vcl)

Trusted proxies
---------------
The VCL strips the `X-Forwarded-*` and `Forwarded` request headers from every client that is not
listed in the `trusted_proxies` ACL in [parameters.vcl](vcl/parameters.vcl). The application trusts
those headers as soon as `framework.trusted_proxies` is configured, so leaving them unfiltered lets
a client spoof the scheme, host and IP address it is seen with.

If a TLS terminator, load balancer or CDN runs in front of Varnish, add its IP to that ACL —
otherwise the `X-Forwarded-Proto` it sets is discarded and URLs are generated as `http://`.

_Upgrading: `parameters.vcl` and the VCL above must be updated together. The VCL references the
`trusted_proxies` ACL, so an older `parameters.vcl` without it makes Varnish fail to load the
configuration._

For tuning the VCL further to you needs, see the following relevant examples:
- [FOSHttpCache documentation](https://foshttpcache.readthedocs.io/en/latest/varnish-configuration.html)
- Symfony documentation [4.4](https://symfony.com/doc/4.4/http_cache/varnish.html)
Expand Down
13 changes: 13 additions & 0 deletions docs/varnish/vcl/parameters.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ acl debuggers {
"127.0.0.1";
"192.168.0.0"/16;
}

// ACL for reverse proxies, TLS terminators and CDNs running in front of Varnish
//
// Only requests coming from these are allowed to set the "X-Forwarded-*" and "Forwarded" headers,
// see vcl_recv. Requests from anyone else get them stripped, as the application trusts them once
// framework.trusted_proxies is configured, which would otherwise let a client spoof the scheme,
// host and client IP it is seen with.
//
// Add the IP of your TLS terminator/load balancer/CDN here if one runs in front of Varnish,
// otherwise leave this as is.
acl trusted_proxies {
"127.0.0.1";
}
23 changes: 23 additions & 0 deletions docs/varnish/vcl/varnish5.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ sub vcl_recv {
// Add a Surrogate-Capability header to announce ESI support.
set req.http.Surrogate-Capability = "abc=ESI/1.0";

// Stop clients from injecting reverse proxy headers, as the application trusts them once
// framework.trusted_proxies is configured. See parameters.vcl for the trusted_proxies ACL.
if (client.ip !~ trusted_proxies) {
// Varnish appends client.ip to X-Forwarded-For before vcl_recv is entered, so overwrite
// rather than unset, to keep the real client IP as the only entry.
set req.http.X-Forwarded-For = client.ip;
unset req.http.Forwarded;
unset req.http.X-Forwarded-Host;
unset req.http.X-Forwarded-Prefix;
unset req.http.X-Forwarded-Port;
// To prevent the Ibexa Cloud detection in Ibexa DXP from kicking in:
unset req.http.X-Client-IP;
unset req.http.Client-Cdn;

// Varnish itself only knows the scheme when a TLS terminator hands the connection over
// using the PROXY protocol, in which case server.ip is the address the client connected to.
if (std.port(server.ip) == 443) {
set req.http.X-Forwarded-Proto = "https";
} else {
unset req.http.X-Forwarded-Proto;
}
}

// Ensure that the Symfony Router generates URLs correctly with Varnish
if (req.http.X-Forwarded-Proto == "https" ) {
set req.http.X-Forwarded-Port = "443";
Expand Down
23 changes: 23 additions & 0 deletions docs/varnish/vcl/varnish6.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ sub vcl_recv {
// Add a Surrogate-Capability header to announce ESI support.
set req.http.Surrogate-Capability = "abc=ESI/1.0";

// Stop clients from injecting reverse proxy headers, as the application trusts them once
// framework.trusted_proxies is configured. See parameters.vcl for the trusted_proxies ACL.
if (client.ip !~ trusted_proxies) {
// Varnish appends client.ip to X-Forwarded-For before vcl_recv is entered, so overwrite
// rather than unset, to keep the real client IP as the only entry.
set req.http.X-Forwarded-For = client.ip;
unset req.http.Forwarded;
unset req.http.X-Forwarded-Host;
unset req.http.X-Forwarded-Prefix;
unset req.http.X-Forwarded-Port;
// To prevent the Ibexa Cloud detection in Ibexa DXP from kicking in:
unset req.http.X-Client-IP;
unset req.http.Client-Cdn;

// Varnish itself only knows the scheme when a TLS terminator hands the connection over
// using the PROXY protocol, in which case server.ip is the address the client connected to.
if (std.port(server.ip) == 443) {
set req.http.X-Forwarded-Proto = "https";
} else {
unset req.http.X-Forwarded-Proto;
}
}

// Ensure that the Symfony Router generates URLs correctly with Varnish
if (req.http.X-Forwarded-Proto == "https" ) {
set req.http.X-Forwarded-Port = "443";
Expand Down
23 changes: 23 additions & 0 deletions docs/varnish/vcl/varnish7.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,29 @@ sub vcl_recv {
// Add a Surrogate-Capability header to announce ESI support.
set req.http.Surrogate-Capability = "abc=ESI/1.0";

// Stop clients from injecting reverse proxy headers, as the application trusts them once
// framework.trusted_proxies is configured. See parameters.vcl for the trusted_proxies ACL.
if (client.ip !~ trusted_proxies) {
// Varnish appends client.ip to X-Forwarded-For before vcl_recv is entered, so overwrite
// rather than unset, to keep the real client IP as the only entry.
set req.http.X-Forwarded-For = client.ip;
unset req.http.Forwarded;
unset req.http.X-Forwarded-Host;
unset req.http.X-Forwarded-Prefix;
unset req.http.X-Forwarded-Port;
// To prevent the Ibexa Cloud detection in Ibexa DXP from kicking in:
unset req.http.X-Client-IP;
unset req.http.Client-Cdn;

// Varnish itself only knows the scheme when a TLS terminator hands the connection over
// using the PROXY protocol, in which case server.ip is the address the client connected to.
if (std.port(server.ip) == 443) {
set req.http.X-Forwarded-Proto = "https";
} else {
unset req.http.X-Forwarded-Proto;
}
}

// Ensure that the Symfony Router generates URLs correctly with Varnish
if (req.http.X-Forwarded-Proto == "https" ) {
set req.http.X-Forwarded-Port = "443";
Expand Down
23 changes: 23 additions & 0 deletions docs/varnish/vcl/varnish9.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,29 @@ sub vcl_recv {
// Add a Surrogate-Capability header to announce ESI support.
set req.http.Surrogate-Capability = "abc=ESI/1.0";

// Stop clients from injecting reverse proxy headers, as the application trusts them once
// framework.trusted_proxies is configured. See parameters.vcl for the trusted_proxies ACL.
if (client.ip !~ trusted_proxies) {
// Varnish appends client.ip to X-Forwarded-For before vcl_recv is entered, so overwrite
// rather than unset, to keep the real client IP as the only entry.
set req.http.X-Forwarded-For = client.ip;
unset req.http.Forwarded;
unset req.http.X-Forwarded-Host;
unset req.http.X-Forwarded-Prefix;
unset req.http.X-Forwarded-Port;
// To prevent the Ibexa Cloud detection in Ibexa DXP from kicking in:
unset req.http.X-Client-IP;
unset req.http.Client-Cdn;

// Varnish itself only knows the scheme when a TLS terminator hands the connection over
// using the PROXY protocol, in which case server.ip is the address the client connected to.
if (std.port(server.ip) == 443) {
set req.http.X-Forwarded-Proto = "https";
} else {
unset req.http.X-Forwarded-Proto;
}
}

// Ensure that the Symfony Router generates URLs correctly with Varnish
if (req.http.X-Forwarded-Proto == "https" ) {
set req.http.X-Forwarded-Port = "443";
Expand Down
13 changes: 13 additions & 0 deletions features/setup/setup.feature
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,16 @@ Feature: Set system to desired state before tests
And I add policies to "Anonymous"
| module | function |
| user | login |

@APIUser:admin
Scenario: Set up the system to test filtering of reverse proxy headers
Given I create a "proxyHeadersContentType" content type in "Content" with "proxyHeadersContentType" identifier
| Field Type | Name | Identifier | Required | Searchable | Translatable |
| Text line | Name | name | yes | yes | yes |
And I append configuration to "ibexa.system.default.content_view.full"
"""
proxyHeadersContentType:
template: "@IbexaHttpCache/tests/cache/proxy_headers.html.twig"
match:
Identifier\ContentType: [proxyHeadersContentType]
"""
Loading
Loading