Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit f72a56e

Browse files
committed
Probably fix XSS issue
1 parent 35c5057 commit f72a56e

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/core/fontmetrics.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@
3939
var NAME = "FontMetrics Library"
4040
var VERSION = "1-2012.0121.1300";
4141

42+
var entityMap = {
43+
'&': '&',
44+
'<': '&lt;',
45+
'>': '&gt;',
46+
'"': '&quot;',
47+
"'": '&#39;',
48+
'/': '&#x2F;',
49+
'`': '&#x60;',
50+
'=': '&#x3D;'
51+
};
52+
53+
function escapeHtml (string) {
54+
return String(string).replace(/[&<>"'`=\/]/g, function (s) {
55+
return entityMap[s];
56+
});
57+
}
58+
4259
// if there is no getComputedStyle, this library won't work.
4360
if(!document.defaultView.getComputedStyle) {
4461
throw("ERROR: 'document.defaultView.getComputedStyle' not found. This library only works in browsers that can report computed CSS values.");
@@ -99,7 +116,7 @@
99116
leadDiv.style.position = "absolute";
100117
leadDiv.style.opacity = 0;
101118
leadDiv.style.font = fontString;
102-
leadDiv.innerHTML = textstring + "<br/>" + textstring;
119+
leadDiv.innerHTML = escapeHTML(textstring) + "<br/>" + escapeHTML(textstring);
103120
document.body.appendChild(leadDiv);
104121

105122
// make some initial guess at the text leading (using the standard TeX ratio)

0 commit comments

Comments
 (0)