【问题标题】:Android Studio can't find property XMLConstants.ACCESS_EXTERNAL_DTDAndroid Studio 找不到属性 XMLConstants.ACCESS_EXTERNAL_DTD
【发布时间】:2020-05-28 02:43:56
【问题描述】:

我遇到了与这篇文章非常相似的问题 - Java and Xerces: can't find property XMLConstants.ACCESS_EXTERNAL_DTD - 但我正在使用 Android Studio IDE。

我也在尝试解决有关禁用 XML 外部实体 (XXE) 处理的相同问题,该问题在我们的 SonarCloud 分析中作为漏洞提出(请参阅:https://sonarcloud.io/project/issues?id=org.digitalcampus.mobile.learning&open=AW3ezGnx-dJmagWAiKPH&resolved=false&types=VULNERABILITY)。

据我所知,我安装了最新版本的 Android Studio,以及所有最新的 Java 更新,我的 Android Studio 的关于对话框显示如下:

Android Studio 3.5.3
Build #AI-191.8026.42.35.6010548, built on November 15, 2019
JRE: 1.8.0_202-release-1483-b49-5587405 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.15.0-76-generic

非常感谢有关如何解决此问题的任何反馈/帮助,以便我可以从我的代码中删除该漏洞。如果您可能需要任何其他特定信息(版本等),请告诉我。

提前感谢您的帮助...

更新(20 年 14 月 2 日)... 看起来 ACCESS_EXTERNAL_DTD 常量在 Android 中不可用 - 请参阅 Android java 参考文档:https://developer.android.com/reference/javax/xml/XMLConstants.html

那么 FEATURE_SECURE_PROCESSING 常量就足够了吗?

【问题讨论】:

    标签: java android xml android-studio


    【解决方案1】:

    您可以使用以下代码解决您的问题,查看XML External Entity Prevention Cheat Sheet了解更多详情

     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        String FEATURE = null;
        try {
    
            dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
            dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
            dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
            dbf.setXIncludeAware(false);
            dbf.setExpandEntityReferences(false);
    
    
        } catch (ParserConfigurationException e) {
            // This should catch a failed setFeature feature
    
    
        } catch (SAXException e) {
            // On Apache, this should be thrown when disallowing DOCTYPE
    
        } catch (IOException e) {
            // XXE that points to a file that doesn't exist
    
        }
    
    // Load XML file or stream using a XXE agnostic configured parser...
            DocumentBuilder safebuilder = dbf.newDocumentBuilder();
    

    如果有帮助,请将其标记为答案。

    【讨论】:

    • 正是我所需要的……它现在不再显示为漏洞(在我测试过的实例上)。我确实收到了 SAXException 和 IOException 没有在那个特定的 try 块中抛出的消息,所以我不需要包含这些捕获。
    猜你喜欢
    • 2019-04-17
    • 1970-01-01
    • 2017-10-28
    • 2014-02-24
    • 2018-04-12
    • 1970-01-01
    • 2018-12-30
    • 2015-04-27
    • 1970-01-01
    相关资源
    最近更新 更多