Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ function utf8ToAscii(str) {
.join('');
}

function escapeHtml(str) {
if (typeof str !== 'string') {
return '';
}
return str
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;');
}

function sanitizeErrorHeader(msg) {
if (typeof msg === 'string') {
return utf8ToAscii(msg).replace(/\r?\n|\r/g, '');
Expand Down Expand Up @@ -122,7 +134,7 @@ function failSvg(res, msg, statusCode = 500) {
</style>
<foreignObject width="240" height="80"
requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility">
<p xmlns="http://www.w3.org/1999/xhtml">${msg}</p>
<p xmlns="http://www.w3.org/1999/xhtml">${escapeHtml(msg)}</p>
</foreignObject>
</svg>`);
}
Expand Down Expand Up @@ -353,7 +365,7 @@ app.get('/chart', (req, res) => {
renderChartToPng(req, res, opts);
} else {
logger.error(`Request for unsupported format ${outputFormat}`);
res.status(500).end(`Unsupported format ${outputFormat}`);
res.status(500).end(`Unsupported format ${escapeHtml(outputFormat)}`);
}

telemetry.count('chartCount');
Expand Down