Skip to content

Commit cb1ef0a

Browse files
zubeydecivelekzzacharo
authored andcommitted
ckeditor: add source back and sanitize input
1 parent bc1eb29 commit cb1ef0a

File tree

6 files changed

+87
-0
lines changed

6 files changed

+87
-0
lines changed

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,5 @@ proprietary programs. If your program is a subroutine library, you may
338338
consider it more useful to permit linking proprietary applications with the
339339
library. If this is what you want to do, use the GNU Library General
340340
Public License instead of this License.
341+
342+
Includes DOMPurify, licensed under the MPL-2.0.

cds/modules/deposit/static/json/cds_deposit/forms/project.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@
5353
"Replace",
5454
"-",
5555
"RemoveFormat"
56+
],
57+
[
58+
"Source"
5659
]
5760
],
5861
"disableNativeSpellChecker": false,

cds/modules/deposit/static/json/cds_deposit/forms/video.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
"Replace",
5353
"-",
5454
"RemoveFormat"
55+
],
56+
[
57+
"Source"
5558
]
5659
],
5760
"disableNativeSpellChecker": false,

cds/modules/theme/assets/bootstrap3/js/cds_deposit/avc/avc.module.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import "angular-ui-sortable";
2828

2929
// CKEditor
3030
import "ckeditor";
31+
import "../ckeditor-sanitizer";
3132
import "rr-ng-ckeditor/ng-ckeditor";
3233
import "angular-schema-form-ckeditor/bootstrap-ckeditor";
3334

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/**
2+
* CKEditor HTML Sanitizer
3+
* Sanitizes HTML content using DOMPurify to prevent XSS attacks
4+
*/
5+
import DOMPurify from "dompurify";
6+
7+
// Sanitization config - matches backend allowed tags
8+
var sanitizeConfig = {
9+
ALLOWED_TAGS: [
10+
"a",
11+
"abbr",
12+
"acronym",
13+
"b",
14+
"blockquote",
15+
"br",
16+
"code",
17+
"col",
18+
"colgroup",
19+
"div",
20+
"table",
21+
"tbody",
22+
"tfoot",
23+
"thead",
24+
"td",
25+
"th",
26+
"tr",
27+
"em",
28+
"h1",
29+
"h2",
30+
"h3",
31+
"h4",
32+
"h5",
33+
"i",
34+
"li",
35+
"ol",
36+
"p",
37+
"pre",
38+
"s",
39+
"span",
40+
"strike",
41+
"strong",
42+
"sub",
43+
"sup",
44+
"u",
45+
"ul",
46+
],
47+
ALLOWED_ATTR: ["style", "dir", "lang", "color"],
48+
ALLOW_STYLE: true,
49+
ALLOW_DATA_ATTR: false,
50+
};
51+
52+
function sanitizeHtml(html) {
53+
if (!html || typeof html !== "string") {
54+
return html;
55+
}
56+
return DOMPurify.sanitize(html, sanitizeConfig);
57+
}
58+
59+
// Initialize sanitization when CKEditor instances are ready
60+
if (typeof window !== "undefined" && window.CKEDITOR) {
61+
window.CKEDITOR.on("instanceReady", function (ev) {
62+
var editor = ev.editor;
63+
64+
// Store original getData method
65+
var originalGetData = editor.getData;
66+
67+
// Sanitize when content is retrieved (before saving)
68+
editor.getData = function (noEvents) {
69+
var data = originalGetData.call(this, noEvents);
70+
if (data) {
71+
return sanitizeHtml(data);
72+
}
73+
return data;
74+
};
75+
});
76+
}
77+

cds/modules/theme/webpack.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"angular-schema-form-ckeditor": "git+https://github.com/CERNDocumentServer/cds-videos-angular-schema-ckeditor",
9898
"ckeditor": "4.12.1",
9999
"rr-ng-ckeditor": "~0.2.1",
100+
"dompurify": "^2.4.5",
100101
# needed because ci fails on tests otherwise. not imported in any bundle
101102
"semantic-ui-less": "^2.4.1",
102103
"vtt.js": "~0.13.0",

0 commit comments

Comments
 (0)