Reset the header to ensure it isn't defined by the client. set req.http.X-Roles = ""; # Checks if the permission cookie is present and correctly formatted if (req.http.cookie ~ "roles=([^-;]+)-([^-;]+)-([^-;]+)") { set req.http.cookieValue = regsub(req.http.cookie, ".*roles=([^-;]+)-([^-;]+)-([^-;]+).*", "\1"); set req.http.cookieExpiry = regsub(req.http.cookie, ".*roles=([^-;]+)-([^-;]+)-([^-;]+).*", "\2"); set req.http.cookieSign = regsub(req.http.cookie, ".*roles=([^-;]+)-([^-;]+)-([^-;]+).*", "\3"); # Checks the expiration date contained in the cookie if (std.integer(req.http.cookieExpiry, 0) > std.time2integer(now)) { # Checks the signature of the cookie to ensure it was not modified by the client if ("0x"+req.http.cookieSign == digest.hmac_sha256("<secret>", req.http.cookieValue+"-"+req.http.cookieExpiry)) { set req.http.X-Roles = req.http.cookieValue; } } unset req.http.cookieValue; unset req.http.cookieExpiry; unset req.http.cookieSign; } unset req.http.cookie; VCL Varnish 4 (sans doute améliorable)