XML 外部實體
日期
2013 年 9 月 20 日
說明
在 Play 的 XML 處理中發現一個漏洞。
攻擊者可能會使用 XML 外部實體從檔案系統、內部網路讀取檔案,或對應用程式執行 DoS 攻擊。
影響
使用預設的任何內容剖析器,或特別使用 XML 剖析器的任何應用程式都可能存在漏洞。
受影響版本
- Play 2.1.0 - 2.1.4
- Play 2.0 - 2.0.7
解決方法
變更 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://xml.org/sax/features/external-parameter-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 指標 (更多資訊)
- 基本:6.4
AV:N/AC:L/Au:N/C:P/I:N/A:P - 時間:5.0
E:POC/RL:OF/RC:C - 環境:5.6
CDP:ND/TD:H/CR:H/IR:H/AR:ND
環境評分假設為典型網路系統。您組織的實際環境評分可能有所不同。
致謝
發現此漏洞的功勞歸功於澳洲郵政數位信箱安全團隊和 http://www.ubercomp.com/ 的 Reginaldo Silva。