Headline
CVE-2023-41034: Make DDFFileParser and DefaultDDFFileValidator safer. · eclipse-leshan/leshan@4d3e63a
Eclipse Leshan is a device management server and client Java implementation. In affected versions DDFFileParserand
DefaultDDFFileValidator(and so
ObjectLoader) are vulnerable to
XXE Attacks`. A DDF file is a LWM2M format used to store LWM2M object description. Leshan users are impacted only if they parse untrusted DDF files (e.g. if they let external users provide their own model), in that case they MUST upgrade to fixed version. If you parse only trusted DDF file and validate only with trusted xml schema, upgrading is not mandatory. This issue has been fixed in versions 1.5.0 and 2.0.0-M13. Users are advised to upgrade. There are no known workarounds for this vulnerability.
Expand Up @@ -28,6 +28,8 @@
import org.w3c.dom.Node; import org.xml.sax.SAXException; import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException;
/** * A DDF File Validator. Expand All @@ -39,6 +41,8 @@
public class DefaultDDFFileValidator implements DDFFileValidator { private static String LWM2M_V1_SCHEMA_PATH = "/schemas/LWM2M.xsd"; private static final String ACCESS_EXTERNAL_DTD = "http://javax.xml.XMLConstants/property/accessExternalDTD"; private static final String ACCESS_EXTERNAL_SCHEMA = "http://javax.xml.XMLConstants/property/accessExternalSchema";
@Override public void validate(Node xmlToValidate) throws InvalidDDFFileException { Expand Down Expand Up @@ -69,7 +73,30 @@ public void validate(Source xmlToValidate) throws SAXException, IOException { protected Schema getEmbeddedLwM2mSchema() throws SAXException { InputStream inputStream = DDFFileValidator.class.getResourceAsStream(LWM2M_V1_SCHEMA_PATH); Source source = new StreamSource(inputStream); SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); SchemaFactory schemaFactory = createSchemaFactory(); return schemaFactory.newSchema(source); }
protected SchemaFactory createSchemaFactory() { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); try { // Create Safe SchemaFactory (not vulnerable to XXE Attacks) // -------------------------------------------------------- // There is several recommendation from different source we try to apply all, even if some are maybe // redundant.
// from : // https://semgrep.dev/docs/cheat-sheets/java-xxe/ factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
// from : // https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html#schemafactory factory.setProperty(ACCESS_EXTERNAL_DTD, “”); factory.setProperty(ACCESS_EXTERNAL_SCHEMA, “”);
} catch (SAXNotRecognizedException | SAXNotSupportedException e) { throw new IllegalStateException("Unable to create SchemaFactory", e); } return factory; } }
Related news
### Impact `DDFFileParser` and `DefaultDDFFileValidator` (and so `ObjectLoader`) are vulnerable to [XXE Attacks](https://owasp.org/www-community/vulnerabilities/XML_External_Entity_(XXE)_Processing). [DDF file](https://github.com/eclipse-leshan/leshan/wiki/Adding-new-objects#the-lwm2m-model) is a LWM2M format used to store LWM2M object description. Leshan users are impacted only if they parse untrusted DDF files (e.g. if they let external users provide their own model), in that case they MUST upgrade to fixed version. If you parse only trusted DDF file and validate only with trusted xml schema, upgrading is not mandatory. ### Patches This is fixed in **v1.5.0** and **2.0.0-M13**. ### Workarounds No easy way. Eventually writing your own `DDFFileParser`/`DefaultDDFFileValidator` (and so `ObjectLoader`) creating a `DocumentBuilderFactory` with : ```java // For DDFFileParser DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setFeature(XMLConstants.FEATU...