Skip to content
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

Hardened XStream with a converter to prevent exploitation #20

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions components/nexus-client-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@
<artifactId>nexus-test-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Copy link
Author

Choose a reason for hiding this comment

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

This library holds security APIs for hardening XStream operations.

License: MIT ✅ | Open source ✅ | No transitive dependencies ✅ | More facts

<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit-xstream</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.sonatype.nexus.client.internal.rest;

import io.github.pixee.security.xstream.HardeningConverter;
import org.sonatype.nexus.client.internal.msg.ErrorMessage;
import org.sonatype.nexus.client.internal.msg.ErrorResponse;
import org.sonatype.nexus.rest.model.XStreamConfiguratorLightweight;
Expand All @@ -34,6 +35,7 @@ public class NexusXStreamFactory
public XStream createForXml()
{
final XStream xstream = new XStream( new LookAheadXppDriver() );
xstream.registerConverter(new HardeningConverter());
xstream.setMode( XStream.NO_REFERENCES );
xstream.autodetectAnnotations( false );
return xstream;
Expand Down
4 changes: 4 additions & 0 deletions components/nexus-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@
<artifactId>sisu-pr-testutil</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Copy link
Author

Choose a reason for hiding this comment

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

This library holds security APIs for hardening XStream operations.

License: MIT ✅ | Open source ✅ | No transitive dependencies ✅ | More facts

<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit-xstream</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.sonatype.nexus.configuration.application.upgrade;

import io.github.pixee.security.xstream.HardeningConverter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
Expand Down Expand Up @@ -113,7 +114,8 @@ public Object loadConfiguration( File file )
{
// a snippet from old TaskConnfigManager
XStream xstream = new XStream( new DomDriver() );

xstream.registerConverter(new HardeningConverter());

// alias the versioned class (they are frozen to 1.0.3 only!)
xstream.alias( "org.sonatype.nexus.configuration.model.CTaskConfiguration", CTaskConfiguration.class );
xstream.alias(
Expand Down
11 changes: 9 additions & 2 deletions components/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@
<version>2.6.0-SNAPSHOT</version>
<scope>import</scope>
</dependency>

<dependency>
Copy link
Author

Choose a reason for hiding this comment

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

This library holds security APIs for hardening XStream operations.

License: MIT ✅ | Open source ✅ | No transitive dependencies ✅ | More facts

<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit-xstream</artifactId>

Copy link
Author

Choose a reason for hiding this comment

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

This library holds security APIs for hardening XStream operations.

License: MIT ✅ | Open source ✅ | No transitive dependencies ✅ | More facts

<version>${versions.java-security-toolkit-xstream}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -75,5 +80,7 @@
</plugin>
</plugins>
</build>

<properties>
<versions.java-security-toolkit-xstream>1.0.2</versions.java-security-toolkit-xstream>
</properties>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.sonatype.nexus.plugins.plugin.console.error.reporting;

import io.github.pixee.security.xstream.HardeningConverter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.List;
Expand Down Expand Up @@ -41,6 +42,7 @@ public ErrorReportBundleEntry[] getEntries()
ByteArrayOutputStream bos = new ByteArrayOutputStream();

XStream xs = new XStream();
xs.registerConverter(new HardeningConverter());
xs.alias( "PluginInfo", PluginInfo.class );
xs.toXML( l, bos );

Expand Down
4 changes: 4 additions & 0 deletions plugins/restlet1x/nexus-restlet-bridge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
<artifactId>com.noelios.restlet.ext.jetty</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Copy link
Author

Choose a reason for hiding this comment

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

This library holds security APIs for hardening XStream operations.

License: MIT ✅ | Open source ✅ | No transitive dependencies ✅ | More facts

<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit-xstream</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.sonatype.plexus.rest;

import io.github.pixee.security.xstream.HardeningConverter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
Expand Down Expand Up @@ -300,6 +301,7 @@ protected final void recreateRoot( boolean isStarted )
protected final XStream createAndConfigureXstream( HierarchicalStreamDriver driver )
{
XStream xstream = new XStream( driver );
xstream.registerConverter(new HardeningConverter());

xstream.setClassLoader( uberClassLoader );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.sonatype.nexus.rest.global;

import io.github.pixee.security.xstream.HardeningConverter;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;

Expand Down Expand Up @@ -39,6 +40,7 @@ public void unescapeHTMLInSMTPPassword()

// make sure the configuration resource configures xstream to unescape
final XStream xStream = new XStream();
xStream.registerConverter(new HardeningConverter());
testSubject.configureXStream( xStream );

final String xml = xStream.toXML( settings );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.sonatype.nexus.rest.global;

import io.github.pixee.security.xstream.HardeningConverter;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.sonatype.nexus.rest.global.SmtpSettingsValidationPlexusResource.validateEmail;
Expand Down Expand Up @@ -75,6 +76,7 @@ public void unescapeHTMLInSMTPPassword()

// make sure the configuration resource configures xstream to unescape
final XStream xStream = new XStream();
xStream.registerConverter(new HardeningConverter());
testSubject.configureXStream( xStream );

final String xml = xStream.toXML( settings );
Expand Down
7 changes: 6 additions & 1 deletion plugins/restlet1x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

<properties>
<restlet.version>1.1.6-SONATYPE-5348-V8</restlet.version>
<versions.java-security-toolkit-xstream>1.0.2</versions.java-security-toolkit-xstream>
</properties>

<modules>
Expand Down Expand Up @@ -164,7 +165,11 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
Copy link
Author

Choose a reason for hiding this comment

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

This library holds security APIs for hardening XStream operations.

License: MIT ✅ | Open source ✅ | No transitive dependencies ✅ | More facts

<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit-xstream</artifactId>
<version>${versions.java-security-toolkit-xstream}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
4 changes: 4 additions & 0 deletions testsuite/legacy-testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@
<version>${cargo.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Copy link
Author

Choose a reason for hiding this comment

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

This library holds security APIs for hardening XStream operations.

License: MIT ✅ | Open source ✅ | No transitive dependencies ✅ | More facts

<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit-xstream</artifactId>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.sonatype.nexus.testsuite.task.nexus2692;

import io.github.pixee.security.xstream.HardeningConverter;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -95,6 +96,7 @@ public void setupStorageAndAttributes()
FileOutputStream fos = null;

XStream xstream = new XStream();
xstream.registerConverter(new HardeningConverter());
xstream.alias( "file", DefaultStorageFileItem.class );
xstream.alias( "collection", DefaultStorageCollectionItem.class );
xstream.alias( "link", DefaultStorageLinkItem.class );
Expand Down
7 changes: 6 additions & 1 deletion testsuite/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
-->
<testsuite.basedir>${project.basedir}</testsuite.basedir>
<autoshard.outputDir>${settings.localRepository}/autoshard/${project.groupId}/${project.artifactId}</autoshard.outputDir>
<versions.java-security-toolkit-xstream>1.0.2</versions.java-security-toolkit-xstream>
</properties>

<modules>
Expand Down Expand Up @@ -64,7 +65,11 @@
<version>2.6.0-SNAPSHOT</version>
<scope>import</scope>
</dependency>

<dependency>
Copy link
Author

Choose a reason for hiding this comment

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

This library holds security APIs for hardening XStream operations.

License: MIT ✅ | Open source ✅ | No transitive dependencies ✅ | More facts

<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit-xstream</artifactId>
<version>${versions.java-security-toolkit-xstream}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
4 changes: 4 additions & 0 deletions testsupport/nexus-test-harness-launcher/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@
<artifactId>nexus-indexer-lucene-plugin</artifactId>
<version>${nexus.version}</version>
</dependency>
<dependency>
Copy link
Author

Choose a reason for hiding this comment

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

This library holds security APIs for hardening XStream operations.

License: MIT ✅ | Open source ✅ | No transitive dependencies ✅ | More facts

<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit-xstream</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.sonatype.nexus.test.utils;

import io.github.pixee.security.xstream.HardeningConverter;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -91,6 +92,7 @@ public void assertRoleEquals( CRole roleA, CRole roleB )
Collections.sort( roleB.getPrivileges() );

XStream xStream = new XStream();
xStream.registerConverter(new HardeningConverter());
String roleStringA = xStream.toXML( roleA );
String roleStringB = xStream.toXML( roleB );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.sonatype.nexus.test.utils;

import io.github.pixee.security.xstream.HardeningConverter;
import org.sonatype.nexus.rest.MIndexerXStreamConfigurator;
import org.sonatype.nexus.rest.model.XStreamConfigurator;
import org.sonatype.plexus.rest.xstream.json.JsonOrgHierarchicalStreamDriver;
Expand All @@ -32,6 +33,7 @@ public class XStreamFactory
public static XStream getXmlXStream()
{
XStream xmlXStream = new XStream( new LookAheadXppDriver() );
xmlXStream.registerConverter(new HardeningConverter());
initXStream( xmlXStream );

return xmlXStream;
Expand Down
10 changes: 8 additions & 2 deletions testsupport/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@
<version>2.6.0-SNAPSHOT</version>
<scope>import</scope>
</dependency>

<dependency>
Copy link
Author

Choose a reason for hiding this comment

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

This library holds security APIs for hardening XStream operations.

License: MIT ✅ | Open source ✅ | No transitive dependencies ✅ | More facts

<groupId>io.github.pixee</groupId>
<artifactId>java-security-toolkit-xstream</artifactId>
<version>${versions.java-security-toolkit-xstream}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand All @@ -61,5 +65,7 @@
</plugin>
</plugins>
</build>

<properties>
<versions.java-security-toolkit-xstream>1.0.2</versions.java-security-toolkit-xstream>
</properties>
</project>