Skip to content

Commit 3272ed4

Browse files
committed
Close #89 Allow clock drift when validating NotBefore and NotOnOrAfter attributes
1 parent 2afea4f commit 3272ed4

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

core/src/main/java/com/onelogin/saml2/authn/SamlResponse.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ public boolean isValid(String requestId) {
271271
// Check the session Expiration
272272
DateTime sessionExpiration = this.getSessionNotOnOrAfter();
273273
if (sessionExpiration != null) {
274+
sessionExpiration = sessionExpiration.plus(Constants.ALOWED_CLOCK_DRIFT * 1000);
274275
if (sessionExpiration.isEqualNow() || sessionExpiration.isBeforeNow()) {
275276
throw new ValidationError("The attributes have expired, based on the SessionNotOnOrAfter of the AttributeStatement of this Response", ValidationError.SESSION_EXPIRED);
276277
}
@@ -364,6 +365,7 @@ private void validateSubjectConfirmation(String responseInResponseTo) throws XPa
364365
}
365366

366367
DateTime noa = Util.parseDateTime(notOnOrAfter.getNodeValue());
368+
noa = noa.plus(Constants.ALOWED_CLOCK_DRIFT * 1000);
367369
if (noa.isEqualNow() || noa.isBeforeNow()) {
368370
validationIssues.add(new SubjectConfirmationIssue(i, "SubjectConfirmationData is no longer valid"));
369371
continue;
@@ -372,6 +374,7 @@ private void validateSubjectConfirmation(String responseInResponseTo) throws XPa
372374
Node notBefore = subjectConfirmationDataNodes.item(c).getAttributes().getNamedItem("NotBefore");
373375
if (notBefore != null) {
374376
DateTime nb = Util.parseDateTime(notBefore.getNodeValue());
377+
nb = nb.minus(Constants.ALOWED_CLOCK_DRIFT * 1000);
375378
if (nb.isAfterNow()) {
376379
validationIssues.add(new SubjectConfirmationIssue(i, "SubjectConfirmationData is not yet valid"));
377380
continue;
@@ -900,14 +903,16 @@ public boolean validateTimestamps() throws ValidationError {
900903
Node naAttribute = attrName.getNamedItem("NotOnOrAfter");
901904
// validate NotOnOrAfter
902905
if (naAttribute != null) {
903-
final DateTime notOnOrAfterDate = Util.parseDateTime(naAttribute.getNodeValue());
906+
DateTime notOnOrAfterDate = Util.parseDateTime(naAttribute.getNodeValue());
907+
notOnOrAfterDate = notOnOrAfterDate.plus(Constants.ALOWED_CLOCK_DRIFT * 1000);
904908
if (notOnOrAfterDate.isEqualNow() || notOnOrAfterDate.isBeforeNow()) {
905909
throw new ValidationError("Could not validate timestamp: expired. Check system clock.", ValidationError.ASSERTION_EXPIRED);
906910
}
907911
}
908912
// validate NotBefore
909913
if (nbAttribute != null) {
910-
final DateTime notBeforeDate = Util.parseDateTime(nbAttribute.getNodeValue());
914+
DateTime notBeforeDate = Util.parseDateTime(nbAttribute.getNodeValue());
915+
notBeforeDate = notBeforeDate.minus(Constants.ALOWED_CLOCK_DRIFT * 1000);
911916
if (notBeforeDate.isAfterNow()) {
912917
throw new ValidationError("Could not validate timestamp: not yet valid. Check system clock.", ValidationError.ASSERTION_TOO_EARLY);
913918
}

0 commit comments

Comments
 (0)