Use pixi.js/unsafe-eval polyfills to remove unsafe-eval CSP requirement#1773
Use pixi.js/unsafe-eval polyfills to remove unsafe-eval CSP requirement#1773
Conversation
Co-authored-by: jenningsanderson <1637425+jenningsanderson@users.noreply.github.com>
…onments Co-authored-by: jenningsanderson <1637425+jenningsanderson@users.noreply.github.com>
Co-authored-by: jenningsanderson <1637425+jenningsanderson@users.noreply.github.com>
brad-richardson
left a comment
There was a problem hiding this comment.
It seems like the package lock change is unnecessary given no package.json change, but otherwise looks fine
There was a problem hiding this comment.
Pull request overview
This PR aims to remove Rapid’s need for script-src 'unsafe-eval' by enabling PixiJS v8’s pixi.js/unsafe-eval polyfills, which avoid new Function() at runtime and should allow running under a strict CSP.
Changes:
- Add a side-effect import of
pixi.js/unsafe-evalbefore importingpixi.jsinGraphicsSystem.js. - Update
package-lock.json(introducing additional platform-specific optional dependency entries).
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
modules/core/GraphicsSystem.js |
Adds the Pixi unsafe-eval polyfill import intended to remove the CSP unsafe-eval requirement. |
package-lock.json |
Lockfile updated with additional optional/platform packages (notably esbuild/resvg variants). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| import 'pixi.js/unsafe-eval'; | ||
| import * as PIXI from 'pixi.js'; |
There was a problem hiding this comment.
pixi.js/unsafe-eval needs to be loaded before Pixi generates any new Function()-based sync functions. In this codebase, several modules import from pixi.js (e.g. modules/core/AbstractSystem.js, modules/Context.js) before GraphicsSystem.js is reached, so this import may not reliably run first. Consider moving the side-effect import to the earliest application entry module (or a dedicated Pixi bootstrap module that all Pixi imports depend on) to guarantee it executes before any pixi.js import/evaluation.
…1776) * Initial plan * Fix arrow function this context in missing_role.js onClick handlers Co-authored-by: jenningsanderson <1637425+jenningsanderson@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jenningsanderson <1637425+jenningsanderson@users.noreply.github.com>
Rapid requires
unsafe-evalin the Content Security Policy because pixi.js v8 usesnew Function()for dynamic code generation (uniform syncing, shader syncing, UBO sync, particle updates). iD does not have this requirement.Change
pixi.js 8.x ships a
pixi.js/unsafe-evalsubmodule that monkey-patches the relevant prototype methods with static polyfill equivalents, eliminating thenew Function()calls entirely.Import it at the top of
GraphicsSystem.jsbefore pixi.js initializes:This installs polyfills for:
GlUniformGroupSystem._generateUniformsSyncGlUboSystem._generateUboSync/GpuUboSystem._generateUboSyncGlShaderSystem._generateShaderSyncParticleBuffer.generateParticleUpdateRapid now works under a strict
script-src 'self'CSP with nounsafe-evalallowance.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.