Skip to content

Commit

Permalink
#158 #159 XML 解析 XXE漏洞处理
Browse files Browse the repository at this point in the history
  • Loading branch information
liyi committed Jul 6, 2018
1 parent 3a62a16 commit 71c58bf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ WEIXIN-POPULAR CHANGELOG
===========================
https://github.com/liyiorg/weixin-popular

Changes in version 2.8.21 (2018-07-?)
Changes in version 2.8.21 (2018-07-06)
-------------------------------------
* 退款申请接口添加 refund_desc 退款原因字段
* 升级依赖emoji-java 版本到 4.0.0
* 升级依赖fastjson 版本到 1.2.47
* #156 JsUtil.generateConfigJson 规范JSON数据格式
* #157 统一下单添加H5 场景支持
* #158 #159 XML 解析 XXE漏洞处理


Changes in version 2.8.20 (2018-05-28)
-------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/qq/weixin/mp/aes/XMLParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ public static Object[] extract(String xmltext) throws AesException {
Object[] result = new Object[3];
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

/*
* 避免 XXE 攻击
* @since 2.8.21
*/
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setXIncludeAware(false);
dbf.setExpandEntityReferences(false);

DocumentBuilder db = dbf.newDocumentBuilder();
StringReader sr = new StringReader(xmltext);
InputSource is = new InputSource(sr);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/weixin/popular/util/XMLConverUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ public static Map<String,String> convertToMap(String xml){
Map<String, String> map = new LinkedHashMap<String,String>();
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

/*
* 避免 XXE 攻击
* @since 2.8.21
*/
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setXIncludeAware(false);
dbf.setExpandEntityReferences(false);

DocumentBuilder db = dbf.newDocumentBuilder();
StringReader sr = new StringReader(xml);
InputSource is = new InputSource(sr);
Expand All @@ -162,4 +171,5 @@ public static Map<String,String> convertToMap(String xml){
}
return map;
}

}

1 comment on commit 71c58bf

@jxs-xx
Copy link

@jxs-xx jxs-xx commented on 71c58bf Jul 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

要不要加满
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
dbf.setXIncludeAware(false);
dbf.setExpandEntityReferences(false);

Please sign in to comment.