Skip to content

Commit 3987aa2

Browse files
committed
Support InResponseTo validations through in MultiSaml
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
1 parent e2154f2 commit 3987aa2

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

multiSamlStrategy.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,50 @@
11
var util = require('util');
22
var saml = require('./lib/passport-saml/saml');
3+
var InMemoryCacheProvider = require('./lib/passport-saml/inmemory-cache-provider').CacheProvider;
34
var SamlStrategy = require('./lib/passport-saml/strategy');
45

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

11+
if(!options.requestIdExpirationPeriodMs){
12+
options.requestIdExpirationPeriodMs = 28800000; // 8 hours
13+
}
14+
15+
if(!options.cacheProvider){
16+
options.cacheProvider = new InMemoryCacheProvider(
17+
{keyExpirationPeriodMs: options.requestIdExpirationPeriodMs });
18+
}
19+
1020
SamlStrategy.call(this, options, verify);
11-
this._getSamlOptions = options.getSamlOptions;
21+
this._options = options;
1222
}
1323

1424
util.inherits(MultiSamlStrategy, SamlStrategy);
1525

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

19-
this._getSamlOptions(req, function (err, samlOptions) {
29+
this._options.getSamlOptions(req, function (err, samlOptions) {
2030
if (err) {
2131
return self.error(err);
2232
}
2333

24-
self._saml = new saml.SAML(samlOptions);
34+
self._saml = new saml.SAML({ ...this._options, ...samlOptions });
2535
self.constructor.super_.prototype.authenticate.call(self, req, options);
2636
});
2737
};
2838

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

32-
this._getSamlOptions(req, function (err, samlOptions) {
42+
this._options.getSamlOptions(req, function (err, samlOptions) {
3343
if (err) {
3444
return self.error(err);
3545
}
3646

37-
self._saml = new saml.SAML(samlOptions);
47+
self._saml = new saml.SAML({ ...this._options, ...samlOptions });
3848
self.constructor.super_.prototype.logout.call(self, req, options);
3949
});
4050
};

0 commit comments

Comments
 (0)