Skip to content

Manually define cookie domain#205

Draft
leohemsted wants to merge 4 commits intomainfrom
config-fixes
Draft

Manually define cookie domain#205
leohemsted wants to merge 4 commits intomainfrom
config-fixes

Conversation

@leohemsted
Copy link
Contributor

@leohemsted leohemsted commented Jan 4, 2024

we can be smart and just derive the cookie domain (which is the most specific available shared subdomain of the api and frontend) by parsing the api host name and frontend host name and working out the subdomain hierarchy there.

This has the advantage of us not needing to thing about domain structure when setting up the configuration - rather we can just pass in the full hostnames of the apps, which lets us not worry about the domains the two apps are running on varying significantly based on running locally vs on paas/on ecs.

This function splits the host name by dot, (so download.documents.service.gov.uk becomes ["uk", "gov", "service", "documents", "download"]) and then loops through both api and frontend at the same time.


🚨⚠️ This will be deployed automatically all the way to production when you click merge ⚠️🚨

For more information, including how to check this deployment on preview or staging first before it goes to production, see our team wiki section on deployment

Leo Hemsted added 3 commits December 28, 2023 13:38
we can be smart and just derive the cookie domain (which is the most
specific available shared subdomain of the api and frontend) by parsing
the api host name and frontend host name and working out the subdomain
hierarchy there.

This has the advantage of us not needing to thing about domain structure
when setting up the configuration - rather we can just pass in the full
hostnames of the apps, which we're more likely to have available rather
than the nebulous concept of a shared domain which varies wildly based
on running locally vs on paas/on ecs.

This function splits the host name by dot, (so
download.documents.service.gov.uk becomes ["uk", "gov", "service",
"documents", "download"]) and then loops through both api and frontend
at the same time.
note that patching os environ is pretty tough because it's read at
import time by config, so just patch the values on the config object
itself
),
# running locally outside of docker is no longer supported? :thinking_face:
pytest.param(
"http://localhost:7001", "http://localhost:7002", None, marks=pytest.mark.xfail(raises=ValueError)
Copy link
Contributor Author

@leohemsted leohemsted Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i suspect that the cookies never worked previously if you ran natively on your laptop (rather than under document-download.localhost a la docker compose), but it only happened at cookie-setting-time - which is only if you have confirm emails set to true.

it's got the same function as the frontend hostname, but is only used on
dev.

note this needs a matching change to notifications-local
leohemsted pushed a commit to alphagov/notifications-local that referenced this pull request Jan 10, 2024
instead of server_name. this is now used on all hosted envs to work out
cookie details - see
alphagov/document-download-frontend#205 for
details.

note: you will need to update your private doc dl frontend file to
reflect the change in var name
diff --git a/document-download-frontend.env.tmpl b/document-download-frontend.env.tmpl
index b6f4412..a959450 100644
--- a/document-download-frontend.env.tmpl
+++ b/document-download-frontend.env.tmpl
@@ -4,7 +4,7 @@ FLASK_DEBUG=1
 WERKZEUG_DEBUG_PIN=off
 NOTIFY_ENVIRONMENT=development

-SERVER_NAME=frontend.document-download.localhost:7001
+DOCUMENT_DOWNLOAD_FRONTEND_HOST_NAME=frontend.document-download.localhost:7001

 API_HOST_NAME=http://notify-api.localhost:6011
 DOCUMENT_DOWNLOAD_API_HOST_NAME=http://api.document-download.localhost:7000
@quis quis marked this pull request as draft September 25, 2025 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant