-
Notifications
You must be signed in to change notification settings - Fork 61
Lutece 2206 #144
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
base: develop
Are you sure you want to change the base?
Lutece 2206 #144
Conversation
|
||
if ( ( strForwardUrl.startsWith("//") || strForwardUrl.contains("://") ) | ||
&& !strForwardUrl.startsWith ( AppPathService.getBaseUrl( request ) ) ) { | ||
return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the Lutece coding style, you should put spaces around methods args
* | ||
* @param strForwardUrl | ||
* @param request | ||
* @return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These javadoc tags are incomplete
@@ -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) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When and why should I use that ?
{ | ||
|
||
if ( StringUtils.isBlank( strUrl) ) return false ; | ||
AntPathMatcher pathMatcher = new AntPathMatcher(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for else
since you return in the if
if ( !pathMatcher.matchStart( strUrl, AppPathService.getBaseUrl( request ) ) ) | ||
return true ; | ||
|
||
if ( strAntPathMatcherPatterns != null ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not covered by tests
private static final String [ ] XXE_TERMS = { | ||
"!DOCTYPE", "!ELEMENT", "!ENTITY" | ||
}; | ||
private static final String [ ] PATH_MANIPULATION = { | ||
"..", "/", "\\" | ||
}; | ||
|
||
public static final String PROPERTY_ANTPATHMATCHER_PATTERNS = "lutece.security.antpathmatcher.patterns"; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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