Skip to content

Gracefully handle bad SAML logout data#4895

Closed
zachmargolis wants to merge 1 commit intomainfrom
saml-error-logout
Closed

Gracefully handle bad SAML logout data#4895
zachmargolis wants to merge 1 commit intomainfrom
saml-error-logout

Conversation

@zachmargolis
Copy link
Contributor

I had some trouble building a request that generated the same error we saw in prod, so I went the route of stubbing something inside the IDP gem and then catching all the places

Fingerprinter.fingerprint_cert(matching_cert || current_service_provider.ssl_certs.first)
saml_request.service_provider.fingerprint = matching_cert ?
Fingerprinter.fingerprint_cert(matching_cert) :
'some-non-nil-value'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully understand the library, but to avoid the magic string, could we do

if matching_cert
  saml_request.service_provider.fingerprint = Fingerprinter.fingerprint_cert(matching_cert)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the library gets cranky if .fingerprint is nil, so that's what I'm trying to avoid at all costs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my confusion is we weren't setting fingerprint before, so it was getting set somewhere? If we need to override we can with the if, and if there's no matching cert, it feels like we should error earlier in the request.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used to pass fingerprint every time: https://github.com/18F/identity-idp/pull/4851/files#diff-fdfe3f731c3c1bb52752814efbd9b353dec85fca38e11f0ccc05e8622b9893beL29-L31

But since fingerprint is tied to a specific cert, we can't do that for multiple certs

Copy link
Contributor Author

@zachmargolis zachmargolis Apr 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(wrong place to comment)

@aduth
Copy link
Contributor

aduth commented Apr 8, 2021

Before multi-cert, we had this line which checked cert.blank? before parsing it. Would this be something we would have wanted to have kept in #4851?

https://github.com/18F/identity-idp/pull/4851/files#diff-fdfe3f731c3c1bb52752814efbd9b353dec85fca38e11f0ccc05e8622b9893beL35

@aduth
Copy link
Contributor

aduth commented Apr 8, 2021

Or change:

@ssl_certs ||= (certs.presence || Array(cert)).map do |cert|

...to:

@ssl_certs ||= (certs.presence || Array(cert).compact).map do |cert|

@orenyk
Copy link
Contributor

orenyk commented Apr 8, 2021

@aduth Array(cert) will always only have a single element, I think since the cert attribute is the old column (I had this same confusion when I initially reviewed this feature).

@zachmargolis
Copy link
Contributor Author

Before multi-cert, we had this line which checked cert.blank? before parsing it. Would this be something we would have wanted to have kept in #4851?

Based on the stack trace from the errors, I think that the nil/blank data is coming from the request when we try to validate it, not from us having blank data inside here

@aduth
Copy link
Contributor

aduth commented Apr 8, 2021

@aduth Array(cert) will always only have a single element, I think since the cert attribute is the old column (I had this same confusion when I initially reviewed this feature).

My thinking was that if cert is nil, Array(cert) results in [nil], whereas Array(cert).compact would result in [].

And [nil].map { |cert| OpenSSL::X509::Certificate.new(load_cert(cert)) } may error?

@zachmargolis
Copy link
Contributor Author

My thinking was that if cert is nil, Array(cert) results in [nil], whereas Array(cert).compact would result in [].

Not exactly! 😬

irb(main):008:0> Array(nil)
=> []

@aduth
Copy link
Contributor

aduth commented Apr 8, 2021

Not exactly! 😬

🤦

@orenyk
Copy link
Contributor

orenyk commented Apr 8, 2021

Lol - whee Ruby!

@zachmargolis
Copy link
Contributor Author

Closing in favor of #4898

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants