Skip to content

Commit 1b6ee67

Browse files
MarioTesoroMarioTesoro
andauthored
fix(security): sanitize HTML in toggleEditorMode() to prevent XSS (#587)
* bugfix added sanitization html preview to text. * Added sanitization in oContent --------- Co-authored-by: MarioTesoro <mario@kraken.localdomain>
1 parent beb3574 commit 1b6ee67

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

projects/angular-editor/src/lib/editor/angular-editor.component.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,20 @@ export class AngularEditorComponent implements OnInit, ControlValueAccessor, Aft
353353
oCode.focus();
354354
} else {
355355
if (this.doc.querySelectorAll) {
356+
// if sanitize: true the html element, from preview to text, is sanitized according the sanitizer config.
357+
if(this.config.sanitize !== false){
358+
editableElement.innerText = this.sanitizer.sanitize(SecurityContext.HTML, editableElement.innerText)
359+
}
356360
this.r.setProperty(editableElement, 'innerHTML', editableElement.innerText);
357361
} else {
358362
oContent = this.doc.createRange();
359363
oContent.selectNodeContents(editableElement.firstChild);
360-
this.r.setProperty(editableElement, 'innerHTML', oContent.toString());
364+
let oContentString = oContent.toString()
365+
// if sanitize: true the oContent is sanitized according the sanitizer config.
366+
if(this.config.sanitize !== false){
367+
oContentString = this.sanitizer.sanitize(SecurityContext.HTML, oContentString)
368+
}
369+
this.r.setProperty(editableElement, 'innerHTML', oContentString);
361370
}
362371
this.r.setProperty(editableElement, 'contentEditable', true);
363372
this.modeVisual = true;

0 commit comments

Comments
 (0)