-
Notifications
You must be signed in to change notification settings - Fork 14
Improve varnish config, add support for URIBAN by regex #495
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
Changes from 3 commits
ead552d
11cbd62
b8ef26d
9e62b7f
6859a11
a3e28a4
2294948
cba1254
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -304,8 +304,8 @@ data: | |
| return(pipe); | ||
| } | ||
|
|
||
| # Only allow BAN requests from IP addresses in the 'purge' ACL. | ||
| if (req.method == "BAN" || req.method == "URIBAN") { | ||
| # Only allow BAN requests from IP addressees in the 'internal' ACL. | ||
| if (req.method == "BAN") { | ||
| # Admin port is only exposed to internal network | ||
| if (!client.ip ~ purge) { | ||
| return (synth(403, "Not allowed.")); | ||
|
|
@@ -319,11 +319,30 @@ data: | |
| elseif (req.http.Cache-Tags) { | ||
| ban("obj.http.Cache-Tags ~ " + req.http.Cache-Tags); | ||
| } | ||
| elseif (req.method == "URIBAN") { | ||
| ban("req.http.host == " + req.http.host + " && req.url == " + req.url); | ||
| else { | ||
| # If there are no cache tags headers in a BAN request, | ||
| # it is a bad request, so indicate that to the client. | ||
| return (synth(400, "Cache tags headers not present.")); | ||
| } | ||
| # Throw a synthetic page so the request won't go to the backend. | ||
| return (synth(200, "Ban added.")); | ||
| } | ||
|
|
||
| # Only allow URIBAN requests from IP addressees in the 'internal' ACL. | ||
| if (req.method == "URIBAN") { | ||
| # Admin port is only exposed to internal network | ||
| if (!client.ip ~ purge) { | ||
| return (synth(403, "Not allowed.")); | ||
| } | ||
|
|
||
| # If x-url-invalidate-pattern header is present, | ||
| # use it to match URLs in stored objects. (ban by regex pattern) | ||
| if (req.http.x-url-invalidate-pattern) { | ||
| ban("obj.http.x-url ~ " + req.http.x-url-invalidate-pattern); | ||
|
||
| } | ||
| # Without pattern, ban by matching host and URL exactly. | ||
| else { | ||
| return (synth(403, "Cache tags headers not present.")); | ||
| ban("obj.http.host == " + req.http.host + " && obj.http.x-url == " + req.url); | ||
|
MarttiR marked this conversation as resolved.
|
||
| } | ||
| # Throw a synthetic page so the request won't go to the backend. | ||
| return (synth(200, "Ban added.")); | ||
|
|
@@ -420,8 +439,9 @@ data: | |
| return (pass); | ||
| } | ||
|
|
||
| if (req.url ~ "\.(png|gif|jpg|tif|tiff|ico|webp|swf|css|js|pdf|doc|xls|ppt|zip)(\?.*)?$") { | ||
| // Forcing a lookup with static file requests | ||
| if (req.url ~ "\.(png|gif|jpg|svg|tif|tiff|ico|webp|swf|css|js|pdf|doc|xls|ppt|zip|woff|eot|ttf|bmp|bz2)$") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sort the extensions alphabetically?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 9e62b7f. Also noticed that the Accept-Encoding block tried to skip compressing already compressed files, but as there is significant overlap with the static files handling and the block was after the static files block, it was actually not doing anything for many types of static files. 6859a11 moves it to before the static files block. |
||
| # Static file request do not vary on cookies | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I like this. |
||
| unset req.http.Cookie; | ||
| return (hash); | ||
| } | ||
|
|
||
|
|
@@ -445,12 +465,7 @@ data: | |
| } | ||
|
|
||
| if (req.http.Cookie) { | ||
| if (req.url ~ "\.(png|gif|jpg|svg|tif|tiff|ico|webp|swf|css|js|pdf|doc|xls|ppt|zip|woff|eot|ttf|bmp|bz2)$") { | ||
| # Static file request do not vary on cookies | ||
| unset req.http.Cookie; | ||
| return (hash); | ||
| } | ||
| elseif (req.http.Cookie ~ "(SESS[a-z0-9]+|SSESS[a-z0-9]+)") { | ||
| if (req.http.Cookie ~ "(SESS[a-z0-9]+|SSESS[a-z0-9]+)") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. simplify?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea, done in cba1254. |
||
| # Authenticated users should not be cached | ||
| return (pass); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider "IP not allowed".
Reasoning: suppose someone gets the error, and has no clue of this code here, it could be a guesswork why the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, the message set here is only logged in varnishlog, not transmitted via HTTP.