Skip to content

OidcBackChannelLogoutWebFilter error response is not a correct JSON #16072

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

Closed
katya-tis opened this issue Nov 12, 2024 · 6 comments
Closed

OidcBackChannelLogoutWebFilter error response is not a correct JSON #16072

katya-tis opened this issue Nov 12, 2024 · 6 comments
Assignees
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: bug A general bug

Comments

@katya-tis
Copy link

Describe the bug
When OidcBackChannelLogoutWebFilter returns an error from handleAuthenticationFailure(...) method:

  • the response content type is not set to "application/json";
  • error_uri is missing closing quotes;
  • the text for at least the description should be escaped for special characters.

To Reproduce
Call the oidc back channel logout endpoint without a logout token for example. The response is:

{
	"error_code": "invalid_request",
	"error_description": "An error occurred while attempting to decode the Jwt: Cannot invoke "String.indexOf(String)" because "s" is null",
	"error_uri: "https://openid.net/specs/openid-connect-backchannel-1_0.html#Validation"
}

Expected behavior
The expected response should look like this:

{
    "error_code": "invalid_request",
    "error_description": "An error occurred while attempting to decode the Jwt: Cannot invoke \"String.indexOf(String)\" because \"s\" is null",
    "error_uri": "https://openid.net/specs/openid-connect-backchannel-1_0.html#Validation"
}
@katya-tis katya-tis added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Nov 12, 2024
@sjohnr sjohnr added the in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) label Nov 14, 2024
@harpreets789
Copy link
Contributor

Should the description field in the error response escape quotes for safe use in HTML (e.g., converting " to "), or should it simply escape strings as described in the issue (i.e., using basic string escaping for special characters)?

@harpreets789
Copy link
Contributor

@sjohnr @jzheaux

Request for Clarification:

  • Given that the error_description is part of a JSON response, should I escape the string for HTML use (using HtmlUtils), for JSON use (using StringEscapeUtils.escapeJson), or simply handle specific characters using basic string replacement (with String.replace())?

  • Which approach would be most appropriate for this case considering both the context and the potential security concerns?

@AndreasKasparek
Copy link

@harpreets789 as this is a back-channel call from the OP and https://openid.net/specs/openid-connect-backchannel-1_0.html#BCResponse specifies that an application/json response can be returned in error case, I would expect the error description to be JSON-escaped. If the OP wants to display any of that information on an HTML page, it would by its responsibility to escape it then accordingly.

@jzheaux
Copy link
Contributor

jzheaux commented Dec 6, 2024

@katya-tis, thanks for the report. We'll target the next maintenance release for a fix.

I'd like to know something else in addition to improving the serialization behavior; the error message in your payload appears to be a null pointer exception. Can you share a stack trace or give me more information regarding where the null pointer exception is from so we can make that error message more informative?

@jzheaux
Copy link
Contributor

jzheaux commented Dec 6, 2024

Closed in 3d1e4b5

@AndreasKasparek
Copy link

AndreasKasparek commented Dec 9, 2024

@jzheaux The null pointer exception comes from com.nimbusds.jwt.JWTParser#parse(String) method when the given string is null. For the test the back-channel logout endpoint was called without an actual logout token. The org.springframework.security.config.web.server.OidcLogoutServerAuthenticationConverter just reads the logout_token parameter from the form data and creates a new OidcLogoutAuthenticationToken from it. Neither the converter nor the ctor of the token class checks if the string is null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants