made req.oauth3 immutable after its creation

This commit is contained in:
tigerbot 2017-08-11 16:38:22 -06:00
parent de594964b4
commit 92d052faf0
1 changed files with 11 additions and 0 deletions

View File

@ -165,6 +165,15 @@ function verifyToken(token) {
});
}
function deepFreeze(obj) {
Object.keys(obj).forEach(function (key) {
if (obj[key] && typeof obj[key] === 'object') {
deepFreeze(obj[key]);
}
});
Object.freeze(obj);
}
function attachOauth3(req, res, next) {
req.oauth3 = {};
@ -210,6 +219,8 @@ function attachOauth3(req, res, next) {
return PromiseA.resolve(sub || ppid);
};
}).then(function () {
deepFreeze(req.oauth3);
Object.defineProperty(req, 'oauth3', {configurable: false, writable: false});
next();
}, function (err) {
res.send(err);