mirror of
https://github.com/keycloak/keycloak.git
synced 2025-12-16 20:15:46 -06:00
fix: preventing raw stacktrace response and error log (#44815)
closes: #44712 Signed-off-by: Steve Hawkins <shawkins@redhat.com>
This commit is contained in:
@@ -107,7 +107,7 @@ public class KeycloakErrorHandler implements ExceptionMapper<Throwable> {
|
||||
}
|
||||
|
||||
return Response.status(responseStatus)
|
||||
.header(HttpHeaders.CONTENT_TYPE, jakarta.ws.rs.core.MediaType.APPLICATION_JSON_TYPE.toString())
|
||||
.type(MediaType.APPLICATION_JSON_TYPE)
|
||||
.entity(error)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -3,8 +3,12 @@ package org.keycloak.utils;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
public class MediaTypeMatcher {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(MediaTypeMatcher.class);
|
||||
|
||||
public static boolean isHtmlRequest(HttpHeaders headers) {
|
||||
return isAcceptMediaType(headers, MediaType.TEXT_HTML_TYPE);
|
||||
}
|
||||
@@ -14,10 +18,15 @@ public class MediaTypeMatcher {
|
||||
}
|
||||
|
||||
private static boolean isAcceptMediaType(HttpHeaders headers, MediaType textHtmlType) {
|
||||
for (MediaType m : headers.getAcceptableMediaTypes()) {
|
||||
if (!m.isWildcardType() && m.isCompatible(textHtmlType)) {
|
||||
return true;
|
||||
try {
|
||||
for (MediaType m : headers.getAcceptableMediaTypes()) {
|
||||
if (!m.isWildcardType() && m.isCompatible(textHtmlType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// illegal state, or illegal argument are possible
|
||||
logger.debug("Could not determine if the media type is accepted", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user