File tree 2 files changed +38
-0
lines changed
2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -913,6 +913,8 @@ export default class Autolinker {
913
913
textOrHtml = textOrHtml . replace ( / < / g, '<' ) . replace ( / > / g, '>' ) ;
914
914
}
915
915
916
+ textOrHtml = this . stripUnsafeCharacters ( textOrHtml ) ;
917
+
916
918
let matches = this . parse ( textOrHtml ) ,
917
919
newHtml : string [ ] = [ ] ,
918
920
lastIndex = 0 ;
@@ -1020,6 +1022,16 @@ export default class Autolinker {
1020
1022
1021
1023
return tagBuilder ;
1022
1024
}
1025
+
1026
+ /**
1027
+ * Strips characters considered as unsafe
1028
+ * SNYK-AUTOLINKER-2438289
1029
+ * @param text
1030
+ * @private
1031
+ */
1032
+ private stripUnsafeCharacters ( text : string ) {
1033
+ return text . replace ( / [ \u202a - \u202e , \u200e - \u200f ] / g, '' ) ;
1034
+ }
1023
1035
}
1024
1036
1025
1037
export interface AutolinkerConfig {
Original file line number Diff line number Diff line change @@ -1265,4 +1265,30 @@ describe('Autolinker Url Matching -', () => {
1265
1265
) ;
1266
1266
} ) ;
1267
1267
} ) ;
1268
+
1269
+ describe ( 'unicode exploits' , ( ) => {
1270
+ it ( 'should strip out character direction override unicodes' , ( ) => {
1271
+ expect ( autolinker . link ( 'foo.combar.com' ) ) . toBe (
1272
+ '<a href="http://foo.combar.com">foo.combar.com</a>'
1273
+ ) ;
1274
+ expect ( autolinker . link ( 'foo.com\u202Ebar.com' ) ) . toBe (
1275
+ '<a href="http://foo.combar.com">foo.combar.com</a>'
1276
+ ) ;
1277
+ expect ( autolinker . link ( 'foo.com\u202abar.com' ) ) . toBe (
1278
+ '<a href="http://foo.combar.com">foo.combar.com</a>'
1279
+ ) ;
1280
+ expect ( autolinker . link ( 'foo.com\u202bbar.com' ) ) . toBe (
1281
+ '<a href="http://foo.combar.com">foo.combar.com</a>'
1282
+ ) ;
1283
+ expect ( autolinker . link ( 'foo.com\u202cbar.com' ) ) . toBe (
1284
+ '<a href="http://foo.combar.com">foo.combar.com</a>'
1285
+ ) ;
1286
+ expect ( autolinker . link ( 'foo.com\u202dbar.com' ) ) . toBe (
1287
+ '<a href="http://foo.combar.com">foo.combar.com</a>'
1288
+ ) ;
1289
+ expect ( autolinker . link ( 'foo.com\u202ebar.com' ) ) . toBe (
1290
+ '<a href="http://foo.combar.com">foo.combar.com</a>'
1291
+ ) ;
1292
+ } ) ;
1293
+ } ) ;
1268
1294
} ) ;
You can’t perform that action at this time.
0 commit comments