当前位置:网站首页>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解析。
边栏推荐
- Use of typescript classes
- Fabric.js 精简JSON
- Mathematical knowledge (Euler function)
- The reason why sizeof (ARR) / sizeof (arr[0]) is used in the function to calculate the length of the array is incorrect
- Lay the foundation for children's programming to become a basic discipline
- Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
- 06 装饰(Decorator)模式
- ansible安装与使用
- Briefly introduce chown command
- 7.1模擬賽總結
猜你喜欢

DMA Porter

数学知识——快速幂的理解及例题

Go Chan's underlying principles

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

Record my pytorch installation process and errors

Ansible installation and use

Hcip day 17

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

数学知识(欧拉函数)

Pyechats 1.19 generate a web version of Baidu map
随机推荐
Mathematical knowledge -- understanding and examples of fast power
Global and Chinese market of cell culture freezers 2022-2028: Research Report on technology, participants, trends, market size and share
Fabric.js IText 手动设置斜体
删除排序数组中的重复项go语言实现
Briefly introduce chown command
Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
设置滚动条默认样式 谷歌浏览器
奠定少儿编程成为基础学科的原理
Find the subscript with and as the target from the array
Fabric.js 精简JSON
Dark horse notes -- map set system
Fabric.js 背景不受视口变换影响
Getting started with pytest -- description of fixture parameters
Precipitate yourself and stay up late to sort out 100 knowledge points of interface testing professional literacy
Pyechart1.19 national air quality exhibition
Rhcsa --- work on the fourth day
fastText文本分类
No logic is executed after the El form is validated successfully
農業生態領域智能機器人的應用
el-cascader回显只选中不显示的问题