Skip to content

Commit f21ea01

Browse files
committed
Commit for handling XSS scenarios by escaping html tag brackets.
1 parent 0298484 commit f21ea01

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/autolinker.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff 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, '&lt;').replace(/\>/gi, '&gt;');
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

0 commit comments

Comments
 (0)