📋 전자금융기반시설 보안 취약점 평가기준 WEB-SER-015
기업뱅킹 API 시스템
B2B 기업고객 대량이체 서비스
// ❌ 취약한 XML Parser
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
// External Entity 활성화 (기본)
DocumentBuilder builder =
factory.newDocumentBuilder();
Document doc = builder.parse(
new InputSource(
new StringReader(xmlInput)
)
);
// 문제: XXE 공격 취약!
대기 중...
// ✅ 안전한 XML Parser 설정
DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
// 1. DOCTYPE 선언 차단
factory.setFeature(
"http://apache.org/xml/features/" +
"disallow-doctype-decl", true);
// 2. External Entities 비활성화
factory.setFeature(
"http://xml.org/sax/features/" +
"external-general-entities", false);
factory.setFeature(
"http://xml.org/sax/features/" +
"external-parameter-entities", false);
// 3. XInclude 비활성화
factory.setXIncludeAware(false);
// 4. Expand Entity 비활성화
factory.setExpandEntityReferences(false);
// 입력값 검증
if (xmlInput.contains("<!DOCTYPE") ||
xmlInput.contains("<!ENTITY")) {
throw new SecurityException(
"DOCTYPE/ENTITY not allowed");
}
DocumentBuilder builder =
factory.newDocumentBuilder();
Document doc = builder.parse(
new InputSource(
new StringReader(xmlInput)
)
);