Last active
July 17, 2018 09:06
-
-
Save AdityaChaudhary/076f826fbcb5a2cec21552731a59962f to your computer and use it in GitHub Desktop.
Node.js insecure deserialization server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var cookieParser = require('cookie-parser'); | |
var escape = require('escape-html'); | |
var serialize = require('node-serialize'); | |
var app = express(); | |
app.use(cookieParser()) | |
app.get('/', function(req, res) { | |
if (req.cookies.profile) { | |
var str = new Buffer(req.cookies.profile, 'base64').toString(); | |
var obj = serialize.unserialize(str); | |
if (obj.username) { | |
res.send("Hello " + escape(obj.username)); | |
} | |
} else { | |
res.cookie('profile', "eyJ1c2VybmFtZSI6IkFkaXR5YSIsImNvdW50cnkiOiJpbmRpYSIsImNpdHkiOiJEZWxoaSJ9", { | |
maxAge: 900000, | |
httpOnly: true | |
}); | |
} | |
res.send("Hello World"); | |
}); | |
app.listen(3000); | |
console.log("Listening on port 3000..."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment