XSLT 변환 취약점 (Xslt Injection)
XML Injection (aka Blind XPath Injection)
PreviousXMLDecoder를 이용한 불안전한 역직렬화 (Insecure Deserialization using XMLDecoder)NextXML 외부 개체(XML External Entity, XXE) 취약점
Last updated
XML Injection (aka Blind XPath Injection)
Last updated
import java.io.FileInputStream;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamSource;
public class InsecureXslt {
public static void main(String[] args) throws Exception {
TransformerFactory factory = TransformerFactory.newInstance();
Source xslSource = new StreamSource(new FileInputStream(args[0])); // 사용자 입력을 기반으로 XSLT 로드
Transformer transformer = factory.newTransformer(xslSource);
Source xmlSource = new StreamSource(new FileInputStream("data.xml"));
Result result = new StreamResult(System.out);
transformer.transform(xmlSource, result);
}
}import java.io.FileInputStream;
import javax.xml.XMLConstants;
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamSource;
public class SecureXslt {
public static void main(String[] args) throws Exception {
TransformerFactory factory = TransformerFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); // 보안 기능 활성화
Source xslSource = new StreamSource(new FileInputStream("trusted.xsl")); // 안전한 XSLT 파일만 사용
Transformer transformer = factory.newTransformer(xslSource);
Source xmlSource = new StreamSource(new FileInputStream("data.xml"));
Result result = new StreamResult(System.out);
transformer.transform(xmlSource, result);
}
}