Skip to content

Commit 53fa83a

Browse files
committed
修复微信官方发布的XML外部实体注入漏洞
1 parent ccd6533 commit 53fa83a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Wechat/Lib/Tools.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ static private function _data_to_xml($data, $item = 'item', $id = 'id', $content
137137
*/
138138
static public function xml2arr($xml)
139139
{
140-
return json_decode(Tools::json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
140+
$disableEntities = libxml_disable_entity_loader(true);
141+
$result = json_decode(Tools::json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
142+
libxml_disable_entity_loader($disableEntities);
143+
return $result;
141144
}
142145

143146
/**

Wechat/WechatPay.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ public function createMicroPay($auth_code, $out_trade_no, $total_fee, $body, $go
208208
*/
209209
public function getNotify()
210210
{
211+
$disableEntities = libxml_disable_entity_loader(true);
211212
$notifyInfo = (array)simplexml_load_string(file_get_contents("php://input"), 'SimpleXMLElement', LIBXML_NOCDATA);
213+
libxml_disable_entity_loader($disableEntities);
212214
if (empty($notifyInfo)) {
213215
Tools::log('Payment notification forbidden access.', "ERR - {$this->appid}");
214216
$this->errCode = '404';

0 commit comments

Comments
 (0)