Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClockLeeway and compare time on Millisecond #135

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ type SAMLServiceProvider struct {
ValidateEncryptionCert bool
SkipSignatureValidation bool
AllowMissingAttributes bool

Clock *dsig.Clock
ClockLeeway time.Duration // to handle clock drift issues

// Required encryption key and default signing key.
// Deprecated: Use SetSPKeyStore instead of setting or reading this field.
Expand Down
4 changes: 3 additions & 1 deletion validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const (
//all SAML2 contracts are upheld.
func (sp *SAMLServiceProvider) VerifyAssertionConditions(assertion *types.Assertion) (*WarningInfo, error) {
warningInfo := &WarningInfo{}
now := sp.Clock.Now()
now := sp.Clock.Now().Truncate(time.Millisecond)

conditions := assertion.Conditions
if conditions == nil {
Expand All @@ -77,6 +77,7 @@ func (sp *SAMLServiceProvider) VerifyAssertionConditions(assertion *types.Assert
return nil, ErrParsing{Tag: NotBeforeAttr, Value: conditions.NotBefore, Type: "time.RFC3339"}
}

notBefore = notBefore.Add(-sp.ClockLeeway).Truncate(time.Millisecond)
if now.Before(notBefore) {
warningInfo.InvalidTime = true
}
Expand All @@ -90,6 +91,7 @@ func (sp *SAMLServiceProvider) VerifyAssertionConditions(assertion *types.Assert
return nil, ErrParsing{Tag: NotOnOrAfterAttr, Value: conditions.NotOnOrAfter, Type: "time.RFC3339"}
}

notOnOrAfter = notOnOrAfter.Add(sp.ClockLeeway).Truncate(time.Millisecond)
if now.After(notOnOrAfter) {
warningInfo.InvalidTime = true
}
Expand Down