-
Notifications
You must be signed in to change notification settings - Fork 381
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
HTTP request and response egress validation #3973
HTTP request and response egress validation #3973
Conversation
bugwash:
My personal vote goes to the latter aspect. I think we need to keep the option for customization, even if malformed responses were rightly considered an internal error. |
f6e9338
to
f0cda9e
Compare
f0cda9e
to
1b7e9d0
Compare
This PR should probably be discussed again in bugwash regarding error page customization brought up by Nils. |
This implements HTTP character set validation run on the `struct http` after vcl_deliver, vcl_synth and vcl_backend_fetch. The idea is to pick up if the VCL program has ended up filling in illegal values that would violate the HTTP protocol. If a problem is found, we will error out with a 503. If the error is caught in vcl_synth, the connection will be closed.
There is no need to validate client response headers that we do not intend to transmit.
1b7e9d0
to
504d274
Compare
Bugwash: merge this with the existing |
From last bugwash:
On a second thought, do we really want to make a task fail as soon as an invalid value is written to a header (or any other (be)req/(be)resp field) ? We might have users using headers as temporary variables in VCL and those might contain invalid data, but this should be fine as long as the invalid headers are used internally and removed before the req/resp leaves varnish. That's why I think having a full final check at the very end of VCL processing is a better approach. |
Random notes from bugwash of my take on this:
|
I strongly disagree with the arguments against validation of what we send. We needlessly prevent iterative modifications where intermediate steps may not be correct. See for example this snippet that was for a long time _the_ way to filter cookies in VCL: if (req.http.Cookie) {
/* Warning: Not a pretty solution */
/* Prefix header containing cookies with ';' */
set req.http.Cookie = ";" + req.http.Cookie;
/* Remove any spaces after ';' in header containing cookies */
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
/* Prefix cookies we want to preserve with one space */
/* 'S{1,2}ESS[a-z0-9]+' is the regular expression matching a Drupal session cookie ({1,2} added for HTTPS support) */
/* 'NO_CACHE' is usually set after a POST request to make sure issuing user see the results of his post */
/* Keep in mind we should add here any cookie that should reach the backend such as splahs avoiding cookies */
set req.http.Cookie = regsuball(req.http.Cookie, ";(S{1,2}ESS[a-z0-9]+|NO_CACHE|OATMEAL|CHOCOLATECHIP)=", "; \1=");
/* Remove from the header any single Cookie not prefixed with a space until next ';' separator */
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
/* Remove any '; ' at the start or the end of the header */
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
if (req.http.Cookie == "") {
/* If there are no remaining cookies, remove the cookie header. */
unset req.http.Cookie;
}
} And while admittedly "not a pretty solution" (and clearly not the most efficient) it is still a construct someone may use to get to a valid point. From what I remember the last consensus on the topic of variables was:
Once we have something in VCL I may consider hardening this check. But right now this is solving a problem, and it is better to start lenient and harden later instead of starting with something prone to breaking existing valid setups to later relax it. Going crescendo would make this change more approachable. If we had terrible logs that would make it nigh impossible to pinpoint when a header turned wrong, I could hear the POLA argument, but we do a more-than-decent job in that department. (dare I say Varnish shines when it comes to logging?) |
@dridi what you ask for exists except for |
During today's BugWashWed, I think that I made up my mind about this:
|
bugwash: close for now, @walid-git will work on a new proposal in the direction of what bugwash agreed |
This implements HTTP character set validation run on the struct http after vcl_deliver, vcl_synth and vcl_backend_fetch. The idea is to pick up if the VCL program has ended up filling in illegal values that would violate the HTTP protocol.
If a problem is found, we will error out with a 503. If the error is caught in vcl_synth, the connection will be closed.
Authored by:
@mbgrydeland
@daghf