Skip to content

Commit f36efce

Browse files
committed
backported error handler from 1.2, closes remote execution exploit
1 parent cdd5106 commit f36efce

File tree

5 files changed

+99
-2
lines changed

5 files changed

+99
-2
lines changed

openid-connect-server-webapp/src/main/webapp/WEB-INF/application-context.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@
155155

156156
<import resource="authz-config.xml" />
157157

158+
<bean id="oauth2ExceptionTranslator" class="org.springframework.security.oauth2.provider.error.DefaultWebResponseExceptionTranslator" />
159+
158160
<bean id="clientCredentialsTokenEndpointFilter" class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
159161
<property name="authenticationManager" ref="clientAuthenticationManager" />
160162
<property name="filterProcessesUrl" value="/token"/>

openid-connect-server-webapp/src/main/webapp/WEB-INF/authz-config.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
request-validator-ref="oauthRequestValidator"
3939
redirect-resolver-ref="blacklistAwareRedirectResolver"
4040
authorization-endpoint-url="/authorize"
41-
token-endpoint-url="/token">
41+
token-endpoint-url="/token"
42+
error-page="/error">
4243

4344
<oauth:authorization-code authorization-code-services-ref="defaultOAuth2AuthorizationCodeService"/>
4445
<oauth:implicit />
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<%@page import="org.springframework.http.HttpStatus"%>
2+
<%@page import="org.springframework.security.oauth2.common.exceptions.OAuth2Exception"%>
3+
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
4+
<%@ taglib prefix="o" tagdir="/WEB-INF/tags"%>
5+
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags"%>
6+
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
7+
<%
8+
9+
if (request.getAttribute("error") != null && request.getAttribute("error") instanceof OAuth2Exception) {
10+
request.setAttribute("errorCode", ((OAuth2Exception)request.getAttribute("error")).getOAuth2ErrorCode());
11+
request.setAttribute("message", ((OAuth2Exception)request.getAttribute("error")).getMessage());
12+
} else if (request.getAttribute("javax.servlet.error.exception") != null) {
13+
Throwable t = (Throwable)request.getAttribute("javax.servlet.error.exception");
14+
request.setAttribute("errorCode", t.getClass().getSimpleName() + " (" + request.getAttribute("javax.servlet.error.status_code") + ")");
15+
request.setAttribute("message", t.getMessage());
16+
} else if (request.getAttribute("javax.servlet.error.status_code") != null) {
17+
Integer code = (Integer)request.getAttribute("javax.servlet.error.status_code");
18+
HttpStatus status = HttpStatus.valueOf(code);
19+
request.setAttribute("errorCode", status.toString() + " " + status.getReasonPhrase());
20+
request.setAttribute("message", request.getAttribute("javax.servlet.error.message"));
21+
} else {
22+
request.setAttribute("errorCode", "Server error");
23+
request.setAttribute("message", "See the logs for details");
24+
}
25+
26+
%>
27+
<o:header title="Error" />
28+
<div class="container-fluid main">
29+
<div class="row-fluid">
30+
<div class="offset1 span10">
31+
<div class="hero-unit">
32+
<h1><span>Error:</span>
33+
<span class="text-error"><c:out value="${ errorCode }" /></span>
34+
</h1>
35+
<p>
36+
There was an error processing your request. The server's message was:
37+
<blockquote class="text-error"><b><c:out value="${ message }" /></b></blockquote>
38+
</p>
39+
40+
</div>
41+
42+
</div>
43+
</div>
44+
</div>
45+
<o:footer />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*******************************************************************************
2+
* Copyright 2015 The MITRE Corporation
3+
* and the MIT Kerberos and Internet Trust Consortium
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*******************************************************************************/
17+
18+
package org.mitre.oauth2.web;
19+
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.http.ResponseEntity;
24+
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception;
25+
import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;
26+
import org.springframework.web.bind.annotation.ControllerAdvice;
27+
import org.springframework.web.bind.annotation.ExceptionHandler;
28+
29+
/**
30+
* Controller helper that handles OAuth2 exceptions and propagates them as JSON errors.
31+
*
32+
* @author jricher
33+
*
34+
*/
35+
@ControllerAdvice
36+
public class OAuth2ExceptionHandler {
37+
private static final Logger logger = LoggerFactory.getLogger(OAuth2ExceptionHandler.class);
38+
39+
@Autowired
40+
private WebResponseExceptionTranslator providerExceptionHandler;
41+
42+
@ExceptionHandler(OAuth2Exception.class)
43+
public ResponseEntity<OAuth2Exception> handleException(Exception e) throws Exception {
44+
logger.info("Handling error: " + e.getClass().getSimpleName() + ", " + e.getMessage());
45+
return providerExceptionHandler.translate(e);
46+
}
47+
48+
}

openid-connect-server/src/main/java/org/mitre/openid/connect/filter/PromptFilter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
9090
}
9191

9292
// we have to create our own auth request in order to get at all the parmeters appropriately
93-
AuthorizationRequest authRequest = authRequestFactory.createAuthorizationRequest(createRequestMap(request.getParameterMap()));
93+
AuthorizationRequest authRequest = null;
9494

9595
ClientDetailsEntity client = null;
9696

9797
try {
98+
authRequest = authRequestFactory.createAuthorizationRequest(createRequestMap(request.getParameterMap()));
9899
client = clientService.loadClientByClientId(authRequest.getClientId());
99100
} catch (InvalidClientException e) {
100101
// no need to worry about this here, it would be caught elsewhere

0 commit comments

Comments
 (0)