Skip to content

Commit

Permalink
Merge pull request silverstripe#9 from silverstripe-security/pulls/1.…
Browse files Browse the repository at this point in the history
…3/xss-hollywood

CVE-2019-14272 Sanitise link text for insert modals
  • Loading branch information
dnsl48 authored Sep 23, 2019
2 parents 2a7b851 + 6ec1004 commit 0742b6c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 1 addition & 1 deletion client/dist/js/TinyMCE_sslink.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions client/src/legacy/TinyMCE_sslink.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import TinyMCEActionRegistrar from 'lib/TinyMCEActionRegistrar';
import ReactDOM from 'react-dom';
import jQuery from 'jquery';
import { setupTinyMceInlineToolbar } from 'components/TinymceInlineToolbar/TinymceInlineToolbar';
import { createHTMLSanitiser } from 'lib/ShortcodeSerialiser';
import i18n from 'i18n';

const plugin = {
Expand Down Expand Up @@ -95,7 +96,7 @@ jQuery.entwine('ss', ($) => {
/* noop */
},

/**
/**
* Default behaviour, recommended to overload this and sanitise where needed
*
* @param data
Expand All @@ -107,8 +108,9 @@ jQuery.entwine('ss', ($) => {
editor.selection.moveToBookmark(this.getBookmark());

const attributes = this.buildAttributes(data);

this.insertLinkInEditor(attributes, data.Text);
const sanitise = createHTMLSanitiser();
const linkText = sanitise(data.Text);
this.insertLinkInEditor(attributes, linkText);
this.close();

return Promise.resolve();
Expand Down
22 changes: 22 additions & 0 deletions client/src/lib/ShortcodeSerialiser.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,26 @@ const ShortcodeSerialiser = {
},
};

const createHTMLSanitiser = () => {
const div = document.createElement('div');
return (str) => {
div.textContent = str;

return div.innerHTML;
};
};

const sanitiseShortCodeProperties = (rawProperties) => {
const sanitise = createHTMLSanitiser();
return Object.entries(rawProperties).reduce((props, [name, value]) => ({
...props,
[name]: sanitise(value)
}), {});
};

export {
sanitiseShortCodeProperties,
createHTMLSanitiser,
};

export default ShortcodeSerialiser;

0 comments on commit 0742b6c

Please sign in to comment.