Skip to content

Commit 11daa05

Browse files
committed
LUTECE-2206 : Avoid open redirect when modifying a theme
1 parent 342ca3e commit 11daa05

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/java/fr/paris/lutece/portal/web/style/ThemesJspBean.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ public String doModifyUserTheme( HttpServletRequest request, HttpServletResponse
138138
String strTheme = request.getParameter( PARAMETER_THEME );
139139
String strForwardUrl = request.getParameter( PARAMETER_URL );
140140

141-
if ( !SecurityUtil.containsCleanParameters( request ) )
141+
if ( !SecurityUtil.containsCleanParameters( request )
142+
|| !SecurityUtil.isForwardUrlValid( strForwardUrl, request) )
142143
{
143144
return AppPathService.getBaseUrl( request );
144145
}

src/java/fr/paris/lutece/util/http/SecurityUtil.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
*/
3434
package fr.paris.lutece.util.http;
3535

36+
import fr.paris.lutece.portal.service.util.AppPathService;
3637
import fr.paris.lutece.portal.web.LocalVariables;
3738
import fr.paris.lutece.util.string.StringUtil;
3839

@@ -266,6 +267,36 @@ public static String getRealIp( HttpServletRequest request )
266267

267268
return strIPAddress;
268269
}
270+
271+
/**
272+
* Validate a forward URL,
273+
* the url should :
274+
* - not be blank (null or empty string or spaces)
275+
* - start with the base URL, or not start with "http" or "//"
276+
*
277+
* example with a base url "https://lutece.fr/ :
278+
* - valid : /jsp/site/Portal.jsp , Another.jsp , https://lutece.fr/jsp/site/Portal.jsp
279+
* - invalid : http://anothersite.com , https://anothersite.com , //anothersite.com , file://my.txt , ...
280+
*
281+
* @param strForwardUrl
282+
* @param request
283+
* @return
284+
*/
285+
public static boolean isForwardUrlValid( String strForwardUrl, HttpServletRequest request )
286+
{
287+
288+
if ( StringUtils.isBlank( strForwardUrl) ) return false ;
289+
290+
if ( ( strForwardUrl.startsWith("//") || strForwardUrl.contains("://") )
291+
&& !strForwardUrl.startsWith ( AppPathService.getBaseUrl( request ) ) ) {
292+
return false;
293+
}
294+
else
295+
{
296+
return true;
297+
}
298+
}
299+
269300

270301
/**
271302
* Identify user data saved in log files to prevent Log Forging attacks

0 commit comments

Comments
 (0)