Skip to content

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Lutece 2206 #144

wants to merge 2 commits into from

Conversation

seboo
Copy link
Contributor

@seboo seboo commented Aug 7, 2018

Avoid open redirect when modifying a theme

@seboo seboo changed the base branch from master to develop August 7, 2018 16:16

if ( ( strForwardUrl.startsWith("//") || strForwardUrl.contains("://") )
&& !strForwardUrl.startsWith ( AppPathService.getBaseUrl( request ) ) ) {
return false;
Copy link
Member

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 , ...
*
Copy link
Member

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 ) ) ) {
Copy link
Member

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("://") )
Copy link
Member

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
Copy link
Member

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) )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space after request

@seboo
Copy link
Contributor Author

seboo commented Aug 8, 2018 via email

@seboo seboo force-pushed the LUTECE-2206 branch 2 times, most recently from bdf1133 to ba3b6f4 Compare August 8, 2018 15:47
* @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
Copy link
Member

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();
Copy link
Member

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
Copy link
Member

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 )
Copy link
Member

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";

Copy link
Member

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.

@seboo seboo force-pushed the LUTECE-2206 branch 2 times, most recently from 5338579 to c66d8fc Compare August 9, 2018 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants