Created
April 20, 2017 15:10
-
-
Save rezan/4ad9877812a7c6bbe03bace8b8fc3945 to your computer and use it in GitHub Desktop.
Parse XFF and check it against an ACL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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