XML 외부 항목 삽입 (XXE)
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
OWASP 카테고리: MASVS-CODE: 코드 품질
개요
XML 외부 항목 삽입 (XXE)은 XML 입력을 파싱하는 애플리케이션에 대한 공격입니다. XXE 공격은 외부 항목 참조가 포함된 신뢰할 수 없는 XML 입력이 약하게 구성된 XML 파서에 의해 처리될 때 발생합니다. 이 공격은 서비스 거부, 파일 시스템 액세스, 데이터 유출을 비롯한 여러 사고를 조정하는 데 사용할 수 있습니다.
영향
애플리케이션은 XML 문서를 파싱할 때 문서에 포함된 모든 DTD (문서 유형 정의, 외부 항목이라고도 함)를 처리할 수 있습니다. 공격자는 악성 코드를 DTD로 삽입하여 이 동작을 악용할 수 있습니다. 그러면 이 코드는 애플리케이션에서만 액세스할 수 있고 민감한 데이터가 포함될 수 있는 기기의 파일 시스템 부분에 액세스할 수 있습니다.
또한 이 악성 코드는 기기에서 요청을 실행하여 경계 보안 조치를 우회할 수 있습니다.
마지막으로 애플리케이션이 DTD를 확장하면 참조된 항목이 여러 번 반복되는 상황이 발생하여 기기의 리소스가 소진되고 서비스 거부가 발생할 수 있습니다.
완화 조치
DTD 사용 중지
XXE를 방지하는 가장 안전한 방법은 항상 DTD (외부 항목)를 완전히 사용 중지하는 것입니다. 사용 중인 파서에 따라 메서드는 XML 풀 파서 라이브러리의 다음 예와 유사할 수 있습니다.
자바
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
Kotlin
val factory = XmlPullParserFactory.newInstance()
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true)
DTD를 사용 중지하면 서비스 거부 공격으로부터 파서를 보호할 수도 있습니다.
DTD를 완전히 사용 중지할 수 없다면 외부 항목 및 외부 문서 유형 선언을 각 파서에 고유한 방식으로 사용 중지해야 합니다.
시장에 나와 있는 XML 파싱 엔진이 많기 때문에 XXE 공격을 방지하는 방법은 엔진마다 다릅니다. 자세한 내용은 엔진 문서를 참고하세요.
사용자가 XML 문서의 선언부에 임의의 코드를 삽입할 수 없도록 애플리케이션을 재구성해야 합니다. 클라이언트 측 제어는 우회될 수 있으므로 서버 측에서 확인해야 합니다.
다른 라이브러리 사용
사용되는 라이브러리 또는 메서드를 안전하게 구성할 수 없는 경우 다른 라이브러리 또는 메서드를 고려해야 합니다. XML 풀 파서와 SAX 파서는 모두 DTD 및 항목을 허용하지 않는 안전한 방식으로 구성할 수 있습니다.
리소스
이 페이지에 나와 있는 콘텐츠와 코드 샘플에는 콘텐츠 라이선스에서 설명하는 라이선스가 적용됩니다. 자바 및 OpenJDK는 Oracle 및 Oracle 계열사의 상표 또는 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-07-26(UTC)"],[],[],null,["# XML External Entities Injections (XXE)\n\n\u003cbr /\u003e\n\n**OWASP category:** [MASVS-CODE: Code Quality](https://mas.owasp.org/MASVS/10-MASVS-CODE)\n\nOverview\n--------\n\nAn XML eXternal Entity injection (XXE) is an attack against applications that\nparse XML input. An XXE attack occurs when untrusted XML input with a reference\nto an external entity is processed by a weakly configured XML parser. This\nattack can be used to stage multiple incidents, including denial of service,\nfile system access, or data exfiltration.\n\nImpact\n------\n\nWhen an application parses an XML document, it can process any DTDs (Document\nType Definitions, also known as external entities) contained within the\ndocument. An attacker can exploit this behavior by injecting malicious code as\nDTDs. This code can then access parts of the file system of the device, only\naccessible to the application and potentially containing sensitive data.\nFurthermore, this malicious code can make requests from the device, potentially\nbypassing perimeter security measures.\n\nLastly, if the application expands DTDs,\nthis can create a situation with multiple iterations of referenced entities,\nexhausting the resources of the device and leading to a denial of service.\n\nMitigations\n-----------\n\n### Disable DTDs\n\nThe safest way to prevent XXE is to always disable DTDs (external entities)\ncompletely. Depending on the parser in use, the method could be similar to the\nfollowing example for the XML Pull Parser library: \n\n### Java\n\n XmlPullParserFactory factory = XmlPullParserFactory.newInstance();\n factory.setFeature(\"http://apache.org/xml/features/disallow-doctype-decl\", true);\n\n### Kotlin\n\n val factory = XmlPullParserFactory.newInstance()\n factory.setFeature(\"http://apache.org/xml/features/disallow-doctype-decl\", true)\n\nDisabling DTDs also makes the parser secure against denial of service attacks.\nIf it is not possible to disable DTDs completely, then external entities and\nexternal document type declarations must be disabled in a way that's specific to\neach parser.\n\nBecause of the large number of XML parsing engines in the market, the ways to\nprevent XXE attacks differ from engine to engine. You may need to refer to your\nengine documentation for more information.\n\n### Perform input sanitisation\n\nThe application should be reconfigured so that it does not allow users to inject\narbitrary code in the XML document's preamble. This has to be verified\nserver-side, as client-side controls can be bypassed.\n\n### Use a different library\n\nIf the library or method used cannot be configured in a secure manner, a\ndifferent one should be considered. [XML Pull Parser](/reference/org/xmlpull/v1/XmlPullParser) and [SAX Parser](/reference/javax/xml/parsers/SAXParser) can\nboth be configured in a secure manner, disallowing DTDs and entities.\n\nResources\n---------\n\n- [OWASP XXE](https://owasp.org/www-community/vulnerabilities/XML_External_Entity_(XXE)_Processing)\n- [OWASP XXE Prevention Cheat sheet](https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html)\n- [XML Constants: FEATURE_SECURE_PROCESSING](/reference/javax/xml/XMLConstants#FEATURE_SECURE_PROCESSING)\n- [XML Pull Parser](/reference/org/xmlpull/v1/XmlPullParser)\n- [SAX Parser](/reference/javax/xml/parsers/SAXParser)"]]