Skip to content

Saml2WebSsoAuthenticationFilter does not follow standard patterns for request matching. #8768

Closed
@fpagliar

Description

@fpagliar

Describe the bug

The common pattern for filters is to provide the ability to set a custom RequestMatcher for them to execute.
This is the case for Saml2WebSsoAuthenticationRequestFilter and AbstractAuthenticationProcessingFilter.

Now Saml2WebSsoAuthenticationFilter extends AbstractAuthenticationProcessingFilter but creates its own custom private RequestMatcher from a String.
This is unnecessarily restrictive for the developer, and goes against the common pattern.

Not only that, but since AbstractAuthenticationProcessingFilter provides setRequiresAuthenticationRequestMatcher()
A developer can totally unknowingly set a different matcher on the parent.

Example

The following line compiles and looks valid to a developer using SpringSecurity, but creates an instance of the filter that is completely inconsistent.

final Saml2WebSsoAuthenticationFilter myFilter = new Saml2WebSsoAuthenticationFilter(getRelyingPartyRegistrationRepository());
myFilter.setRequiresAuthenticationRequestMatcher(new AntPathRequestMatcher("/someother"));

The method requiresAuthentication will match based on the parent matcher, but attemptAuthentication will match based on the local one.

Activity

added
in: saml2An issue in SAML2 modules
and removed on Jun 27, 2020
self-assigned this
on Jun 27, 2020
fpagliar

fpagliar commented on Jun 29, 2020

@fpagliar
Author

I was looking and the old infrastructure (spring-security-saml) uses the same URL endpoint for authentication for every IdP and picks up the appropriate configuration info from the cache by matching based on the issuer ID.

That allows to have one SP config and multiple IdPs pointing with the exact same config. Is there a benefit for the current alternative of requiring a different endpoint per IdP config?

jzheaux

jzheaux commented on Jun 29, 2020

@jzheaux
Contributor

@fpagliar, it allows looking up the configuration without needing to first parse the assertion. I believe the other approach is valid, too, but perhaps discussing how to best address that is for another ticket.

For this ticket, it appears the private matcher is there simply because the parent class keeps the requiresAuthenticationRequestMatcher private. I believe it would resolve the issue to override setRequiresAuthenticationRequestMatcher to set both the local matcher and the parent's matcher.

Would you be able to submit a PR to bring those to member variables into alignment?

fpagliar

fpagliar commented on Jun 30, 2020

@fpagliar
Author

I can. I was wondering about the implementation though.
AbstractAuthenticationProcessingFilter.setRequiresAuthenticationRequestMatcher() is a final method, and that makes sense given that it is called from the constructor so it shouldn't be overrideable.

Any alternative I'm thinking of right now requires either redesigning that bit on the AbstractAuthenticationProcessingFilter or accepting/documenting some part of inconsistency. I'll sit on it for a bit and see what I come up with.

added 2 commits that reference this issue on Aug 5, 2020
added this to the 5.4.0-RC1 milestone on Aug 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: saml2An issue in SAML2 modulestype: bugA general bug

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @fpagliar@jzheaux

      Issue actions

        Saml2WebSsoAuthenticationFilter does not follow standard patterns for request matching. · Issue #8768 · spring-projects/spring-security