Skip to content

Commit

Permalink
Support InResponseTo validations through in MultiSaml
Browse files Browse the repository at this point in the history
Either use cache provided by user, or a default memory
cache to store InResponse parameters. This cache is not
yet partitioned per provider, which means a malicious
provider could do replay attacks by using anothers
unconsummed `InResponse` values

node-saml#334
  • Loading branch information
stavros-wb committed Feb 8, 2019
1 parent e2154f2 commit 3987aa2
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions multiSamlStrategy.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,50 @@
var util = require('util');
var saml = require('./lib/passport-saml/saml');
var InMemoryCacheProvider = require('./lib/passport-saml/inmemory-cache-provider').CacheProvider;
var SamlStrategy = require('./lib/passport-saml/strategy');

function MultiSamlStrategy (options, verify) {
if (!options || typeof options.getSamlOptions != 'function') {
throw new Error('Please provide a getSamlOptions function');
}

if(!options.requestIdExpirationPeriodMs){
options.requestIdExpirationPeriodMs = 28800000; // 8 hours
}

if(!options.cacheProvider){
options.cacheProvider = new InMemoryCacheProvider(
{keyExpirationPeriodMs: options.requestIdExpirationPeriodMs });
}

SamlStrategy.call(this, options, verify);
this._getSamlOptions = options.getSamlOptions;
this._options = options;
}

util.inherits(MultiSamlStrategy, SamlStrategy);

MultiSamlStrategy.prototype.authenticate = function (req, options) {
var self = this;

this._getSamlOptions(req, function (err, samlOptions) {
this._options.getSamlOptions(req, function (err, samlOptions) {
if (err) {
return self.error(err);
}

self._saml = new saml.SAML(samlOptions);
self._saml = new saml.SAML({ ...this._options, ...samlOptions });
self.constructor.super_.prototype.authenticate.call(self, req, options);
});
};

MultiSamlStrategy.prototype.logout = function (req, options) {
var self = this;

this._getSamlOptions(req, function (err, samlOptions) {
this._options.getSamlOptions(req, function (err, samlOptions) {
if (err) {
return self.error(err);
}

self._saml = new saml.SAML(samlOptions);
self._saml = new saml.SAML({ ...this._options, ...samlOptions });
self.constructor.super_.prototype.logout.call(self, req, options);
});
};
Expand Down

0 comments on commit 3987aa2

Please sign in to comment.