Skip to content

Commit

Permalink
TRUNK-6188: Add whitelisting for components loaded via XStream
Browse files Browse the repository at this point in the history
  • Loading branch information
dkayiwa committed Nov 22, 2024
1 parent 6db57c4 commit c88eb0e
Showing 1 changed file with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,42 @@ public Object unmarshal(HierarchicalStreamReader reader, Object root) {
xstream.registerConverter(new IndicatorConverter(mapper, converterLookup));

xstream.registerConverter(new ReportDefinitionConverter(mapper, converterLookup));

setupXStreamSecurity(xstream);
}

private void setupXStreamSecurity(XStream xstream) throws SerializationException {

if (!isPlatformTwoPointSevenOrAbove()) {
return;
}


try {
SimpleXStreamSerializer serializer = Context.getRegisteredComponent("simpleXStreamSerializer", SimpleXStreamSerializer.class);
if (serializer != null) {
try {
Method method = serializer.getClass().getMethod("initXStream", XStream.class);
method.invoke(serializer, xstream);
}
catch (Exception ex) {
throw new SerializationException("Failed to set up XStream Security", ex);
}
}
}
catch (APIException ex) {
//Ignore APIException("Error during getting registered component) for platform versions below 2.7.0
}
}

private boolean isPlatformTwoPointSevenOrAbove() {
try {
Class.forName("org.openmrs.ConceptReferenceRange");
return true;
}
catch (ClassNotFoundException exception) {
return false;
}
}

@Override
Expand Down

0 comments on commit c88eb0e

Please sign in to comment.