From 2ade46ab20f8fbc7d636cb520fc1af7094e633c8 Mon Sep 17 00:00:00 2001 From: Martin Stockhammer Date: Sun, 10 Mar 2019 11:36:06 +0100 Subject: [PATCH] [MRM-1972] Adding additional encoding for name value (cherry picked from commit 8e5fdd4536421a1a3f0cc5b70725148eeb27b652) --- .../admin/DefaultArchivaAdministration.java | 7 +++++++ .../admin/ArchivaAdministrationTest.java | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java index e04180c53..0c8a682a6 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/main/java/org/apache/archiva/admin/repository/admin/DefaultArchivaAdministration.java @@ -31,6 +31,8 @@ import org.apache.archiva.configuration.Configuration; import org.apache.archiva.configuration.UserInterfaceOptions; import org.apache.archiva.configuration.WebappConfiguration; import org.apache.archiva.metadata.model.facets.AuditEvent; +import org.apache.commons.codec.net.URLCodec; +import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.maven.wagon.providers.http.HttpWagon; @@ -336,6 +338,10 @@ public class DefaultArchivaAdministration } + private String convertName(String name) { + return StringEscapeUtils.escapeHtml( StringUtils.trimToEmpty( name ) ); + } + @Override public void setOrganisationInformation( OrganisationInformation organisationInformation ) throws RepositoryAdminException @@ -345,6 +351,7 @@ public class DefaultArchivaAdministration Configuration configuration = getArchivaConfiguration( ).getConfiguration( ); if ( organisationInformation != null ) { + organisationInformation.setName( convertName( organisationInformation.getName() )); org.apache.archiva.configuration.OrganisationInformation organisationInformationModel = getModelMapper( ).map( organisationInformation, org.apache.archiva.configuration.OrganisationInformation.class ); diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java index 6e3fbd671..9bb9ed443 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/repository/admin/ArchivaAdministrationTest.java @@ -253,6 +253,23 @@ public class ArchivaAdministrationTest } + @Test + public void badOrganisationName( ) + { + try + { + OrganisationInformation newOrganisationInformation = new OrganisationInformation( ); + newOrganisationInformation.setName( "/>Test Org\"" ); + archivaAdministration.setOrganisationInformation( newOrganisationInformation ); + assertEquals("/><svg/onload=alert(/url_xss/)>Test Org"", archivaAdministration.getOrganisationInformation().getName()); + } + catch ( RepositoryAdminException e ) + { + // OK + } + + } + @Test public void uiConfiguration() throws Exception -- 2.39.5