mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-08 12:37:00 +03:00
Added global salt for hashed ips
This commit is contained in:
16
index.js
16
index.js
@@ -18,6 +18,10 @@ var db = new sqlite3.Database('./databases/sponsorTimes.db');
|
|||||||
// Create an HTTP service.
|
// Create an HTTP service.
|
||||||
http.createServer(app).listen(80);
|
http.createServer(app).listen(80);
|
||||||
|
|
||||||
|
//global salt that is added to every ip before hashing to
|
||||||
|
// make it even harder for someone to decode the ip
|
||||||
|
var globalSalt = "49cb0d52-1aec-4b89-85fc-fab2c53062fb";
|
||||||
|
|
||||||
//setup CORS correctly
|
//setup CORS correctly
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
res.header("Access-Control-Allow-Origin", "*");
|
res.header("Access-Control-Allow-Origin", "*");
|
||||||
@@ -59,18 +63,18 @@ app.get('/api/postVideoSponsorTimes', function (req, res) {
|
|||||||
let endTime = req.query.endTime;
|
let endTime = req.query.endTime;
|
||||||
let userID = req.query.userID;
|
let userID = req.query.userID;
|
||||||
|
|
||||||
//x-forwarded-for if this server is behind a proxy
|
|
||||||
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
|
||||||
|
|
||||||
//hash the ip so no one can get it from the database
|
|
||||||
let hashedIP = hash.update(ip).digest('hex');
|
|
||||||
|
|
||||||
if (typeof videoID != 'string' || startTime == undefined || endTime == undefined || userID == undefined) {
|
if (typeof videoID != 'string' || startTime == undefined || endTime == undefined || userID == undefined) {
|
||||||
//invalid request
|
//invalid request
|
||||||
res.sendStatus(400);
|
res.sendStatus(400);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//x-forwarded-for if this server is behind a proxy
|
||||||
|
let ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
|
||||||
|
|
||||||
|
//hash the ip so no one can get it from the database
|
||||||
|
let hashedIP = hash.update(ip + globalSalt).digest('hex');
|
||||||
|
|
||||||
startTime = parseFloat(startTime);
|
startTime = parseFloat(startTime);
|
||||||
endTime = parseFloat(endTime);
|
endTime = parseFloat(endTime);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user