如何使用com.sun.org.apache.xerces.internal.parsers.SAXParser在SAXBuilder中禁用XML外部实体(XEE)处理

问题描述 投票:0回答:1

这是我的片段:

public static SAXBuilder createBuilder(@NotNull final String schemaPath)  {


     final SAXBuilder builder = new SAXBuilder("com.sun.org.apache.xerces.internal.parsers.SAXParser", true);
    builder.setFeature("http://apache.org/xml/features/validation/schema", true);
    builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);


    builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl",true);
    builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
    builder.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
    builder.setExpandEntities(false);
    builder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", schemaPath);
    builder.setEntityResolver(getEntityResolver());
    return builder;
}

我花了一些时间搜索,但没有太多遗漏

java xml xml-parsing sax owasp
1个回答
1
投票

我找出了这个问题的根本原因。这是因为我的xsd中的processContents="lax"属性

© www.soinside.com 2019 - 2024. All rights reserved.