forked from rohitcoderCdefense/vulnCodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCWE-548.js
25 lines (24 loc) · 846 Bytes
/
CWE-548.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var http = require('http');
var url = require('url');
var fs = require('fs');
var path = require('path');
http.createServer(function (req, res) {
var q = url.parse(req.url, true);
var filename = "." + q.pathname;
var ext = path.extname(filename);
var allowedExtensions = ['.jpg', '.jpeg', '.png', '.gif'];
if (allowedExtensions.indexOf(ext) > -1) {
fs.readFile(filename, function(err, data) {
if (err) {
res.writeHead(404, {'Content-Type': 'text/html'});
return res.end("404 Not Found");
}
res.writeHead(200, {'Content-Type': 'image/jpeg'});
res.write(data);
return res.end();
});
} else {
res.writeHead(403, {'Content-Type': 'text/html'});
return res.end("403 Forbidden");
}
}).listen(8080);