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("https://apache.dokyumento.jp/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 メtrique (詳細

謝辞

この脆弱性を見つけた功績は、Australia Post Digital Mailbox Security Team にあります。