Skip to content

DefaultLoginPageGeneratingFilter should be able to handle AuthenticationExceptions without message #13768

Closed
@pctF

Description

@pctF

Describe the bug

Right now DefaultLoginPageGeneratingFilter#getLoginErrorMessage can return nullable exception message. This message passed to org.springframework.web.util.HtmlUtils#htmlEscape with can not handle null with results in exception in.. exception handling.

I think filter should have normal flow because:

  1. It is default filter for many applications
  2. Message is nullable attribute and there is always a chance to catch one with null message and there is really no valid way to enforce otherwise at this point

To Reproduce

Create an filter/user service that throws org.springframework.security.core.AuthenticationException with null message.

java.lang.IllegalArgumentException: Input is required
        at org.springframework.util.Assert.notNull(Assert.java:201)
	at org.springframework.web.util.HtmlUtils.htmlEscape(HtmlUtils.java:83)
	at org.springframework.web.util.HtmlUtils.htmlEscape(HtmlUtils.java:63)
	at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.createError(DefaultLoginPageGeneratingFilter.java:372)

Expected behavior

Here should be some discussion:

  1. We already have default message: "Invalid credentials". IMHO it doesn't really fit
  2. We can show at least exception name ie: exception.getClass().getSimpleName(). It doesn't expose much but can provide some information
  3. Utilize org.springframework.context.MessageSourceAware with some default message like "Unexpected error while performing login" and code for overriding it. Seems like commitment for future backward compatibility but possible.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions