Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

fix: Remove Beamer cookies on consent withdraw #3610

Merged
merged 2 commits into from
Mar 3, 2022

Conversation

usame-algan
Copy link
Member

What it solves

Resolves #3608

How this PR fixes it

When withdrawing consent for Community Support & Updates cookies all _BEAMER cookies are deleted

How to test it

  1. Open the Safe app
  2. Accept all cookies
  3. Observe _BEAMER cookies being added
  4. Open Cookie Preferences
  5. Uncheck Community Support & Updates and save
  6. Reload the page
  7. Observe _BEAMER cookies not existing anymore

@github-actions
Copy link

github-actions bot commented Mar 2, 2022

CLA Assistant Lite All Contributors have signed the CLA.

@github-actions
Copy link

github-actions bot commented Mar 2, 2022

ESLint Summary View Full Report

Annotations are provided inline on the Files Changed tab. You can also see all annotations that were generated on the annotations page.

Type Occurrences Fixable
Errors 0 0
Warnings 0 0
Ignored 0 N/A
  • Result: ✅ success
  • Annotations: 0 total

Report generated by eslint-plus-action

@@ -37,3 +42,9 @@ export const saveCookie = async <T extends Record<string, any>>(
}

export const removeCookie = (key: string, path: string, domain: string): void => Cookies.remove(key, { path, domain })

export const removeCookies = (cookieList: Cookie[]): void => {
// Extracts the main domain, e.g. gnosis-safe.io
Copy link
Member

Choose a reason for hiding this comment

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

Can't you get this from location.hostname?

Copy link
Member Author

@usame-algan usame-algan Mar 2, 2022

Choose a reason for hiding this comment

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

It looks like location.hostname returns the same value as location.host. Where is the difference?

Copy link
Member

Choose a reason for hiding this comment

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

Hostname also returns the port, e.g. localhost:3000, whereas host doesn't. So it's better to use host here.

Comment on lines +7 to +11
{ name: `_BEAMER_LAST_POST_SHOWN_${BEAMER_ID}`, path: '/' },
{ name: `_BEAMER_DATE_${BEAMER_ID}`, path: '/' },
{ name: `_BEAMER_FIRST_VISIT_${BEAMER_ID}`, path: '/' },
{ name: `_BEAMER_USER_ID_${BEAMER_ID}`, path: '/' },
{ name: `_BEAMER_FILTER_BY_URL_${BEAMER_ID}`, path: '/' },
Copy link
Member

Choose a reason for hiding this comment

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

Didn't we establish that the id is generated on Beamer's side? Can't you just recurse through the cookies and remove anything that starts with _BEAMER?

Copy link
Member Author

Choose a reason for hiding this comment

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

The Beamer ID is saved on our side within .env. I like the idea of simply deleting all cookies with the _BEAMER prefix but unfortunately it looks like we can't read cross-site cookies and at least on localhost the cookies are saved with getbeamer.com domain.

Copy link
Member

Choose a reason for hiding this comment

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

Sure, but when @francovenica demoed the cookies earlier, it generated a different id the second time round? document.cookie doesn't return all cookies?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to reproduce it but for me they all have the same product id now and no duplicates. If the cookies are saved with a different domain than the one the user is on, document.cookie will not return them.

Copy link
Member

Choose a reason for hiding this comment

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

Alright. Let's see how it goes in testing.

@github-actions
Copy link

github-actions bot commented Mar 2, 2022

Deployment links

🟠 Rinkeby Mainnet 🟣 Polygon 🟡 BSC Arbitrum 🟢 Gnosis Chain

@github-actions
Copy link

github-actions bot commented Mar 2, 2022

E2E Tests Failed
Check the results here: https://github.com/gnosis/safe-react-e2e-tests/actions/runs/1923100493

Failed tests:

  • ❌ Address book Address book
  • ❌ Safe Apps List Safe Apps List


export const removeCookies = (cookieList: Cookie[]): void => {
// Extracts the main domain, e.g. gnosis-safe.io
const subDomain = location.host.split('.').slice(-2).join('.')
Copy link
Member

Choose a reason for hiding this comment

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

Technically, it's not a subdomain, it's the main domain.

@usame-algan usame-algan merged commit 26484ee into feature-discoverability Mar 3, 2022
@usame-algan usame-algan deleted the fix-remove-beamer-cookies branch March 3, 2022 09:06
@github-actions github-actions bot locked and limited conversation to collaborators Mar 3, 2022
@iamacook iamacook linked an issue Mar 3, 2022 that may be closed by this pull request
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Beamer - Delete cookies when opting out in the preferences settings
3 participants