← Java / Spring · 目次

JAVA-030 / 上級

XML 外部実体(XXE)の許可

A05:2021 Security Misconfiguration · CWE-611 XXE

なぜ問題になるのか?

file:///etc/passwd の読み取りや SSRF が発生します。

修正方法

java
DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
f.setFeature("https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html", true);
f.setFeature("https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html", false);
f.setFeature("https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html", false);
f.setXIncludeAware(false); f.setExpandEntityReferences(false);

参考資料