Skip to content

Commit

Permalink
Add req.http.Client-Cert value to the Varnish hash instead of passi…
Browse files Browse the repository at this point in the history
…ng requests that contain it
  • Loading branch information
namedgraph committed Nov 22, 2024
1 parent 24d7ee9 commit b370428
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions platform/varnish.vcl.template
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ acl local {
"${CLIENT_HOST}";
}

acl remote {
}

sub vcl_recv {
if (req.method == "PURGE") {
if (!client.ip ~ local && !client.ip ~ remote) {
Expand Down Expand Up @@ -52,24 +49,34 @@ sub vcl_recv {
/* We only deal with GET and HEAD by default */
return (pass);
}
if (req.http.Client-Cert) {
/* Authenticated requests are not cacheable */
return (pass);
}

if (req.http.Cookie) {
/* only allow cookies in the admin app (for login etc.) */
if(req.url !~ "^/admin(/.*)?$") {
unset req.http.Cookie;
return (hash);
# explicitly allow only cookies required by LDH server-side
set req.http.Cookie = ";" + req.http.Cookie;
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
set req.http.Cookie = regsuball(req.http.Cookie, ";(LinkedDataHub\.state|LinkedDataHub\.id_token)=", "; \1=");
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");

if (req.http.cookie ~ "^\s*$") {
unset req.http.cookie;
}
/* if other cookies are present, request is not cacheable */
return (pass);
}

return (hash);
}

sub vcl_hash {
hash_data(req.url);
hash_data(req.http.Host);

if (req.http.Client-Cert) {
hash_data(std.digest("sha256", req.http.Client-Cert));
}

return (lookup);
}

sub vcl_backend_response {
/* purge URLs after updates */
if ((beresp.status == 200 || beresp.status == 201 || beresp.status == 204) && bereq.method ~ "POST|PUT|DELETE|PATCH") {
Expand Down

0 comments on commit b370428

Please sign in to comment.