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

Commit

Permalink
Merge pull request #997 from yilenpan/feat/csrf
Browse files Browse the repository at this point in the history
[feat] Added Lusca middleware for CSRF [fixes #828]
  • Loading branch information
lirantal committed Feb 20, 2016
2 parents bdac45f + b2db312 commit 35d7501
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
13 changes: 13 additions & 0 deletions config/env/default.js
Expand Up @@ -28,6 +28,19 @@ module.exports = {
// for obsecurity reasons
sessionKey: 'sessionId',
sessionCollection: 'sessions',
// Lusca config
csrf: {
csrf: false,
csp: { /* Content Security Policy object */},
xframe: 'SAMEORIGIN',
p3p: 'ABCDEF',
hsts: {
maxAge: 31536000, // Forces HTTPS for one year
includeSubDomains: true,
preload: true
},
xssProtection: true
},
logo: 'modules/core/client/img/brand/logo.png',
favicon: 'modules/core/client/img/brand/favicon.ico',
uploads: {
Expand Down
8 changes: 6 additions & 2 deletions config/lib/express.js
Expand Up @@ -17,7 +17,8 @@ var config = require('../config'),
helmet = require('helmet'),
flash = require('connect-flash'),
consolidate = require('consolidate'),
path = require('path');
path = require('path'),
lusca = require('lusca');

/**
* Initialize local variables
Expand Down Expand Up @@ -122,6 +123,9 @@ module.exports.initSession = function (app, db) {
collection: config.sessionCollection
})
}));

// Add Lusca CSRF Middleware
app.use(lusca(config.csrf));
};

/**
Expand Down Expand Up @@ -228,7 +232,7 @@ module.exports.init = function (db) {

// Initialize Express view engine
this.initViewEngine(app);

// Initialize Helmet security headers
this.initHelmetHeaders(app);

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -43,6 +43,7 @@
"helmet": "~0.9.1",
"jasmine-core": "~2.3.4",
"lodash": "~3.10.0",
"lusca": "~1.3.0",
"method-override": "~2.3.3",
"mocha": "~2.4.5",
"mongoose": "~4.2.3",
Expand Down

0 comments on commit 35d7501

Please sign in to comment.