Skip to content

Commit

Permalink
Add security flags to cookies (HttpOnly, secure)
Browse files Browse the repository at this point in the history
Fixes #4525
  • Loading branch information
cgx committed Aug 21, 2018
1 parent 69c03e7 commit 828d773
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
1 change: 1 addition & 0 deletions NEWS
Expand Up @@ -7,6 +7,7 @@ New features
Enhancements
- [web] prohibit duplicate calendar categories in Preferences module
- [web] added Romanian (ro) translation - thanks to Vasile Razvan Luca
- [web] add security flags to cookies (HttpOnly, secure) (#4525)
- [core] enable Oracle OCI support for CentOS/RHEL v7

Bug fixes
Expand Down
9 changes: 8 additions & 1 deletion SoObjects/SOGo/SOGoWebAuthenticator.m
Expand Up @@ -383,6 +383,7 @@ - (WOCookie *) cookieWithUsername: (NSString *) username
{
WOCookie *authCookie;
NSString *cookieValue, *cookieString, *appName, *sessionKey, *userKey, *securedPassword;
BOOL isSecure;

//
// We create a new cookie - thus we create a new session
Expand All @@ -409,8 +410,14 @@ - (WOCookie *) cookieWithUsername: (NSString *) username
userKey, sessionKey];
cookieValue = [NSString stringWithFormat: @"basic %@",
[cookieString stringByEncodingBase64]];
isSecure = [[[context serverURL] scheme] isEqualToString: @"https"];
authCookie = [WOCookie cookieWithName: [self cookieNameInContext: context]
value: cookieValue];
value: cookieValue
path: nil
domain: nil
expires: nil
isSecure: isSecure
httpOnly: YES];
appName = [[context request] applicationName];
[authCookie setPath: [NSString stringWithFormat: @"/%@/", appName]];

Expand Down
23 changes: 3 additions & 20 deletions UI/WebServerResources/js/Common/Authentication.service.js
Expand Up @@ -57,18 +57,6 @@
function getService($q, $http, $cookies, passwordPolicyConfig) {
var service;

function readLoginCookie() {
var loginValues = null,
cookie = $cookies.get('0xHIGHFLYxSOGo'),
value;
if (cookie && cookie.length > 8) {
value = decodeURIComponent(cookie.substr(8));
loginValues = value.base64decode().split(':');
}

return loginValues;
}

service = {
login: function(data) {
var d = $q.defer(),
Expand Down Expand Up @@ -99,9 +87,8 @@
}).then(function(response) {
var data = response.data;
// Make sure browser's cookies are enabled
var loginCookie = readLoginCookie();
if (!loginCookie) {
d.reject(l('cookiesNotEnabled'));
if (navigator && !navigator.cookieEnabled) {
d.reject({error: l('cookiesNotEnabled')});
}
else {
// Check password policy
Expand Down Expand Up @@ -145,7 +132,6 @@

changePassword: function(newPassword) {
var d = $q.defer(),
loginCookie = readLoginCookie(),
xsrfCookie = $cookies.get('XSRF-TOKEN');

$cookies.remove('XSRF-TOKEN', {path: '/SOGo/'});
Expand All @@ -156,10 +142,7 @@
headers: {
'X-XSRF-TOKEN' : xsrfCookie
},
data: {
userName: loginCookie[0],
password: loginCookie[1],
newPassword: newPassword }
data: { newPassword: newPassword }
}).then(d.resolve, function(response) {
var error,
data = response.data,
Expand Down

0 comments on commit 828d773

Please sign in to comment.