fix: remove unncessary guards that require CSP privilege when removing event attributes #15846
+7
−6
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.
In the client code
replay_events
, accessingdom.onload
anddom.onerror
causes CSP violations without unsafe-inline for script-src-attr or script-src. Fortunately the guards are unnecessary becauseElement.removeAttribute
is a no-op when it doesn't exist (MDN), so it's straightforward cleanup that shaves bytes regardless of the CSP behavior.Reproduction - https://github.com/ryanatkn/svelte-reproduction-csp-inline-script in this commit
From what I can tell, this partially addresses a couple of issues but doesn't close them - it only silences the problems when the handlers are not added (they're included for SSR, see here), but when present you still get errors. Specifically the repro in #14014 stops erroring with this fix (as does mine) but the repro in #14270 which looks like a duplicate continues to have one of the two errors, caused by the presence of onload and onerror. (not their detection as this PR addresses)
This may be related to some SvelteKit issues like htps://github.com/sveltejs/kit/issues/11747 but I didn't see any that could be fully closed by it, it doesn't address the root cause.
Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.packages/svelte/src
, add a changeset (npx changeset
).Tests and linting
pnpm test
and lint the project withpnpm lint