当前位置:网站首页>Disable access to external entities in XML parsing
Disable access to external entities in XML parsing
2022-07-02 05:09:00 【◢◤】
- 使用SAXReader读取XML数据
SAXReader saxReader = new SAXReader();
Document userDocument = null;
try {
// 读取xml数据为Document对象
Document document = saxReader.read(new ByteArrayInputStream(xmlData.getBytes(StandardCharsets.UTF_8)));
String signatureContent = document.getRootElement().element("signatureContent").getData().toString();
// Base64解析获取数据
byte[] byteData = Base64.decode(signatureContent);
String data = new String(byteData, StandardCharsets.UTF_8);
userDocument = saxReader.read(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)));
} catch (DocumentException e) {
}
- 使用SonarLint扫描代码提示Disable access to external entities in XML parsing,提示风险禁止在XML解析中访问外部实体
// 关闭DTD解析
SAXReader saxReader = SAXReader.createDefault();
Document userDocument = null;
try {
// 读取xml数据为Document对象
Document document = saxReader.read(new ByteArrayInputStream(xmlData.getBytes(StandardCharsets.UTF_8)));
String signatureContent = document.getRootElement().element("signatureContent").getData().toString();
// Base64解析获取数据
byte[] byteData = Base64.decode(signatureContent);
String data = new String(byteData, StandardCharsets.UTF_8);
userDocument = saxReader.read(new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)));
} catch (DocumentException e) {
result.addElement("status").addText("1");
result.addElement("failReason").addText(e.getMessage());
log.error("解析xml数据失败: " + e.getMessage(), e);
}

使用SAXReader.createDefault()来生成解析器,里面设置关闭了DTO解析。
边栏推荐
- 数学知识(欧拉函数)
- 画波形图_数字IC
- 06 decorator mode
- Mapping settings in elk (8) es
- Case sharing | intelligent Western Airport
- How do I interview for a successful software testing position? If you want to get a high salary, you must see the offer
- Briefly introduce chown command
- ansible安装与使用
- Use of Baidu map
- No logic is executed after the El form is validated successfully
猜你喜欢

Fabric.js IText设置指定文字的颜色和背景色

Pyechart1.19 national air quality exhibition

Lm09 Fisher inverse transform inversion mesh strategy

Creation and destruction of function stack frames

Precipitate yourself and stay up late to sort out 100 knowledge points of interface testing professional literacy

About PROFIBUS: communication backbone network of production plant

Pycharm breakpoint management: temporarily cancel some breakpoints + run directly to a line

Analyzing the hands-on building tutorial in children's programming

C case of communication between server and client based on mqttnet

el form 表单validate成功后没有执行逻辑
随机推荐
Virtual machine installation deepin system
Ruby replaces gem Alibaba image
LM09丨费雪逆变换反转网格策略
奠定少儿编程成为基础学科的原理
The underlying principle of go map (storage and capacity expansion)
How to recover deleted data in disk
Cultivate primary and secondary school students' love for educational robots
Global and Chinese market of travel data recorder (VDR) 2022-2028: Research Report on technology, participants, trends, market size and share
创新永不止步——nVisual网络可视化平台针对Excel导入的创新历程
Application d'un robot intelligent dans le domaine de l'agroécologie
[bus interface] Axi interface
黑馬筆記---Set系列集合
Leetcode 18 problem [sum of four numbers] recursive solution
Differential identities (help find mean, variance, and other moments)
Precipitate yourself and stay up late to sort out 100 knowledge points of interface testing professional literacy
Global and Chinese market of insulin pens 2022-2028: Research Report on technology, participants, trends, market size and share
LeetCode 241. Design priorities for operational expressions (divide and conquer / mnemonic recursion / dynamic programming)
Pyflink writes MySQL examples with JDBC
Go Chan's underlying principles
Ansible installation and use