Skip to content

Desktop: Rich Text Editor: Disallow inline event handlers #12106

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

Open
wants to merge 11 commits into
base: dev
Choose a base branch
from

Conversation

personalizedrefrigerator
Copy link
Collaborator

Summary

This pull request enables the TinyMCE content_security_policy option, selecting a policy that:

  • Disallows inline event handlers (e.g. onclick="...", onmouseenter="...").
  • Disallows loading scripts from remote URLs.
  • Continues to allow inline CSS and importing CSS from remote servers.
  • Continues to allow loading images from http/https/data/blob.

Goal: Make the Rich Text Editor more secure.

Important

This pull request may break certain plugins in the Rich Text Editor. For example, versions of the Freehand Drawing plugin before v3.0.0 don't support the Rich Text Editor with this change.

To allow plugins to continue to run scripts in the Rich Text Editor, this pull request also adds support for loading plugin assets registered by Joplin plugins in the Rich Text Editor (similar to the existing logic for the Markdown viewer). Previously, assets (e.g. CSS) specified by plugins were not loaded in the Rich Text Editor.

What does this break?

Certain plugins rely on inline event handlers in the Rich Text Editor. These include

  • Freehand Drawing plugin (fixed in v3.0.0).
  • Copy Code Blocks.
  • The example Markdown-it plugin (fixed in this pull request).

Testing

I have verified that:

  • An image from the internet can still render (link).
  • It's possible to click a web link.
  • It's possible to click a resource link.
  • A base64 PNG still renders.
  • KaTeX renders.
  • Mermaid markup renders.
  • With the updated Freehand Drawing plugin (v3.0.0), it's possible to double-click on images to edit them.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Plugin asset files were regenerated due to changes to mermaid_render.js.

Comment on lines -101 to -102
// Clicking on export button manually triggers a right click context menu event
const onClickHandler = `
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This onClick handler was converted from an inline event handler to an event handler added by a script.

Comment on lines +402 to +403
const allRules = { ...rules, ...this.extraRendererRules_ };
for (const key in allRules) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change (along with a few other modifications) add support for loading plugin-specified assets in the Rich Text Editor. This allows migrating inline event handlers to JavaScript files that aren't blocked by the content security policy. Plugin-specified assets were previously only supported in the Markdown viewer.


// Disallow certain unused features
'child-src \'none\'', // Should not contain sub-frames
'object-src \'none\'', // Objects can be used for script injection
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant