[Bug]: Failure to set inline styles in Content-Security-Policy hardened environment #6261
Open
1 task done
Labels
Category: Open Source
The issue or pull reuqest is related to the open source packages of Tiptap.
Type: Bug
The issue or pullrequest is related to a bug
Affected Packages
extension-highlight, extension-color
Version(s)
2.11.7
Bug Description
I'm running Tiptap on Content-Security-Policy (CSP) hardened website with blocked inline styles.
I'm experiencing an issue where Highlight extension fails to set color. This is because
color
attribute of highlight extension uses'style'
attribute inrenderHTML
. But in my environment browser will block set of inlinestyle
on DOM element due to CSP policy failure.tiptap/packages/extension-highlight/src/highlight.ts
Lines 78 to 91 in 6ceff32
Error
Stack trace points to the following line in ProseMirror https://github.com/ProseMirror/prosemirror-model/blob/1898c7db4bacf8475939403473389b5cf3f5df8d/src/to_dom.ts#L218.
Browser Used
Edge
Code Example URL
No response
Sorry no URL for the repro as there's no sandbox to easily emulate CSP environment. I can try setup something if this is really needed.
Expected Behavior
Highlight extension should work in CSP hardened environment without
unsafe-inline
styles. Inline styles should be set viaelement.style[property] = value
.Additional Context (Optional)
When CSP is enabled and inline styles are blocked browsers will also prevent from setting inline styles using JS via
setAttribute
ifname
is"style"
.I'm not sure how to approach this problem. The error happens in
renderSpec
function on ProseMirror's side.Ideally renderHTML should look like
But this syntax isn't supported by ProseMirror.
Dependency Updates
The text was updated successfully, but these errors were encountered: