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

Commit

Permalink
Fixing roles security issues
Browse files Browse the repository at this point in the history
  • Loading branch information
amoshaviv committed Apr 26, 2014
1 parent 8cccae2 commit 36acc48
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
7 changes: 7 additions & 0 deletions app/controllers/users.server.controller.js
Expand Up @@ -36,6 +36,9 @@ var getErrorMessage = function(err) {
* Signup
*/
exports.signup = function(req, res) {
// For security measurement we remove the roles from the req.body object
delete req.body.roles;

// Init Variables
var user = new User(req.body);
var message = null;
Expand All @@ -44,6 +47,7 @@ exports.signup = function(req, res) {
user.provider = 'local';
user.displayName = user.firstName + ' ' + user.lastName;

// Then save the user
user.save(function(err) {
if (err) {
return res.send(400, {
Expand Down Expand Up @@ -96,6 +100,9 @@ exports.update = function(req, res) {
var user = req.user;
var message = null;

// For security measurement we remove the roles from the req.body object
delete req.body.roles;

if (user) {
// Merge existing user
user = _.extend(user, req.body);
Expand Down
66 changes: 33 additions & 33 deletions config/strategies/google.js
@@ -1,39 +1,39 @@
'use strict';

var passport = require('passport'),
url = require('url'),
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy,
config = require('../config'),
users = require('../../app/controllers/users.server.controller');
url = require('url'),
GoogleStrategy = require('passport-google-oauth').OAuth2Strategy,
config = require('../config'),
users = require('../../app/controllers/users.server.controller');

module.exports = function() {
// Use google strategy
passport.use(new GoogleStrategy({
clientID: config.google.clientID,
clientSecret: config.google.clientSecret,
callbackURL: config.google.callbackPath,
passReqToCallback: true
},
function(req, accessToken, refreshToken, profile, done) {
// Set the provider data and include tokens
var providerData = profile._json;
providerData.accessToken = accessToken;
providerData.refreshToken = refreshToken;

// Create the user OAuth profile
var providerUserProfile = {
firstName: profile.name.givenName,
lastName: profile.name.familyName,
displayName: profile.displayName,
email: profile.emails[0].value,
username: profile.username,
provider: 'google',
providerIdentifierField: 'id',
providerData: providerData
};
// Use google strategy
passport.use(new GoogleStrategy({
clientID: config.google.clientID,
clientSecret: config.google.clientSecret,
callbackURL: config.google.callbackPath,
passReqToCallback: true
},
function(req, accessToken, refreshToken, profile, done) {
// Set the provider data and include tokens
var providerData = profile._json;
providerData.accessToken = accessToken;
providerData.refreshToken = refreshToken;

// Save the user OAuth profile
users.saveOAuthUserProfile(req, providerUserProfile, done);
}
));
};
// Create the user OAuth profile
var providerUserProfile = {
firstName: profile.name.givenName,
lastName: profile.name.familyName,
displayName: profile.displayName,
email: profile.emails[0].value,
username: profile.username,
provider: 'google',
providerIdentifierField: 'id',
providerData: providerData
};

// Save the user OAuth profile
users.saveOAuthUserProfile(req, providerUserProfile, done);
}
));
};

0 comments on commit 36acc48

Please sign in to comment.