Skip to content

Commit 2793a07

Browse files
committed
Fix XSS in omaps urls
Signed-off-by: Alexander Borsuk <[email protected]>
1 parent 728f133 commit 2793a07

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/ge0.ts

+23-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ function normalizeZoom(zoom: string): number {
5353
return z;
5454
}
5555

56+
const htmlEntityCode = {
57+
' ': '&nbsp;',
58+
'¢': '&cent;',
59+
'£': '&pound;',
60+
'¥': '&yen;',
61+
'€': '&euro;',
62+
'©': '&copy;',
63+
'®': '&reg;',
64+
'<': '&lt;',
65+
'>': '&gt;',
66+
'"': '&quot;',
67+
'&': '&amp;',
68+
"'": '&apos;',
69+
};
70+
71+
function encodeHTML(str: string) {
72+
return str.replace(/[\u00A0-\u9999<>\&''""]/gm, (i) => htmlEntityCode[i]);
73+
}
74+
5675
// Coordinates and zoom are validated separately.
5776
const CLEAR_COORDINATES_REGEX =
5877
/(?<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
81100
const params = pathname.split('/').filter(Boolean);
82101
const encodedLatLonZoom = params[0];
83102
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);
85107

86108
template = replaceInTemplate(template, {
87109
...llz,

0 commit comments

Comments
 (0)