Conversation
|
|
||
| if ( ( strForwardUrl.startsWith("//") || strForwardUrl.contains("://") ) | ||
| && !strForwardUrl.startsWith ( AppPathService.getBaseUrl( request ) ) ) { | ||
| return false; |
There was a problem hiding this comment.
You should log here as is done in the other methods of this class
| * example with a base url "https://lutece.fr/ : | ||
| * - valid : /jsp/site/Portal.jsp , Another.jsp , https://lutece.fr/jsp/site/Portal.jsp | ||
| * - invalid : http://anothersite.com , https://anothersite.com , //anothersite.com , file://my.txt , ... | ||
| * |
There was a problem hiding this comment.
These should be turned into unit tests
| if ( StringUtils.isBlank( strForwardUrl) ) return false ; | ||
|
|
||
| if ( ( strForwardUrl.startsWith("//") || strForwardUrl.contains("://") ) | ||
| && !strForwardUrl.startsWith ( AppPathService.getBaseUrl( request ) ) ) { |
There was a problem hiding this comment.
The placement of { is not per Lutece coding style
|
|
||
| if ( StringUtils.isBlank( strForwardUrl) ) return false ; | ||
|
|
||
| if ( ( strForwardUrl.startsWith("//") || strForwardUrl.contains("://") ) |
There was a problem hiding this comment.
Per the Lutece coding style, you should put spaces around methods args
| * | ||
| * @param strForwardUrl | ||
| * @param request | ||
| * @return |
|
|
||
| if ( !SecurityUtil.containsCleanParameters( request ) ) | ||
| if ( !SecurityUtil.containsCleanParameters( request ) | ||
| || !SecurityUtil.isForwardUrlValid( strForwardUrl, request) ) |
|
done !
________________________________
De : rzara [notifications@github.com]
Envoyé : mercredi 8 août 2018 11:10
À : lutece-platform/lutece-core
Cc : Seb Leridon; Author
Objet : Re: [lutece-platform/lutece-core] Lutece 2206 (#144)
@rzara commented on this pull request.
________________________________
In src/java/fr/paris/lutece/util/http/SecurityUtil.java<#144 (comment)>:
+ * example with a base url "https://lutece.fr/ :
+ * - valid : /jsp/site/Portal.jsp , Another.jsp , https://lutece.fr/jsp/site/Portal.jsp
+ * - invalid : http://anothersite.com , https://anothersite.com , //anothersite.com , file://my.txt , ...
+ *
+ * @param strForwardUrl
+ * @param request
+ * @return
+ */
+ public static boolean isForwardUrlValid( String strForwardUrl, HttpServletRequest request )
+ {
+
+ if ( StringUtils.isBlank( strForwardUrl) ) return false ;
+
+ if ( ( strForwardUrl.startsWith("//") || strForwardUrl.contains("://") )
+ && !strForwardUrl.startsWith ( AppPathService.getBaseUrl( request ) ) ) {
+ return false;
You should log here as is done in the other methods of this class
________________________________
In src/java/fr/paris/lutece/util/http/SecurityUtil.java<#144 (comment)>:
@@ -266,6 +267,36 @@ public static String getRealIp( HttpServletRequest request )
return strIPAddress;
}
+
+ /**
+ * Validate a forward URL,
+ * the url should :
+ * - not be blank (null or empty string or spaces)
+ * - start with the base URL, or not start with "http" or "//"
+ *
+ * example with a base url "https://lutece.fr/ :
+ * - valid : /jsp/site/Portal.jsp , Another.jsp , https://lutece.fr/jsp/site/Portal.jsp
+ * - invalid : http://anothersite.com , https://anothersite.com , //anothersite.com , file://my.txt , ...
+ *
These should be turned into unit tests
________________________________
In src/java/fr/paris/lutece/util/http/SecurityUtil.java<#144 (comment)>:
+ *
+ * example with a base url "https://lutece.fr/ :
+ * - valid : /jsp/site/Portal.jsp , Another.jsp , https://lutece.fr/jsp/site/Portal.jsp
+ * - invalid : http://anothersite.com , https://anothersite.com , //anothersite.com , file://my.txt , ...
+ *
+ * @param strForwardUrl
+ * @param request
+ * @return
+ */
+ public static boolean isForwardUrlValid( String strForwardUrl, HttpServletRequest request )
+ {
+
+ if ( StringUtils.isBlank( strForwardUrl) ) return false ;
+
+ if ( ( strForwardUrl.startsWith("//") || strForwardUrl.contains("://") )
+ && !strForwardUrl.startsWith ( AppPathService.getBaseUrl( request ) ) ) {
The placement of { is not per Lutece coding style
________________________________
In src/java/fr/paris/lutece/util/http/SecurityUtil.java<#144 (comment)>:
+ * - start with the base URL, or not start with "http" or "//"
+ *
+ * example with a base url "https://lutece.fr/ :
+ * - valid : /jsp/site/Portal.jsp , Another.jsp , https://lutece.fr/jsp/site/Portal.jsp
+ * - invalid : http://anothersite.com , https://anothersite.com , //anothersite.com , file://my.txt , ...
+ *
+ * @param strForwardUrl
+ * @param request
+ * @return
+ */
+ public static boolean isForwardUrlValid( String strForwardUrl, HttpServletRequest request )
+ {
+
+ if ( StringUtils.isBlank( strForwardUrl) ) return false ;
+
+ if ( ( strForwardUrl.startsWith("//") || strForwardUrl.contains("://") )
Per the Lutece coding style, you should put spaces around methods args
________________________________
In src/java/fr/paris/lutece/util/http/SecurityUtil.java<#144 (comment)>:
@@ -266,6 +267,36 @@ public static String getRealIp( HttpServletRequest request )
return strIPAddress;
}
+
+ /**
+ * Validate a forward URL,
+ * the url should :
+ * - not be blank (null or empty string or spaces)
+ * - start with the base URL, or not start with "http" or "//"
+ *
+ * example with a base url "https://lutece.fr/ :
+ * - valid : /jsp/site/Portal.jsp , Another.jsp , https://lutece.fr/jsp/site/Portal.jsp
+ * - invalid : http://anothersite.com , https://anothersite.com , //anothersite.com , file://my.txt , ...
+ *
+ * @param strForwardUrl
+ * @param request
+ * @return
These javadoc tags are incomplete
________________________________
In src/java/fr/paris/lutece/portal/web/style/ThemesJspBean.java<#144 (comment)>:
@@ -138,7 +138,8 @@ public String doModifyUserTheme( HttpServletRequest request, HttpServletResponse
String strTheme = request.getParameter( PARAMETER_THEME );
String strForwardUrl = request.getParameter( PARAMETER_URL );
- if ( !SecurityUtil.containsCleanParameters( request ) )
+ if ( !SecurityUtil.containsCleanParameters( request )
+ || !SecurityUtil.isForwardUrlValid( strForwardUrl, request) )
Missing space after request
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub<#144 (review)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AYwWrdTqdblHF9duez2mn8euZn3Zr6fEks5uOqrtgaJpZM4VyeBT>.
|
bdf1133 to
ba3b6f4
Compare
| * @param strUrl the Url to validate | ||
| * @param request the current request (containing the baseUrl) | ||
| * @param strAntPathMatcherPatterns a comma separated list of AntPathMatcher patterns, as "http://**.lutece.com,https://**.lutece.com" | ||
| * @return true if valid |
| { | ||
|
|
||
| if ( StringUtils.isBlank( strUrl) ) return false ; | ||
| AntPathMatcher pathMatcher = new AntPathMatcher(); |
There was a problem hiding this comment.
inconsistent alignment
Plus you do not use that until the else clause. this should be moved there
| // relative path | ||
| return true ; | ||
| } | ||
| else |
There was a problem hiding this comment.
No need for else since you return in the if
| if ( !pathMatcher.matchStart( strUrl, AppPathService.getBaseUrl( request ) ) ) | ||
| return true ; | ||
|
|
||
| if ( strAntPathMatcherPatterns != null ) |
| }; | ||
|
|
||
| public static final String PROPERTY_ANTPATHMATCHER_PATTERNS = "lutece.security.antpathmatcher.patterns"; | ||
|
|
There was a problem hiding this comment.
Maybe add a commented out entry in the default propertied file, with an explanation as to what this property does, when to use it, etc.
5338579 to
c66d8fc
Compare
135e4f9 to
e399c1d
Compare
Avoid open redirect when modifying a theme