Play Framework 安全公告

XML 外部實體

日期

2013 年 9 月 11 日

說明

在 Play 的 XML 處理中發現了一個漏洞。

攻擊者可能會利用 XML 外部實體從檔案系統、內部網路讀取檔案,或對應用程式執行 DoS 攻擊。

影響

任何使用預設的任何內容剖析器,或特別是 XML 剖析器的應用程式都可能存在漏洞。

受影響的版本

解決方法

將 JDK 使用的預設 SAXParserFactory 實作變更為停用外部實體的實作。

例如,如果使用 Oracle JDK,請將下列類別新增至您的應用程式

package xml;

import org.xml.sax.*;
import javax.xml.parsers.*;

public class SecureSAXParserFactory extends SAXParserFactory {
    private final SAXParserFactory platformDefault = new com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl();

    public SecureSAXParserFactory() throws SAXNotSupportedException, SAXNotRecognizedException, ParserConfigurationException {
        platformDefault.setFeature("http://xml.org/sax/features/external-general-entities", false);
        platformDefault.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
    }

    public SAXParser newSAXParser() throws ParserConfigurationException, SAXException {
        return platformDefault.newSAXParser();
    }

    public void setFeature(String name, boolean value) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException {
        platformDefault.setFeature(name, value);
    }

    public boolean getFeature(String name) throws ParserConfigurationException, SAXNotRecognizedException, SAXNotSupportedException {
        return platformDefault.getFeature(name);
    }
}

然後在生產模式中啟動應用程式時,將下列系統屬性新增至命令列引數

-Djavax.xml.parsers.SAXParserFactory=xml.SecureSAXParserFactory

修正

升級至下列適當版本

CVSS 指標 (更多資訊)

致謝

發現此漏洞的功勞歸功於澳洲郵政數位信箱安全團隊。