当前位置:网站首页>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解析。
边栏推荐
- Paddlepaddle project source code
- Global and Chinese market of travel data recorder (VDR) 2022-2028: Research Report on technology, participants, trends, market size and share
- 画波形图_数字IC
- Save the CDA from the disc to the computer
- Johnson–Lindenstrauss Lemma(2)
- 数学知识——快速幂的理解及例题
- Mathematical problems (number theory) trial division to judge prime numbers, decompose prime factors, and screen prime numbers
- Latest: the list of universities and disciplines for the second round of "double first-class" construction was announced
- DMA Porter
- C # picture display occupancy problem
猜你喜欢
视差特效的原理和实现方法
Orthogonal test method and function diagram method for test case design
Pytest learning ----- pytest Interface Association framework encapsulation of interface automation testing
Virtual machine installation deepin system
黑马笔记---Set系列集合
LM09丨费雪逆变换反转网格策略
Video multiple effects production, fade in effect and border background are added at the same time
Line by line explanation of yolox source code of anchor free series network (7) -- obj in head_ loss、Cls_ Loss and reg_ Calculation and reverse transmission of loss I
黑马笔记---Map集合体系
Typescript function details
随机推荐
Implementation of go language for deleting duplicate items in sorting array
Global and Chinese market of hydrocyclone desander 2022-2028: Research Report on technology, participants, trends, market size and share
Knowledge arrangement about steam Education
Fabric.js 精简JSON
Future trend of automated testing ----- self healing technology
黑马笔记---Map集合体系
Analyzing the hands-on building tutorial in children's programming
Fasttext text text classification
7.1模擬賽總結
[common error] the DDR type of FPGA device is selected incorrectly
Express logistics quick query method, set the unsigned doc No. to refresh and query automatically
Learn BeanShell before you dare to say you know JMeter
Leetcode 18 problem [sum of four numbers] recursive solution
How to recover deleted data in disk
黑马笔记---Set系列集合
CubeMx DMA笔记
LeetCode 241. Design priorities for operational expressions (divide and conquer / mnemonic recursion / dynamic programming)
设置滚动条默认样式 谷歌浏览器
运维工作的“本手、妙手、俗手”
MMAP zero copy knowledge point notes