fix(csp): allow blob: in script-src and img-src for client-side selfie - #1529
Merged
Conversation
The client-side 'Selfie with an Advocate' pipeline (#1512) fails on the deployed approuter because its CSP forbids blob: URLs: - script-src: onnxruntime-web (the @imgly/background-removal WASM backend) bootstraps by creating a blob: module and dynamically importing it. Without blob: in script-src the import is blocked -> 'no available backend found' -> segmentation fails soft -> 'Couldn't remove the background — using your full photo.' - img-src: Konva/canvas loads the photo via <img src=blob:> and the final preview <img :src=finalUrl> is a blob: URL. Without blob: in img-src both are blocked -> broken final image. worker-src already permits blob:, so this is consistent with existing policy. Paired with the wasm-unsafe-eval already present. Preserves all security-headers smoke-test assertions (ui5.sap.com, trustarc hosts).
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The client-side "Selfie with an Advocate" tool at
/devtoberfest/selfie/(shipped in #1523) works locally but fails on the deployed DEV approuter with two symptoms Tom reported:Root cause (single)
The approuter CSP in
approuter/xs-app.jsonforbidsblob:URLs in two directives the pipeline depends on. It passes locally because the Hugo dev server has no strict CSP; the production approuter does.Live Playwright console on DEV:
script-src: onnxruntime-web (the@imgly/background-removalWASM inference backend) bootstraps by creating ablob:module and dynamically importing it. With noblob:inscript-src:→ segmentation fails soft → "using your full photo" (Symptom 1).
img-src: compositing loads the photo via<img src=blob:>(Konva), and the final preview is<img :src=finalUrl>wherefinalUrlis ablob:URL. With noblob:inimg-src:→ fallback path also renders a
blob:<img>→ broken image (Symptom 2).Fix
Add
blob:toscript-srcandimg-src. One-line change (two tokens):worker-srcalready allowsblob:, so this is consistent with the existing policy, and it pairs with thewasm-unsafe-evalalready present for WASM. The vendored imgly model/WASM assets already serve 200 — this is purely the CSP.Verification
jq);security-headers.test.jsassertions preserved (script-srcstill matchesui5.sap.com+consent.trustarc.com;connect-srcmatchesuser-consent-center.trustarc.com).mbt build(approuter change), from freshorigin/mainin the primary tree.Only one CSP file in the repo carries this header (
app/admin-shell/webapp/xs-app.jsonhas routes only). Shipped bytutorials-approuter(path: ../approuterin.deploy/mta.yaml).