Skip to content
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

fix!: (WIP) Disable Secure cookies by default, enable when using HTTPS #5011

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rolodato
Copy link
Member

@rolodato rolodato commented Jan 17, 2025

This change possibly fixes #4940, though is a breaking change.

Secure cookies are now opt-in instead of opt-out. By default, secure cookies are now automatically enabled if the request is secure. Users can still force secure cookies if needed.

Having secure cookies enabled by default means that Flagsmith must be used on HTTPS or localhost exclusively. Deploying our provided Docker Compose definition or Helm chart and trying to access it over anything except HTTPS or localhost will fail, unless secure cookies are disabled. Specifically this will fail on any origin that is not potentially trustworthy, which is essentially everything except HTTPS, 127.0.0.1, ::1, and localhost.

This is particularly annoying when testing Kubernetes or Docker deployments, where it's often easier to access services using service URLs and not port forwarding to localhost. The behaviour when secure cookies fail is also confusing, where users can log in but are immediately logged out with no visible errors when reloading the page.

I consider these new defaults to be more secure for most users - they allow testing and experimenting over HTTP when it is not a concern, and they provide secure behaviour when using HTTPS in production. With the current situation, users might forget to opt back into secure cookies after needing to disable them for testing over HTTP, and carry a less secure configuration into a production deployment.

There are legitimate use cases for using Flagsmith in production over HTTP such as having a VPN deal with TLS instead of the application, or local networks.

The Helm chart could also be made to force HTTPS depending on values or ingress configuration.

Testing

Running the ghcr.io/flagsmith/flagsmith-private-cloud:pr-5011 image on Kubernetes, we can successfully log in and access the cluster over HTTP using the default settings:

image

Connecting with the same settings over HTTPS sets a secure cookie - the load balancer here is OrbStack using Docker Compose:

image

@rolodato rolodato requested review from a team as code owners January 17, 2025 06:09
@rolodato rolodato requested review from tiagoapolo and matthewelwell and removed request for a team January 17, 2025 06:09
Copy link

vercel bot commented Jan 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2025 6:09am
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2025 6:09am
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Jan 17, 2025 6:09am

@github-actions github-actions bot added front-end Issue related to the React Front End Dashboard api Issue related to the REST API labels Jan 17, 2025
Copy link
Contributor

github-actions bot commented Jan 17, 2025

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-5011 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-5011 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api:pr-5011 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-5011 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-5011 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-frontend:pr-5011 Finished ✅ Results

@rolodato rolodato added the fix label Jan 17, 2025
Copy link
Contributor

github-actions bot commented Jan 17, 2025

Uffizzi Ephemeral Environment deployment-60006

☁️ https://app.uffizzi.com/github.com/Flagsmith/flagsmith/pull/5011

📄 View Application Logs etc.

What is Uffizzi? Learn more!

Copy link

codecov bot commented Jan 17, 2025

Codecov Report

Attention: Patch coverage is 38.46154% with 8 lines in your changes missing coverage. Please review.

Project coverage is 97.37%. Comparing base (2fe4e02) to head (3323a9d).
Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
api/app/views.py 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5011      +/-   ##
==========================================
- Coverage   97.39%   97.37%   -0.02%     
==========================================
  Files        1191     1191              
  Lines       41630    41634       +4     
==========================================
- Hits        40546    40543       -3     
- Misses       1084     1091       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rolodato rolodato marked this pull request as draft January 20, 2025 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API fix front-end Issue related to the React Front End Dashboard
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing authentication token in cookies
1 participant