Skip to content

Commit 4155bfe

Browse files
committed
Fix not sanitizing file names rendered in html
1 parent 0c45fc6 commit 4155bfe

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crud-file-server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ exports.handleRequest = function(vpath, path, req, res, readOnly, logHeadRequest
140140
var name = results[f].name;
141141
var normalized = url + '/' + name;
142142
while(normalized[0] == '/') { normalized = normalized.slice(1, normalized.length); }
143-
res.write('\r\n<p><a href="/' + normalized + '">' + name + '</a></p>');
143+
if(normalized.indexOf('"') >= 0) throw new Error('unsupported file name')
144+
name = name.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
145+
res.write('\r\n<p><a href="/' + normalized + '"><span>' + name + '</span></a></p>');
144146
}
145147
res.end('\r\n</body></html>');
146148
}

0 commit comments

Comments
 (0)