Skip to content

Commit

Permalink
Tighten clock skew checks for SAML. (auth0#97)
Browse files Browse the repository at this point in the history
Changing default clock skew to 3 minutes to adhere to standard industry practice.
Also make clock skew a configurable option.
  • Loading branch information
gkwang authored Sep 21, 2018
1 parent dda3ce4 commit d79a7ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
8 changes: 5 additions & 3 deletions lib/passport-wsfed-saml2/saml.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var SAML = function (options) {
this.options.checkExpiration = (typeof this.options.checkExpiration !== 'undefined') ? this.options.checkExpiration : true;
// Note! It would be best to set this to true. But it's defaulting to false so as not to break login for expired certs.
this.options.checkCertExpiration = (typeof this.options.checkCertExpiration !== 'undefined') ? this.options.checkCertExpiration : false;
//clockskew in minutes
this.options.clockSkew = (typeof this.options.clockSkew === 'number' && this.options.clockSkew >= 0) ? this.options.clockSkew : 3;
this.options.checkAudience = (typeof this.options.checkAudience !== 'undefined') ? this.options.checkAudience : true;
this.options.checkRecipient = (typeof this.options.checkRecipient !== 'undefined') ? this.options.checkRecipient : true;
this.options.checkNameQualifier = (typeof this.options.checkNameQualifier !== 'undefined') ? this.options.checkNameQualifier : true;
Expand Down Expand Up @@ -133,15 +135,15 @@ SAML.prototype.validateCertExpiration = function (validatedSamlAssertion) {
};

SAML.prototype.validateExpiration = function (samlAssertion, version) {

var self = this;
var conditions = xpath.select(".//*[local-name(.)='Conditions']", samlAssertion);
if (!conditions || conditions.length === 0) return true;

var notBefore = new Date(conditions[0].getAttribute('NotBefore'));
notBefore = notBefore.setMinutes(notBefore.getMinutes() - 5); // 5 minutes clock skew
notBefore = notBefore.setMinutes(notBefore.getMinutes() - self.options.clockSkew);

var notOnOrAfter = new Date(conditions[0].getAttribute('NotOnOrAfter'));
notOnOrAfter = notOnOrAfter.setMinutes(notOnOrAfter.getMinutes() + 5); // 5 minutes clock skew
notOnOrAfter = notOnOrAfter.setMinutes(notOnOrAfter.getMinutes() + self.options.clockSkew);
var now = new Date();

if (now < notBefore || now > notOnOrAfter)
Expand Down
23 changes: 17 additions & 6 deletions test/saml20.tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d79a7ff

Please sign in to comment.