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

MPP-3838: restore safer CSP #4854

Merged
merged 3 commits into from
Jul 12, 2024
Merged

MPP-3838: restore safer CSP #4854

merged 3 commits into from
Jul 12, 2024

Conversation

groovecoder
Copy link
Member

Use a new EagerNonceCSPMiddleware to add nonce to the CSP and update the React app to include it in dynamic scripts.

This PR fixes MPP-3838.

How to test:

  1. Open the Relay GA4 Realtime view
  2. Check out this branch locally
  3. In frontend/, npm run watch to build the new front-end files
  4. python manage.py runserver
  5. Visit http://127.0.0.1:8000/ and perform some page views & events
    • Check that your new events show up in the Relay GA4 Realtime view
  • l10n changes have been submitted to the l10n repository, if any.
  • I've added a unit test to test for potential regressions of this bug.
  • I've added or updated relevant docs in the docs/ directory.
  • All UI revisions follow the coding standards, and use Protocol tokens where applicable (see /frontend/src/styles/tokens.scss).
  • Commits in this PR are minimal and have descriptive commit messages.

Copy link
Member

@jwhitlock jwhitlock left a comment

Choose a reason for hiding this comment

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

Thanks, looks good

@jwhitlock jwhitlock self-requested a review July 11, 2024 18:59
Copy link
Member

@jwhitlock jwhitlock left a comment

Choose a reason for hiding this comment

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

The tests run fine on /accounts/profile/, but have errors on /faq/.

A warning "@next/third-parties: GA dataLayer dataLayer does not exist" is raised at GoogleAnalyticsWorkaround.tsx:103:12. This is then followed by an error

Content-Security-Policy: The page’s settings blocked an inline script (script-src-elem) from being executed because it violates the following directive: “script-src 'self' https://www.google-analytics.com/ https://*.googletagmanager.com https://js.stripe.com/”

It doesn't happen when the trailing slash is in the path patterns.

from whitenoise.middleware import WhiteNoiseMiddleware

metrics = markus.get_metrics("fx-private-relay")


CSP_NONCE_COOKIE_URLS = ["/", "/premium", "/faq", "/accounts/profile/"]
Copy link
Member

@jwhitlock jwhitlock Jul 11, 2024

Choose a reason for hiding this comment

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

Add "/phone/", "/premium/waitlist/", "/phone/waitlist/", "/vpn-relay/waitlist/", "/contains-tracker-warning/", "/account/settings/", "/accounts/account_inactive/", "/vpn-relay-welcome/", "/tracker-report/"
Add the trailing slash for /premium/ and /faq/

groovecoder and others added 2 commits July 11, 2024 15:18
Use a new EagerNonceCSPMiddleware to add nonce to the CSP and update the
React app to include it in dynamic scripts.
Use SpectacularSwaggerSplitView to load the script as a <script> tag
instead of an inline script. This means 'unsafe-inline' is not needed
for API docs.
@groovecoder
Copy link
Member Author

Updated to include all url paths returned by:

python manage.py collectstatic
find staticfiles -type f -name 'index.html'

(except the mock urls)

Co-authored-by: John Whitlock <[email protected]>
Copy link
Member

@jwhitlock jwhitlock left a comment

Choose a reason for hiding this comment

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

Thanks @groovecoder!

@groovecoder groovecoder added this pull request to the merge queue Jul 12, 2024
Merged via the queue into main with commit 816d39d Jul 12, 2024
29 checks passed
@groovecoder groovecoder deleted the ga4-csp-mpp-3838 branch July 12, 2024 16: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