File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -485,6 +485,13 @@ export default class Autolinker {
485485 */
486486 private readonly context : any = undefined ; // default value just to get the above doc comment in the ES5 output and documentation generator
487487
488+ /**
489+ * @cfg {Boolean} [sanitizeHtml=true]
490+ *
491+ * `true` if starting and ending brackets of an html tags should be escaped
492+ * `false` if they should not be.
493+ */
494+ private readonly sanitizeHtml : boolean = true ; // default value just to get the above doc comment in the ES5 output and documentation generator
488495
489496 /**
490497 * @private
@@ -855,6 +862,15 @@ export default class Autolinker {
855862 */
856863 link ( textOrHtml : string ) {
857864 if ( ! textOrHtml ) { return "" ; } // handle `null` and `undefined`
865+
866+ /* We would want to sanitize the start and end characters of a tag
867+ * before processing the string in order to avoid an XSS scenario.
868+ * This behaviour can be changed by toggling the sanitizeHtml option.
869+ */
870+ if ( this . sanitizeHtml )
871+ {
872+ textOrHtml = textOrHtml . replace ( / \< / gi, '<' ) . replace ( / \> / gi, '>' ) ;
873+ }
858874
859875 let matches = this . parse ( textOrHtml ) ,
860876 newHtml : string [ ] = [ ] ,
@@ -975,6 +991,7 @@ export interface AutolinkerConfig {
975991 className ?: string ;
976992 replaceFn ?: ReplaceFn | null ;
977993 context ?: any ;
994+ sanitizeHtml ?: boolean ;
978995 decodePercentEncoding ?: boolean ;
979996}
980997
You can’t perform that action at this time.
0 commit comments