Authored by 梁志锋

Merge remote-tracking branch 'remotes/origin/hotfix/loophole'

  1 +<?php
  2 +/**
  3 + * AES, 128 ECB模式加密数据
  4 + */
  5 +
  6 +namespace WebPlugin;
  7 +
  8 +class Encryption {
  9 +
  10 + //密钥
  11 + private static $_secretKey = 'yoho9646abcdefgh';
  12 +
  13 + //前面补8位0
  14 + private static $_preString = '00000000';
  15 +
  16 + /**
  17 + * 加密方法
  18 + * @param string $str
  19 + * @return string
  20 + */
  21 + public static function encrypt($str){
  22 + $str = self::$_preString.$str;
  23 + //AES, 128 ECB模式加密数据
  24 + $secretKey = self::$_secretKey;
  25 + $str = trim($str);
  26 + $str = self::addPKCS7Padding($str);
  27 + $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB),MCRYPT_RAND);
  28 + $encrypt_str = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $secretKey, $str, MCRYPT_MODE_ECB, $iv);
  29 + return base64_encode($encrypt_str);
  30 + }
  31 +
  32 + /**
  33 + * 解密方法
  34 + * @param string $str
  35 + * @return string
  36 + */
  37 + public static function decrypt($str){
  38 + //AES, 128 ECB模式加密数据
  39 + $secretKey = self::$_secretKey;
  40 + $str = base64_decode($str);
  41 + $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_ECB),MCRYPT_RAND);
  42 + $encrypt_str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $secretKey, $str, MCRYPT_MODE_ECB, $iv);
  43 + $encrypt_str = trim($encrypt_str);
  44 + $encrypt_str = self::stripPKSC7Padding($encrypt_str);
  45 + $encrypt_str = ltrim($encrypt_str, self::$_preString);
  46 + return $encrypt_str;
  47 +
  48 + }
  49 +
  50 + /**
  51 + * 填充算法
  52 + * @param string $source
  53 + * @return string
  54 + */
  55 + private static function addPKCS7Padding($source){
  56 + $source = trim($source);
  57 + $block = mcrypt_get_block_size('rijndael-128', 'ecb');
  58 + $pad = $block - (strlen($source) % $block);
  59 + if ($pad <= $block) {
  60 + $char = chr($pad);
  61 + $source .= str_repeat($char, $pad);
  62 + }
  63 + return $source;
  64 + }
  65 + /**
  66 + * 移去填充算法
  67 + * @param string $source
  68 + * @return string
  69 + */
  70 + private static function stripPKSC7Padding($source){
  71 + $source = trim($source);
  72 + $char = substr($source, -1);
  73 + $num = ord($char);
  74 + if($num==62)return $source;
  75 + $source = substr($source,0,-$num);
  76 + return $source;
  77 + }
  78 +}
@@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
2 2
3 use Action\WebAction; 3 use Action\WebAction;
4 use WebPlugin\Helpers; 4 use WebPlugin\Helpers;
  5 +use WebPlugin\Encryption;
5 use Index\HomeModel; 6 use Index\HomeModel;
6 use Index\CouponModel; 7 use Index\CouponModel;
7 use LibModels\Web\Home\CouponData; 8 use LibModels\Web\Home\CouponData;
@@ -29,7 +30,7 @@ class CouponController extends WebAction @@ -29,7 +30,7 @@ class CouponController extends WebAction
29 * 领券页面控制器 30 * 领券页面控制器
30 */ 31 */
31 public function indexAction() 32 public function indexAction()
32 - { 33 + {
33 $channel = Helpers::getChannelNameByCookie(); 34 $channel = Helpers::getChannelNameByCookie();
34 //领券频道头部 35 //领券频道头部
35 $this->setWebNavHeader($channel); 36 $this->setWebNavHeader($channel);
@@ -52,6 +53,11 @@ class CouponController extends WebAction @@ -52,6 +53,11 @@ class CouponController extends WebAction
52 break; 53 break;
53 } 54 }
54 $couponId = $this->get('id', ''); 55 $couponId = $this->get('id', '');
  56 + if (empty($couponId)) {
  57 + break;
  58 + }
  59 + //解密
  60 + $couponId = Encryption::decrypt($couponId);
55 $uid = $this->getUid(); 61 $uid = $this->getUid();
56 if (!$uid) { 62 if (!$uid) {
57 $playUrl = Helpers::url('/coupon/index'); 63 $playUrl = Helpers::url('/coupon/index');
@@ -4,6 +4,7 @@ namespace Index; @@ -4,6 +4,7 @@ namespace Index;
4 4
5 use WebPlugin\Helpers; 5 use WebPlugin\Helpers;
6 use WebPlugin\Images; 6 use WebPlugin\Images;
  7 +use WebPlugin\Encryption;
7 use Index\HomeModel; 8 use Index\HomeModel;
8 use LibModels\Web\Home\CouponData; 9 use LibModels\Web\Home\CouponData;
9 10
@@ -60,7 +61,7 @@ class CouponModel @@ -60,7 +61,7 @@ class CouponModel
60 ); 61 );
61 foreach ($couponlistval['data'] as $couponskey => $couponsval) { 62 foreach ($couponlistval['data'] as $couponskey => $couponsval) {
62 $result['categories'][$i]['coupons'][$couponskey] = array( 63 $result['categories'][$i]['coupons'][$couponskey] = array(
63 - 'id' => $couponsval['couponID'], //优惠券号 64 + 'id' => Encryption::encrypt($couponsval['couponID']), //加密优惠券号
64 'img' => Images::getForceSourceUrl($couponsval['image']['src']), //优惠券图片 65 'img' => Images::getForceSourceUrl($couponsval['image']['src']), //优惠券图片
65 'url' => Helpers::getUrlSafe($couponsval['image']['url']) //去逛逛链接 66 'url' => Helpers::getUrlSafe($couponsval['image']['url']) //去逛逛链接
66 ); 67 );
@@ -12,6 +12,7 @@ use WebPlugin\Images; @@ -12,6 +12,7 @@ use WebPlugin\Images;
12 use Configs\WebCacheConfig; 12 use Configs\WebCacheConfig;
13 use Hood\Core\Security\AuthCode; 13 use Hood\Core\Security\AuthCode;
14 use WebPlugin\UdpLog; 14 use WebPlugin\UdpLog;
  15 +use WebPlugin\Encryption;
15 use Configs\ChannelConfig; 16 use Configs\ChannelConfig;
16 17
17 /** 18 /**
@@ -980,7 +981,7 @@ class CartModel @@ -980,7 +981,7 @@ class CartModel
980 $mobile = substr($mobile, 0, 3) . '****' . substr($mobile, 7); 981 $mobile = substr($mobile, 0, 3) . '****' . substr($mobile, 7);
981 982
982 $build = array(); 983 $build = array();
983 - $build['id'] = $value['address_id']; 984 + $build['id'] = Encryption::encrypt($value['address_id']);
984 $build['user'] = $value['consignee']; 985 $build['user'] = $value['consignee'];
985 $build['address'] = $value['area'] . $value['address'] . ' ' . $value['zip_code'] . ' ' . $mobile . ' ' . $value['phone']; 986 $build['address'] = $value['area'] . $value['address'] . ' ' . $value['zip_code'] . ' ' . $mobile . ' ' . $value['phone'];
986 $build['checked'] = $value['is_default'] === 'Y'; 987 $build['checked'] = $value['is_default'] === 'Y';
@@ -1095,6 +1096,10 @@ class CartModel @@ -1095,6 +1096,10 @@ class CartModel
1095 // 处理返回结果 1096 // 处理返回结果
1096 if (isset($address['code']) && $address['code'] == 200) { 1097 if (isset($address['code']) && $address['code'] == 200) {
1097 $result = $address; 1098 $result = $address;
  1099 + if ($result['data']['address_id']) {
  1100 + $result['data']['address_id'] = Encryption::encrypt($result['data']['address_id']);
  1101 + $result['data']['id'] = Encryption::encrypt($result['data']['id']);
  1102 + }
1098 } 1103 }
1099 } 1104 }
1100 1105
@@ -4,6 +4,7 @@ use Action\WebAction; @@ -4,6 +4,7 @@ use Action\WebAction;
4 use WebPlugin\Helpers; 4 use WebPlugin\Helpers;
5 use Shopping\CartModel; 5 use Shopping\CartModel;
6 use WebPlugin\UdpLog; 6 use WebPlugin\UdpLog;
  7 +use WebPlugin\Encryption;
7 8
8 /** 9 /**
9 * 购物车相关的控制器 10 * 购物车相关的控制器
@@ -269,6 +270,8 @@ class IndexController extends WebAction @@ -269,6 +270,8 @@ class IndexController extends WebAction
269 if ($this->isAjax()) { 270 if ($this->isAjax()) {
270 $uid = $this->getUid(false); 271 $uid = $this->getUid(false);
271 $addressId = $this->post('id'); 272 $addressId = $this->post('id');
  273 + //解密
  274 + $addressId = intval(Encryption::decrypt($addressId));
272 $result = CartModel::setDefaultAddress($uid, $addressId); 275 $result = CartModel::setDefaultAddress($uid, $addressId);
273 } 276 }
274 277
@@ -295,7 +298,11 @@ class IndexController extends WebAction @@ -295,7 +298,11 @@ class IndexController extends WebAction
295 298
296 if ($this->isAjax()) { 299 if ($this->isAjax()) {
297 $uid = $this->getUid(false); 300 $uid = $this->getUid(false);
298 - $id = $this->post('id', null); 301 + $id = $this->post('id', null); //TODO
  302 + if ($id) {
  303 + //解密
  304 + $id = intval(Encryption::decrypt($id));
  305 + }
299 $address = $this->post('address', ''); 306 $address = $this->post('address', '');
300 $areaCode = $this->post('areaCode', ''); 307 $areaCode = $this->post('areaCode', '');
301 $consignee = $this->post('consignee', ''); 308 $consignee = $this->post('consignee', '');
@@ -327,7 +334,8 @@ class IndexController extends WebAction @@ -327,7 +334,8 @@ class IndexController extends WebAction
327 334
328 if ($this->isAjax()) { 335 if ($this->isAjax()) {
329 $uid = $this->getUid(false); 336 $uid = $this->getUid(false);
330 - $addressId = $this->post('id'); 337 + $addressId = $this->post('id');// TODO
  338 + $addressId = intval(Encryption::decrypt($addressId));
331 $result = CartModel::delAddress($uid, $addressId); 339 $result = CartModel::delAddress($uid, $addressId);
332 } 340 }
333 341
@@ -435,7 +443,9 @@ class IndexController extends WebAction @@ -435,7 +443,9 @@ class IndexController extends WebAction
435 break; 443 break;
436 } 444 }
437 445
438 - $addressId = $this->post('addressId', null); 446 + $addressId = $this->post('addressId', null);//TODO
  447 + //解密
  448 + $addressId = intval(Encryption::decrypt($addressId));
439 $cartType = $this->post('cartType', 'ordinary'); // 默认普通购物车 449 $cartType = $this->post('cartType', 'ordinary'); // 默认普通购物车
440 $deliveryTimeId = $this->post('deliveryTimeId', 1); // 默认只工作日配送 450 $deliveryTimeId = $this->post('deliveryTimeId', 1); // 默认只工作日配送
441 $deliveryWayId = $this->post('deliveryWayId', 1); // 默认普通快递 451 $deliveryWayId = $this->post('deliveryWayId', 1); // 默认普通快递