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

Commit 7efd7d8

Browse files
authored
Merge pull request #478 from irskep/bug-fixes
Fix XSS vuln. Add yarn.lock and 'yarn dev' script.
2 parents 35c5057 + c741b3b commit 7efd7d8

File tree

4 files changed

+5080
-3
lines changed

4 files changed

+5080
-3
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"main": "lib/js",
66
"scripts": {
77
"prepublish": "gulp commonjs",
8-
"test": "echo \"Error: no test specified\" && exit 1"
8+
"test": "echo \"Error: no test specified\" && exit 1",
9+
"dev": "gulp dev",
10+
"gulp": "gulp"
911
},
1012
"repository": {
1113
"type": "git",

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)

src/core/svgRenderer.coffee

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ renderShapeToSVG = (shape, opts={}) ->
1818
else
1919
throw "Can't render shape of type #{shape.className} to SVG"
2020

21+
entityMap = {
22+
'&': '&amp;',
23+
'<': '&lt;',
24+
'>': '&gt;',
25+
'"': '&quot;',
26+
"'": '&#39;',
27+
'/': '&#x2F;',
28+
'`': '&#x60;',
29+
'=': '&#x3D;'
30+
}
31+
32+
escapeHTML = (string) -> String(string).replace /[&<>"'`=\/]/g, (s) -> entityMap[s]
33+
2134

2235
defineSVGRenderer 'Rectangle', (shape) ->
2336
x1 = shape.x
@@ -171,7 +184,7 @@ defineSVGRenderer 'Text', (shape) ->
171184
dy = if i == 0 then 0 else '1.2em'
172185
return "
173186
<tspan x='#{shape.x}' dy='#{dy}' alignment-baseline='text-before-edge'>
174-
#{line}
187+
#{escapeHTML(line)}
175188
</tspan>"
176189
).join('')}
177190
</text>

0 commit comments

Comments
 (0)