Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5974705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:58:47+00:00 2026-05-22T20:58:47+00:00

Can I safely use XStream to process XML coming from outside of my system

  • 0

Can I safely use XStream to process XML coming from outside of my system ?
What’s the best practice when dealing with “potentially malicious XML” using xstream ?

Let’s say, I have a class somewhere in my code like this :

 package hazard;
 class Dangerous {
    public Dangerous() {
       AtomicBomb.getInstance().nuke();
    }
 }

A malicious user, might submit a XML file such as :

 <hazard.Dangerous/>

and make XStream calls the nuke() method.

This example is quite theoretical. As was pointed out, I do not expect constructor to do this kind of things. But can I be certain that no constructor in any lib available in the classpath is free from such issues (for example, allocate some ressource like a file descriptor).

The point is that sending a XML file allows an attacker to create arbitrary objects. A more realistic approach might be using some class instead of another one.

public class Foo<T implements Bar> {
    private T t;
    // Getters/setters ...
}

public interface Bar {
   public void bar();
}

public class Bar1 implements Bar {
   // ...
}

public class Bar2 implements Bar {
   // ...
}

With the (malicious) XML input :

<foo>
  <!-- I expect bar1 -->
  <package.Bar2/>
</foo>

Now with the Java code :

Bar<Foo1> bar = (Bar<Foo1>) xstream.fromXML(xml);
// I expect to have a bar1 but I have a bar2.
bar.getT().foo();

At first glance, the solution is to provide a custom Mapper (the job being done in the realClass() method).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:58:47+00:00Added an answer on May 22, 2026 at 8:58 pm

    Never ever allow xstream (or any other serialization framework) to marshal anything but clean, pure javabeans (getters and setters).

    UPDATE:
    Your mentioned theory about using a Mapper should work, although it will require some amount of scaffolding and custom config being built by you. Another way is to use the feature of XStream to specify a dedicated classloader for resolving classes. What you would try is to put all classes that SHOULD be allowed to be marshalled by xstream in a separate JAR (think of it as a domain module). Then create a clean classloader that only loads that JAR and assign it to xstream. That way, xstream will not know of any classes outside of it’s scope, failing to deserialize anything you don’t want it to.

    Try something like

    ClassLoader bootstrapClassLoader = ClassLoader.getSystemClassLoader().getParent();
    List urls = new ArrayList();
    urls.add(new File("yourJarOfXstreamBeanClasses.jar").toURL());
    ClassLoader xstreamClassLoader = new URLClassLoader(urls.toArray(new URL[0]), bootstrapClassLoader);
    XStream xstream = new XStream();
    xstream.setClassLoader(xstreamClassLoader);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can see there are many ways to use jQuery safely in the javascript
As per title, can an ActorContext extracted from within an actor be safely used
Can I safely use DateTime as a key in a SortedDictionary<K, V> without implementing
In which part of the Global.asax lifecycle can I safely 'use' the User object?
I need to know if i can safely use normal string or I have
Can i safely use code like fprintf(nullptr, str); or smth like std::ofstream() << str;
First off, I know the best-practice is to use a single database user account
Can I safely rename an aif file to caf and use that with Core
I've read in several places that a C struct can safely be defined multiple
Just to be sure it can be safely used with JQuery scripting.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.