add header restriction to cache purging

This commit is contained in:
Thomas Lynch
2024-11-12 20:33:04 +11:00
parent ad659aa1c5
commit bd8079743f

View File

@ -1,6 +1,10 @@
vcl 4.1;
import std;
sub vcl_init {
set purge_secret_key = "CHANGEME_YOUR_SECRET_KEY";
}
# backend pointing to HAProxy
backend haproxy {
.path = "/shared-sockets/varnish-to-haproxy-internal.sock";
@ -14,7 +18,7 @@ acl purge_allowed {
sub vcl_recv {
# handle PURGE requests
if (req.method == "PURGE") {
if (req.method == "PURGE" && req.http.X-BasedFlare-Varnish-Key == secret_key) {
if (req.http.X-Forwarded-For) {
set req.http.X-Real-IP = regsub(req.http.X-Forwarded-For, ",.*", "");
} else {