Skip to content

Instantly share code, notes, and snippets.

@rezan
Created April 20, 2017 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rezan/4ad9877812a7c6bbe03bace8b8fc3945 to your computer and use it in GitHub Desktop.
Save rezan/4ad9877812a7c6bbe03bace8b8fc3945 to your computer and use it in GitHub Desktop.
Parse XFF and check it against an ACL
vcl 4.0;
import std;
backend default
{
.host = "127.0.0.1";
.port = "80";
}
acl security
{
"65.0.0.0"/8;
"80.81.0.0"/16;
"192.168.1.0"/24;
! "192.168.1.23";
}
sub vcl_recv
{
# Grab the first XFF ip, Varnish will append current client.ip
set req.http.X-client-ip = regsub(req.http.X-Forwarded-For, ",.*$", "");
# ACL security check
if (std.ip(req.http.X-client-ip, "0.0.0.0") ~ security) {
std.log("Security ACL passed");
} else {
std.log("Security ACL failed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment