Skip to content
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

Commit 36acc48

Browse files
committed
Fixing roles security issues
1 parent 8cccae2 commit 36acc48

File tree

2 files changed

+40
-33
lines changed

2 files changed

+40
-33
lines changed

app/controllers/users.server.controller.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ var getErrorMessage = function(err) {
3636
* Signup
3737
*/
3838
exports.signup = function(req, res) {
39+
// For security measurement we remove the roles from the req.body object
40+
delete req.body.roles;
41+
3942
// Init Variables
4043
var user = new User(req.body);
4144
var message = null;
@@ -44,6 +47,7 @@ exports.signup = function(req, res) {
4447
user.provider = 'local';
4548
user.displayName = user.firstName + ' ' + user.lastName;
4649

50+
// Then save the user
4751
user.save(function(err) {
4852
if (err) {
4953
return res.send(400, {
@@ -96,6 +100,9 @@ exports.update = function(req, res) {
96100
var user = req.user;
97101
var message = null;
98102

103+
// For security measurement we remove the roles from the req.body object
104+
delete req.body.roles;
105+
99106
if (user) {
100107
// Merge existing user
101108
user = _.extend(user, req.body);

config/strategies/google.js

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
'use strict';
22

33
var passport = require('passport'),
4-
url = require('url'),
5-
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy,
6-
config = require('../config'),
7-
users = require('../../app/controllers/users.server.controller');
4+
url = require('url'),
5+
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy,
6+
config = require('../config'),
7+
users = require('../../app/controllers/users.server.controller');
88

99
module.exports = function() {
10-
// Use google strategy
11-
passport.use(new GoogleStrategy({
12-
clientID: config.google.clientID,
13-
clientSecret: config.google.clientSecret,
14-
callbackURL: config.google.callbackPath,
15-
passReqToCallback: true
16-
},
17-
function(req, accessToken, refreshToken, profile, done) {
18-
// Set the provider data and include tokens
19-
var providerData = profile._json;
20-
providerData.accessToken = accessToken;
21-
providerData.refreshToken = refreshToken;
22-
23-
// Create the user OAuth profile
24-
var providerUserProfile = {
25-
firstName: profile.name.givenName,
26-
lastName: profile.name.familyName,
27-
displayName: profile.displayName,
28-
email: profile.emails[0].value,
29-
username: profile.username,
30-
provider: 'google',
31-
providerIdentifierField: 'id',
32-
providerData: providerData
33-
};
10+
// Use google strategy
11+
passport.use(new GoogleStrategy({
12+
clientID: config.google.clientID,
13+
clientSecret: config.google.clientSecret,
14+
callbackURL: config.google.callbackPath,
15+
passReqToCallback: true
16+
},
17+
function(req, accessToken, refreshToken, profile, done) {
18+
// Set the provider data and include tokens
19+
var providerData = profile._json;
20+
providerData.accessToken = accessToken;
21+
providerData.refreshToken = refreshToken;
3422

35-
// Save the user OAuth profile
36-
users.saveOAuthUserProfile(req, providerUserProfile, done);
37-
}
38-
));
39-
};
23+
// Create the user OAuth profile
24+
var providerUserProfile = {
25+
firstName: profile.name.givenName,
26+
lastName: profile.name.familyName,
27+
displayName: profile.displayName,
28+
email: profile.emails[0].value,
29+
username: profile.username,
30+
provider: 'google',
31+
providerIdentifierField: 'id',
32+
providerData: providerData
33+
};
34+
35+
// Save the user OAuth profile
36+
users.saveOAuthUserProfile(req, providerUserProfile, done);
37+
}
38+
));
39+
};

0 commit comments

Comments
 (0)