Package: com.atlassian.security.serialblocklist.xstream
Description: A hardened XStream implementation that enforces Atlassian's serialization blocklist to prevent deserialization attacks.
Inheritance: BlocklistRestrictedXStream extends XStream
1 2public BlocklistRestrictedXStream()
Creates a new BlocklistRestrictedXStream instance in allowlist mode (default). Only explicitly allowed types can be processed.
1 2public BlocklistRestrictedXStream(ReflectionProvider reflectionProvider)
Creates a new instance with a custom reflection provider.
Parameters:
reflectionProvider - Custom reflection provider for object instantiation1 2public BlocklistRestrictedXStream(HierarchicalStreamDriver hierarchicalStreamDriver)
Creates a new instance with a custom stream driver.
Parameters:
hierarchicalStreamDriver - Custom driver for reading/writing hierarchical streams1 2public BlocklistRestrictedXStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver)
Creates a new instance with custom reflection provider and stream driver.
1 2public BlocklistRestrictedXStream(ReflectionProvider reflectionProvider, Mapper mapper, HierarchicalStreamDriver hierarchicalStreamDriver)
Creates a new instance with custom reflection provider, mapper, and stream driver.
1 2public BlocklistRestrictedXStream(ReflectionProvider reflectionProvider, HierarchicalStreamDriver hierarchicalStreamDriver, ClassLoaderReference classLoaderReference)
Creates a new instance with custom reflection provider, stream driver, and class loader reference.
1 2public void addPermission(TypePermission permission)
Adds a type permission. Use AnyTypePermission.ANY to enable blocklist mode.
Parameters:
permission - The permission to addExample:
1 2// Enable blocklist mode xstream.addPermission(AnyTypePermission.ANY);
1 2public void allowTypes(Class<?>[] types)
Explicitly allows the specified types for serialization/deserialization.
Parameters:
types - Array of classes to allowThrows:
IllegalArgumentException - If any type is on the security blocklistExample:
1 2xstream.allowTypes(new Class<?>[] { UserProfile.class, Config.class });
1 2public void allowTypes(String[] typeNames)
Allows types by their class names. Unknown classes are ignored, but blocklisted classes will cause an exception.
Parameters:
typeNames - Array of fully qualified class namesThrows:
IllegalArgumentException - If any resolvable type is on the security blocklist1 2public void allowTypeHierarchy(Class<?> type)
Allows a type and all its subtypes/implementations.
Parameters:
type - The base type to allow (including subtypes)Throws:
IllegalArgumentException - If the type is on the security blocklistExample:
1 2xstream.allowTypeHierarchy(Collection.class); // Allows List, Set, etc.
The following XStream methods are intentionally blocked for security:
1 2public void allowTypesByWildcard(String[] patterns)
Status: ❌ BLOCKED - Throws UnsupportedOperationException
1 2public void allowTypesByRegExp(String[] regexps)
Status: ❌ BLOCKED - Throws UnsupportedOperationException
1 2public void allowTypesByRegExp(Pattern[] regexps)
Status: ❌ BLOCKED - Throws UnsupportedOperationException
1 2public void registerConverter(Converter converter, int priority)
Registers a converter with the specified priority.
Parameters:
converter - The converter to registerpriority - Priority level (must be < blocklist converter priority)Throws:
IllegalArgumentException - If priority >= blocklist converter priority1 2public void registerLocalConverter(Class<?> definedIn, String fieldName, Converter converter)
Registers a field-specific converter. The converter is automatically wrapped with blocklist checking.
Parameters:
definedIn - The class containing the fieldfieldName - The field nameconverter - The converter for the field1 2// Allowlist mode (recommended) XStream xstream = new BlocklistRestrictedXStream(); xstream.allowTypes(new Class<?>[] { MyClass.class }); // Blocklist mode (migration) XStream xstream = new BlocklistRestrictedXStream(); xstream.addPermission(AnyTypePermission.ANY);
1 2// Custom driver with security XStream xstream = new BlocklistRestrictedXStream(new DomDriver()); xstream.allowTypeHierarchy(Collection.class); // Custom converter registration xstream.registerConverter(new MyConverter(), XStream.PRIORITY_NORMAL); // Local field converter (automatically wrapped) xstream.registerLocalConverter(MyClass.class, "field", new MyFieldConverter());
1 2try { /// setting up xstream and xml input Object result = xstream.fromXML(xml); } catch (ForbiddenClassException e) { // Blocklisted class encountered logger.warn("Security violation: {}", e.getMessage()); } catch (IllegalArgumentException e) { // Configuration error logger.error("Configuration error: {}", e.getMessage()); }
Rate this page: