-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
TrustedTypes-Violation when pasting #1493
Comments
marijnh
added a commit
to ProseMirror/prosemirror-view
that referenced
this issue
Nov 5, 2024
FIX: Don't recreated `TrustedTypePolicy` objects for every paste. Issue ProseMirror/prosemirror#1493
Could you verify that something like attached patch solves this problem? |
Using the patch, I can no longer reproduce the error. Thank you. How do you feel about renaming the created policy to be clearly associated with ProseMirror? |
Yeah, that's probably a good idea. I've switched to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately, event after #1485, prosemirror does not properly support the TrustedTypes mechanism when using a restrictive Content-Security-Policy.
In Chrome-based browsers (e.g. Edge 130.0 on Linux or Windows), pasting links into the editor may produce CSP-violation errors in the console and the link is then not recognized as such. I am not sure why this does not always happen but sometimes requires several attempts to reproduce.
The resulting error:
This happens because we have a strict CSP that defines
trusted-types angular foobar default; require-trusted-types-for 'script';
, i.e. only policies with namesangular
,foobar
anddefault
are allowed to be created and used. It took me some time find the code responsible for the violation, since the policy used by prosemirror is calleddetachedDocument
. Suggestion: Could it be renamed to e.g.prosemirror
orproseMirrorClipboardParsing
so that source of the policy violation can be better identified?Having identified the issue, I added
detachedDocument
to the ``trusted-types` of the CSP header, expecting link pasting to work. However, we then get another error:It turns out that policies may only be created once (unless
allow-duplicates
is configured in the header, which significantly weakens the policy). This is is e.g. mentioned here: https://developer.mozilla.org/en-US/docs/Web/API/TrustedTypePolicyFactory/createPolicy#exceptionsCould you create the policy once and use it thereafter (reading it from a property/variable somewhere)?
The text was updated successfully, but these errors were encountered: