Android Studio can't find property XMLConstants.ACCESS_EXTERNAL_DTD

若如初见. 提交于 2020-03-21 05:18:25

问题


I'm having a very similar issue to this post - Java and Xerces: can't find property XMLConstants.ACCESS_EXTERNAL_DTD - but with working on Android Studio IDE.

I'm also trying to fix the same issue about disabling XML external entity (XXE) processing that gets raised as a vulnerability in our SonarCloud analysis (see: https://sonarcloud.io/project/issues?id=org.digitalcampus.mobile.learning&open=AW3ezGnx-dJmagWAiKPH&resolved=false&types=VULNERABILITY).

As far as I can tell, I have the most recent version of Android Studio installed, along with the all recent updates for Java, my Android Studio about dialog shows this:

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

I'd really appreciate any feedback/help on how I can resolve this, so I can remove the vulnerability from my code. Just let me know if there is any other specific information (versions etc) that you may need.

Thanks in advance for you help...

Update (14/2/20)... Looks like the ACCESS_EXTERNAL_DTD constant is not available in Android - see the Android java reference docs: https://developer.android.com/reference/javax/xml/XMLConstants.html.

So would the FEATURE_SECURE_PROCESSING constant be sufficient?


回答1:


you can use the below code to solve your issue, check the XML External Entity Prevention Cheat Sheet for more details

 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();

if this was helpful, please mark this as the answer.



来源:https://stackoverflow.com/questions/60190084/android-studio-cant-find-property-xmlconstants-access-external-dtd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!