import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.maven.wagon.providers.http.HttpWagon;
import org.springframework.stereotype.Service;
+import org.springframework.util.ResourceUtils;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
return getModelMapper().map( organisationInformation, OrganisationInformation.class );
}
+ private void checkUrl(String url, String propertyName) throws RepositoryAdminException {
+ if ( StringUtils.isNotEmpty( url ) )
+ {
+ if ( !ResourceUtils.isUrl( url ) )
+ {
+ throw new RepositoryAdminException( "Bad URL in " + propertyName + ": " + url );
+ }
+ }
+
+ }
+
@Override
public void setOrganisationInformation( OrganisationInformation organisationInformation )
throws RepositoryAdminException
{
- Configuration configuration = getArchivaConfiguration().getConfiguration();
+ checkUrl(organisationInformation.getUrl(), "url");
+ checkUrl( organisationInformation.getLogoLocation(), "logoLocation" );
+ Configuration configuration = getArchivaConfiguration( ).getConfiguration( );
if ( organisationInformation != null )
{
org.apache.archiva.configuration.OrganisationInformation organisationInformationModel =
- getModelMapper().map( organisationInformation,
- org.apache.archiva.configuration.OrganisationInformation.class );
+ getModelMapper( ).map( organisationInformation,
+ org.apache.archiva.configuration.OrganisationInformation.class );
configuration.setOrganisationInfo( organisationInformationModel );
}
else
}
+ @Test
+ public void badOrganisationInfoLogoLocation( )
+ {
+ try
+ {
+ OrganisationInformation newOrganisationInformation = new OrganisationInformation( );
+ newOrganisationInformation.setLogoLocation( "'/><svg/onload=alert(/logoLocation_xss/)>" );
+ newOrganisationInformation.setName( "foo org" );
+ newOrganisationInformation.setUrl( "http://foo.com" );
+ archivaAdministration.setOrganisationInformation( newOrganisationInformation );
+ fail( "RepositoryAdminException expected. Bad URL content should not be allowed for logo location." );
+ }
+ catch ( RepositoryAdminException e )
+ {
+ // OK
+ }
+ }
+
+ @Test
+ public void badOrganisationInfoUrl( )
+ {
+ try
+ {
+ OrganisationInformation newOrganisationInformation = new OrganisationInformation( );
+ newOrganisationInformation.setUrl( "'/><svg/onload=alert(/url_xss/)>" );
+ newOrganisationInformation.setName( "foo org" );
+ newOrganisationInformation.setLogoLocation( "http://foo.com/bar.png" );
+ archivaAdministration.setOrganisationInformation( newOrganisationInformation );
+ fail( "RepositoryAdminException expected. Bad URL content should not be allowed for logo location." );
+ }
+ catch ( RepositoryAdminException e )
+ {
+ // OK
+ }
+
+ }
+
@Test
public void uiConfiguration()
throws Exception