-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Add support for validation of InResponseTo attribute when validating SAML2 responses #10849
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
Conversation
@fast-reflexes Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
@fast-reflexes Thank you for signing the Contributor License Agreement! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @fast-reflexes! I've left some feedback inline.
Additionally, will you please format your commit message like this:
Commit Title
Closes gh-9174
...-service-provider/src/main/java/org/springframework/security/saml2/core/Saml2ErrorCodes.java
Show resolved
Hide resolved
...ework/security/saml2/provider/service/authentication/AbstractSaml2AuthenticationRequest.java
Outdated
Show resolved
Hide resolved
...framework/security/saml2/provider/service/authentication/OpenSamlAuthenticationProvider.java
Outdated
Show resolved
Hide resolved
...ramework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProvider.java
Outdated
Show resolved
Hide resolved
c3456d0
to
5dc183d
Compare
@jzheaux I updated the branch and also included eviction of stale stored requests. Updated behaviour:
Questions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @fast-reflexes! I've left some feedback inline.
In addition to that feedback, will you do me the favor of making your commit title just a tad shorter? ~50 characters is ideal. This helps when scanning through Git logs.
...ramework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProvider.java
Show resolved
Hide resolved
...curity/saml2/provider/service/web/authentication/OpenSaml4AuthenticationRequestResolver.java
Outdated
Show resolved
Hide resolved
...ework/security/saml2/provider/service/authentication/AbstractSaml2AuthenticationRequest.java
Outdated
Show resolved
Hide resolved
I updated based on your feedback.
These are my remarks as a programmer and a Spring user :) In here, I'm nothing but someone who wants to get more involved and learn to contribute so I respect your decisions to 100% and without debate, just letting you know what I think :) Let me know what you think of the current state of the code :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @fast-reflexes! Glad this is taking shape. I've left some feedback inline.
...-service-provider/src/main/java/org/springframework/security/saml2/core/Saml2ErrorCodes.java
Outdated
Show resolved
Hide resolved
...ramework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProvider.java
Outdated
Show resolved
Hide resolved
...ork/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProviderTests.java
Outdated
Show resolved
Hide resolved
...ramework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProvider.java
Outdated
Show resolved
Hide resolved
...ramework/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProvider.java
Outdated
Show resolved
Hide resolved
...ork/security/saml2/provider/service/authentication/OpenSaml4AuthenticationProviderTests.java
Show resolved
Hide resolved
I see your point, but not how to apply it.
We can always add this in a separate PR down the road. I think boolean properties should be added quite slowly and with more usage data than we have now. You are welcome to add a ticket and then we can see if the community votes for it. |
Aha.. so THAT'S the problem ... hmm .. ok, then I'll rest my case for now! |
Factored out repeatedly used code for signing a request.
a172bcb
to
2f1d161
Compare
context.put(SAML2AssertionValidationParameters.SC_VALID_IN_RESPONSE_TO, requestId); | ||
} | ||
else { | ||
context.put(SAML2AssertionValidationParameters.SC_VALID_IN_RESPONSE_TO, ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we set the empty string so that we know that the validation will fail (since the very prerequisite for even doing the validation is that the some of the assertion subject confirmation has a non-empty InResponseTo
). The reason for failing is either that there was no stored request, it could not be deserialized or it lacked id. You think this solution is ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could trigger a false positive if we have multiple confirmations and one has the (invalid) empty string as InResponseTo
whereas a later one has a proper one ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps better to stay with the override anyways?
- Won't be more code than is added by this solution
- Easier to understand what's going on
- Will cover all cases since we can control directly whether to consider valid or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can just leave it unset. The OpenSAML code works as follows:
- If no
InResponseTo
in subject confirmation -> valid - Or, if no
SC_VALID_IN_RESPONSE_TO
set -> invalid - Or, if
SC_VALID_IN_RESPONSE_TO
mismatchesInResponseTo
-> invalid
Could trigger a false positive
If any assertions are wrong, then we should fail. We don't accept a response that is in response to multiple requests.
override anyways ... Easier to understand what's going on
Ideally, we don't write code that we don't have to as this lowers maintenance. I don't see why it's easier to understand what is going on. The code that you have written is virtually the same as OpenSAML's BearerSubjectConfirmationValidator#validateInResponseTo
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah of course, can be unset, I don't know what I was thinking... and what I meant by
Could trigger a false positive if we have multiple confirmations and one has the (invalid) empty string as
InResponseTo whereas a later one has a proper one ...
was that if an assertion has a subject confirmation with the empty string as InResponseTo
and SC_VALID_IN_RESPONSE_TO
was set to the empty string due to problems with deserialization, then the subject confirmation would falsely be valid no matter the value of the actual request id. I was talking about multiple confirmations (not assertions) because apparently it seems it is enough with one confirmation passing the test on the subject (see SAML20AssertionValidator::validateSubjectConfirmation
). I now realized that the false positive does not require two confirmations even, just one with the empty string. However, since we can leave it unset, it should not be a problem.
I've updated the code, let me know what you think!
Whenever an InResponseTo is present in the SAML2 response and / or any of its assertions, it will be validated against the stored SAML2 request. If the request is missing or the ID of the request does not match the InResponseTo, validation fails. If there is no InResponseTo, no validation of it is done (as opposed to checking whether there is a saved request or not and then failing based on that). Closes spring-projectsgh-9174
Thanks, @fast-reflexes! I've merged your commits into |
Great, thanks @jzheaux ! I looked into your changes to learn the style... what do you mean by
Just curious :) |
… a SAML2 response given that this attribute is set and that the request can be found.
#9174
What do you think so far?
Left to do that I know of: