-
Notifications
You must be signed in to change notification settings - Fork 0
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
Strip cookies for "/chat" #124
Conversation
45cbce4
to
d008c27
Compare
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.
Thanks for this. I think there's a few extra areas (because of course it's splattered around)
We've also got:
govuk-fastly/www/www.vcl.tftpl
Lines 372 to 374 in 18fbbae
if (req.url !~ "^/(apply-for-a-licence|email|sign-in/callback|chat/)") { | |
unset req.http.Cookie; | |
} |
We've also got stripping of cookies in responses:
govuk-fastly/www/www.vcl.tftpl
Lines 518 to 521 in 18fbbae
# We don't want to cache any /chat/* responses that set a cookie | |
if (req.url ~ "^/chat/" && beresp.http.Set-Cookie) { | |
return (pass); | |
} |
As an aside I notice there is a bug with
govuk-fastly/www/www.vcl.tftpl
Lines 378 to 380 in 18fbbae
if (req.url ~ "^/chat/") { | |
error 503 "Service unavailable"; | |
} |
www/www.vcl.tftpl
Outdated
# otherwise pass through | ||
if (req.url ~ "^/chat/") { | ||
if (req.url.path ~ "^/chat(/.*)?$") { |
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.
Nice one, did you get a chance to verify this? Though it does look good to me 👍
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.
I tested it in the Fastly Fiddle in the PR description against a few URLs:
- /chat
- /chat/admin
- /chat/
- /chat-with-me
- /chat?foo=bar
- /chatttt
And everything seemed good. I'll deploy it to integration though just to make sure. (I assume it's the same process to deploy this to integration as it is for the chat app?)
We currently strip cookies for requests which lack a relevant session cookie for any URLs starting "/chat/" (note the trailing slash). We want to extend the same functionality to the "/chat" URL as well. It's pretty important that we match _only_ "/chat" (and not, for example, "/chat-with-someone").
The /chat page now relies on cookies to determine its content, so we don't want to cache that URL. This changes the conditional to look at `req.url.path` instead of `req.url` as we're not interested in matching any query params.
d008c27
to
a5a3cf6
Compare
Thanks Kev. I've updated the bits I missed. |
This rule is in place to return a 503 if the `disable_chat` variable is `true` and the request URL is for any GOV.UK Chat page. However due to the trailing slash, it doesn't apply on the chat homepage (www.gov.uk/chat). This updates the logic so we inspect just the path and will kick in if the URL is "/chat" or "/chat/*".
We do some stuff with cookies on requests coming to GOV.UK Chat, but the ordering is currently wrong and so sometimes cookies are being stripped before we get to these rules.
a5a3cf6
to
4204163
Compare
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.
Looks almost there just a bit of a variable misunderstanding to work out
@@ -20,6 +20,7 @@ locals { | |||
ssl_ciphers = "ECDHE-RSA-AES256-GCM-SHA384" | |||
basic_authentication = null | |||
disable_chat = false | |||
chat_path_regex = "^/chat(/.*)?$" # matches /chat and /chat/* |
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.
I imagine we need to do something janky to have this be a string inside quotes - my comments on the next bits will explain the need for that.
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.
Gotcha. I've amended that commit to wrap the variable in quotes in the template file.
www/www.vcl.tftpl
Outdated
@@ -363,37 +363,37 @@ sub vcl_recv { | |||
|
|||
${indent(2, ab_tests_rendered)} | |||
|
|||
# Strip cookies for requests to GOV.UK Chat URLs that lack a session cookie, | |||
# otherwise pass through | |||
if (req.url.path ~ chat_path_regex) { |
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.
We've treated this as a variable within the VCL but it's actually a variable in the terraform template that needs to be printed.
Think of it as we're using the terraftorm template language (tftpl) to create a VCL script file.
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.
Example print:
govuk-fastly/www/www.vcl.tftpl
Line 235 in 4204163
${private_extra_vcl_recv} |
This regex is repeated multiple times so it makes sense to move it to a variable.
4204163
to
61939af
Compare
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.
Great, looks good to me. We should probably brace ourselves for some trial and error if it doesn’t quite work out.
https://trello.com/c/eTyOLA1r/1958
We currently strip cookies for requests which lack a relevant session cookie
for any URLs starting "/chat/" (note the trailing slash).
We want to extend the same functionality to the "/chat" URL as well.
It's pretty important that we match only "/chat" (and not, for
example, "/chat-with-someone").
Here's a Fastly Fiddle that'll pass any relevant URLs and return a 503 for any
URLs we don't want to match: https://fiddle.fastly.dev/fiddle/53922eb7