Skip to content

Commit

Permalink
Cookie handling for GOV.UK Chat
Browse files Browse the repository at this point in the history
  • Loading branch information
samsimpson1 committed Sep 5, 2024
1 parent e0bf949 commit 238988a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions www/www.vcl.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,20 @@ sub vcl_recv {
# - Licensing
# - email-alert-frontend (for subscription management)
# - sign-in (digital identity) callback
if (req.url !~ "^/(apply-for-a-licence|email|sign-in/callback)") {
if (req.url !~ "^/(apply-for-a-licence|email|sign-in/callback|chat/)") {
unset req.http.Cookie;
}

# Strip cookies for requests to /chat/* that lack a session cookie,
# otherwise pass through
if (req.url ~ "^/chat/") {
if (req.http.cookie:_govuk_chat_session) {
return(pass)
} else {
unset req.http.Cookie;
}
}

if (req.url.path ~ "^\/assets(\/.*)?\z") {
set req.backend = F_staticAssetsS3;
set req.http.host = "${s3_static_assets_hostname}";
Expand Down Expand Up @@ -490,10 +500,15 @@ sub vcl_fetch {
}

# Strip cookies from outbound requests. Corresponding rule in vcl_recv{}
if (req.url !~ "^/(apply-for-a-licence|email|sign-in/callback)") {
if (req.url !~ "^/(apply-for-a-licence|email|sign-in/callback|chat/)") {
unset beresp.http.Set-Cookie;
}

# We don't want to cache any /chat/* responses that set a cookie
if (req.url ~ "^/chat/" && resp.http.Set-Cookie) {
return (pass);
}

# Override default.vcl behaviour of return(pass).
if (beresp.http.Set-Cookie) {
return (deliver);
Expand Down

0 comments on commit 238988a

Please sign in to comment.