Added referrer security
This commit is contained in:
parent
0315e0222a
commit
5da867a2fb
1 changed files with 12 additions and 1 deletions
|
@ -99,6 +99,17 @@ if (href.match(/^\/admin\/?$/)) {
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var baseURL = (req.socket.encrypted ? "https" : "http") + "://" + (req.headers.host ? req.headers.host : req.socket.localAddress);
|
||||||
|
if(req.headers.referer && (req.headers.referer + "/").substring(0,baseURL.length + 1) != (baseURL + "/")) {
|
||||||
|
formatTemplate("index.html", {
|
||||||
|
"url": "",
|
||||||
|
"shorturl": "<b>CSRF detected</b>"
|
||||||
|
}, function(data) {
|
||||||
|
res.writeHead(400, {"Content-Type": "text/html; charset=utf-8"});
|
||||||
|
res.end(data);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
var postdata = "";
|
var postdata = "";
|
||||||
req.on("data", function(data) {postdata += data.toString();});
|
req.on("data", function(data) {postdata += data.toString();});
|
||||||
req.on("end", function() {
|
req.on("end", function() {
|
||||||
|
@ -123,7 +134,7 @@ if (href.match(/^\/admin\/?$/)) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
function finalizeResponse(uri, id) {
|
function finalizeResponse(uri, id) {
|
||||||
var shorturl = (req.socket.encrypted ? "https" : "http") + "://" + (req.headers.host ? req.headers.host : req.socket.localAddress) + "/" + id;
|
var shorturl = baseURL + "/" + id;
|
||||||
formatTemplate("index.html", {
|
formatTemplate("index.html", {
|
||||||
"url": antiXSS(uri),
|
"url": antiXSS(uri),
|
||||||
"shorturl": "<p>Shortened URL: <b><a href=\"" + antiXSS(shorturl) + "\" target=\"_blank\">" + antiXSS(shorturl) + "</a></b>"
|
"shorturl": "<p>Shortened URL: <b><a href=\"" + antiXSS(shorturl) + "\" target=\"_blank\">" + antiXSS(shorturl) + "</a></b>"
|
||||||
|
|
Loading…
Reference in a new issue