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: get the top-level hostname #4935

Merged
merged 8 commits into from
May 31, 2024
Merged

Conversation

gilluminate
Copy link
Contributor

@gilluminate gilluminate commented May 30, 2024

Closes PROD-2126

Description Of Changes

IP addresses and top level hostnames that included multiple TLDs (like co.uk) were not working for setting a Fides Cookie.

This fix update cookie setter to guarantee highest level domain allowed to set cookie. It relies on browser's own methods to determine viable domain.

Code Changes

  • Loop through parts of hostname backwards until cookie gets set.
  • Validate the cookie gets set and stop looping

Steps to Confirm

  • Update /etc/hosts on your local machine to include new line:
    127.0.0.1 privacy.example.co.uk
  • Fire up privacy center on localhost
  • Instead of visiting localhost, visit http://privacy.example.co.uk:3001/fides-js-demo.html
  • In the banner/modal make a selection that will set the cookie
  • Verify that the cookie was set with domain example.co.uk
  • repeat for the IP address http://127.0.0.1:3001/fides-js-demo.html and ensure that works.

(domains like www.fides.com and localhost should continue working with this enhancement in place)

Pre-Merge Checklist

  • All CI Pipelines Succeeded
  • Documentation:
    • documentation complete, PR opened in fidesdocs
    • documentation issue created in fidesdocs
    • if there are any new client scopes created as part of the pull request, remember to update public-facing documentation that references our scope registry
  • Issue Requirements are Met
  • Relevant Follow-Up Issues Created
  • Update CHANGELOG.md

Copy link

vercel bot commented May 30, 2024

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

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
fides-plus-nightly ⬜️ Ignored (Inspect) Visit Preview May 30, 2024 10:49pm

Copy link

cypress bot commented May 30, 2024

Passing run #8019 ↗︎

0 4 0 0 Flakiness 0
⚠️ You've recorded test results over your free plan limit.
Upgrade your plan to view test results.

Details:

Merge d613d17 into 06d373c...
Project: fides Commit: 50223d5965 ℹ️
Status: Passed Duration: 00:33 💡
Started: May 30, 2024 11:00 PM Ended: May 30, 2024 11:01 PM

Review all test suite changes for PR #4935 ↗︎

@gilluminate gilluminate force-pushed the PROD-2126-top-level-cookie-domain branch from b34e7aa to e41d864 Compare May 30, 2024 18:09
Copy link
Contributor

@NevilleS NevilleS left a comment

Choose a reason for hiding this comment

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

nitpicky style/questions in there, but looks reasonable!

clients/fides-js/src/lib/cookie.ts Outdated Show resolved Hide resolved
clients/fides-js/src/lib/cookie.ts Outdated Show resolved Hide resolved
clients/fides-js/src/lib/cookie.ts Outdated Show resolved Hide resolved
clients/fides-js/src/lib/cookie.ts Outdated Show resolved Hide resolved
@gilluminate gilluminate marked this pull request as ready for review May 30, 2024 22:19
Copy link
Contributor

@NevilleS NevilleS left a comment

Choose a reason for hiding this comment

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

All just nits! 👍

clients/fides-js/__tests__/lib/cookie.test.ts Outdated Show resolved Hide resolved
break;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If this exits and fails to save a cookie, what should we do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wondered about throwing an error, but I thought the only real world scenario where this happens is if the browser is blocking 1st party cookies. Should we do something a little more invasive, like a browser alert to let the user know it's not going to work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I propose we solve that separately. fides.js should probably check to see if cookies can be written prior to showing a banner at all. We should be thoughtful about how we want to handle it in that initialization phase.

clients/fides-js/__tests__/lib/cookie.test.ts Show resolved Hide resolved
@gilluminate gilluminate merged commit e9cf179 into main May 31, 2024
13 checks passed
@gilluminate gilluminate deleted the PROD-2126-top-level-cookie-domain branch May 31, 2024 15:07
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.

2 participants