Skip to content

Add signals strategy configuration for customers with restrictive CSPs #1284

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

Merged
merged 16 commits into from
Apr 30, 2025

Conversation

silesky
Copy link
Contributor

@silesky silesky commented Apr 29, 2025

  • Raises the max signal buffer to 100.
  • Add new setting:
const plugin = new SignalsPlugin({ sandboxStrategy: 'global' })

Background

This fixes CSP errors: unsafe-inline and unsafe-eval without requiring customers to add these to their CSP directive. These occur because, ironically, the default safe strategy of injecting js as a string into an iframe-web-worker and evaluating is not allowed because it's dynamic, so this setting essentially removes the sandbox.

The iframe sandbox is mainly needed for "vanilla" function scenarios where people can introduce infinite loops, etc -- not UI-driven auto-instrumentation scenarios, so global is probably going to become the default.

There is a feature called Shadow Realms that is coming to JS, that one day we will be able to use without upsetting CSPs.

TLDR

The following CSP:

<meta http-equiv="Content-Security-Policy" content="script-src 'self' https://*.segment.com https://*.googletagmanager.com blob:">

Produces the following error:
image

Copy link

changeset-bot bot commented Apr 29, 2025

🦋 Changeset detected

Latest commit: 098319b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@segment/analytics-signals Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@silesky silesky changed the title Update signals sandbox to use global scope Add signals strategy: global Apr 29, 2025
@silesky silesky requested a review from danieljackins April 29, 2025 22:08
Copy link

codecov bot commented Apr 29, 2025

Codecov Report

Attention: Patch coverage is 20.51282% with 93 lines in your changes missing coverage. Please review.

Project coverage is 82.66%. Comparing base (f2c2b76) to head (098319b).
Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
...ages/signals/signals/src/core/processor/sandbox.ts 31.66% 41 Missing ⚠️
...kages/signals/signals/src/lib/load-script/index.ts 2.85% 34 Missing ⚠️
...gnals/src/core/middleware/event-processor/index.ts 11.76% 15 Missing ⚠️
...es/signals/signals/src/core/processor/processor.ts 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1284      +/-   ##
==========================================
- Coverage   83.84%   82.66%   -1.18%     
==========================================
  Files         223      224       +1     
  Lines        5906     6001      +95     
  Branches     1346     1359      +13     
==========================================
+ Hits         4952     4961       +9     
- Misses        954     1040      +86     
Flag Coverage Δ
browser 92.16% <ø> (ø)
core 89.86% <ø> (ø)
node 87.93% <ø> (ø)

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@silesky silesky requested a review from wenxi-zeng April 29, 2025 22:08
@silesky silesky changed the title Add signals strategy: global Add signals strategy: global for customers with CSP errors Apr 29, 2025
@silesky silesky requested a review from alanjcharles April 29, 2025 23:18
@silesky silesky changed the title Add signals strategy: global for customers with CSP errors Add signals strategy configuration for customers with unsafe-eval/inline CSP errors Apr 29, 2025
@silesky silesky changed the title Add signals strategy configuration for customers with unsafe-eval/inline CSP errors Add signals strategy configuration for customers with restrictive CSPs Apr 29, 2025
alanjcharles
alanjcharles previously approved these changes Apr 30, 2025
Copy link
Contributor

@alanjcharles alanjcharles left a comment

Choose a reason for hiding this comment

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

lgtm!

@silesky silesky merged commit 6483541 into master Apr 30, 2025
8 checks passed
@silesky silesky deleted the update-signals-sandbox-to-use-global-scope branch April 30, 2025 19:12
@github-actions github-actions bot mentioned this pull request Apr 30, 2025
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