Skip to content

Commit 1b9f577

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 1b9f577

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ passport.use(new MultiSamlStrategy(
7373
);
7474
```
7575

76+
Using multiple providers supports `validateInResponseTo`, but all the `InResponse` values are stored on the same Cache. This means that all providers have access to it and a provider might get its response validated against another's request. [Issue Report](!https://github.com/bergie/passport-saml/issues/334)
77+
7678
#### The profile object:
7779

7880
The profile object referenced above contains the following:

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({ ...self._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({ ...self._options, ...samlOptions });
3848
self.constructor.super_.prototype.logout.call(self, req, options);
3949
});
4050
};

0 commit comments

Comments
 (0)