Skip to content

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


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

};

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