Skip to content

Update text component to fix unsafe-eval error with a strict CSP#5821

Merged
dmarcos merged 5 commits into
aframevr:masterfrom
vincentfretin:csp-unsafe-eval-non-regression-test
May 31, 2026
Merged

Update text component to fix unsafe-eval error with a strict CSP#5821
dmarcos merged 5 commits into
aframevr:masterfrom
vincentfretin:csp-unsafe-eval-non-regression-test

Conversation

@vincentfretin
Copy link
Copy Markdown
Contributor

@vincentfretin vincentfretin commented May 30, 2026

Update three-bmfont-text version to include dmarcos/three-bmfont-text#5 to avoid using "new Function()" that triggers unsafe-eval error with a strict CSP (Content Security Policy), see #5028 for context.
Add a unsafe-eval error non regression test that runs in CI with Chrome and Firefox.

@vincentfretin
Copy link
Copy Markdown
Contributor Author

Test is failing as expected until the other PR is merged and this PR is rebased

SUMMARY:
✔ 1163 tests completed
ℹ 17 tests skipped
✖ 1 test failed

FAILED TESTS:
  text component CSP
    ✖ loading the A-Frame bundle does not require unsafe-eval
      Chrome 148.0.0.0 (Linux x86_64)
    Error: Loading the A-Frame bundle triggered a CSP unsafe-eval violation: script-src eval. The text component dependency three-bmfont-text must not use eval() / new Function().
        at check (build/commons.js:250863:21)

@mrxz
Copy link
Copy Markdown
Contributor

mrxz commented May 30, 2026

Small nitpick: the test explicitly mentions the text component (in its name and failure messages), but the tested condition that there are no CSP violation when loading the A-Frame bundle is generic. Ultimately it doesn't matter where/how an eval/new Function gets pulled in, this test will catch that regression.

Loads the A-Frame bundle inside an iframe enforcing a CSP without
'unsafe-eval' (mirroring examples/test/text/index.html) and asserts the
browser reports no eval / new Function() securitypolicyviolation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vincentfretin vincentfretin force-pushed the csp-unsafe-eval-non-regression-test branch from d31ecf8 to 0a56863 Compare May 31, 2026 07:49
@vincentfretin
Copy link
Copy Markdown
Contributor Author

You're absolutely right.
I moved tests/components/text-csp.test.js to tests/csp/no-unsafe-eval.test.js and the error now says:
Error: Loading the A-Frame bundle triggered a CSP unsafe-eval violation: script-src eval. The bundle (or one of its dependencies) must not use eval() / new Function()

@vincentfretin
Copy link
Copy Markdown
Contributor Author

Locally the test is green, but in CI it's failing.
I reproduce it locally with
TEST_ENV=ci npm run test:chrome

The in-memory commons.js is istanbul-instrumented under TEST_ENV=ci, and istanbul injects a new Function("return this")() (its global-object lookup) into every instrumented src/ module.

I'll write the test in another way.

vincentfretin and others added 2 commits May 31, 2026 10:22
The in-memory karma-webpack bundle is istanbul-instrumented under
TEST_ENV=ci, and the instrumentation itself emits new Function() (its
global-object lookup). That tripped the CSP test in CI even though
A-Frame no longer evals. Load the built dist/aframe-master.js instead,
which CI rebuilds via `npm run dist` before tests; detect success via the
global AFRAME the bundle assigns. Also capture the violation source/sample
for clearer diagnostics.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Firefox enforced the iframe srcdoc CSP with an about:srcdoc base URL, so
the absolute-path bundle <script> did not resolve to the real origin and
was blocked by script-src (a script-src-elem load violation, not an eval).
Load a real served page (tests/csp/csp-host.html) in the iframe instead so
'self' and URL resolution behave the same in Chrome and Firefox, and match
only actual eval/wasm-eval blockedURIs rather than any script-src* entry.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vincentfretin vincentfretin changed the title CSP unsafe-eval non regression test Update text component to fix unsafe-eval error with a strict CSP May 31, 2026
@vincentfretin
Copy link
Copy Markdown
Contributor Author

The test pass on Chrome and Firefox. I updated the PR title and description.

@dmarcos dmarcos merged commit 2cc6830 into aframevr:master May 31, 2026
1 check passed
@dmarcos
Copy link
Copy Markdown
Member

dmarcos commented May 31, 2026

Thank you!

@vincentfretin vincentfretin deleted the csp-unsafe-eval-non-regression-test branch June 1, 2026 07:57
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.

3 participants