File tree 1 file changed +23
-1
lines changed
1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,25 @@ function normalizeZoom(zoom: string): number {
53
53
return z ;
54
54
}
55
55
56
+ const htmlEntityCode = {
57
+ ' ' : ' ' ,
58
+ '¢' : '¢' ,
59
+ '£' : '£' ,
60
+ '¥' : '¥' ,
61
+ '€' : '€' ,
62
+ '©' : '©' ,
63
+ '®' : '®' ,
64
+ '<' : '<' ,
65
+ '>' : '>' ,
66
+ '"' : '"' ,
67
+ '&' : '&' ,
68
+ "'" : ''' ,
69
+ } ;
70
+
71
+ function encodeHTML ( str : string ) {
72
+ return str . replace ( / [ \u00A0 - \u9999 < > \& ' ' " " ] / gm, ( i ) => htmlEntityCode [ i ] ) ;
73
+ }
74
+
56
75
// Coordinates and zoom are validated separately.
57
76
const CLEAR_COORDINATES_REGEX =
58
77
/ (?< lat > - ? \d + \. \d + ) [ ^ \d . ] (?< lon > - ? \d + \. \d + ) (?: [ ^ \d . ] (?< zoom > \d { 1 , 2 } ) ) ? (?: [ ^ \d . ] (?< name > .+ ) ) ? / ;
@@ -81,7 +100,10 @@ export async function onGe0Decode(template: string, url: string): Promise<Respon
81
100
const params = pathname . split ( '/' ) . filter ( Boolean ) ;
82
101
const encodedLatLonZoom = params [ 0 ] ;
83
102
const llz = decodeLatLonZoom ( encodedLatLonZoom ) ;
84
- const [ name , title ] = normalizeNameAndTitle ( params . length > 1 ? params [ 1 ] : undefined ) ;
103
+ let [ name , title ] = normalizeNameAndTitle ( params . length > 1 ? params [ 1 ] : undefined ) ;
104
+ // XSS prevention.
105
+ name = encodeHTML ( name ) ;
106
+ title = encodeHTML ( title ) ;
85
107
86
108
template = replaceInTemplate ( template , {
87
109
...llz ,
You can’t perform that action at this time.
0 commit comments