1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-24 20:06:09 +08:00

移除Throttle

This commit is contained in:
xiaochong0302 2025-05-02 07:55:38 +08:00
parent b164a6c1b1
commit 69a384ee04
9 changed files with 0 additions and 108 deletions

View File

@ -30,8 +30,6 @@ class Controller extends \Phalcon\Mvc\Controller
$this->setCors();
}
$this->checkRateLimit();
return true;
}

View File

@ -77,8 +77,6 @@ class Controller extends \Phalcon\Mvc\Controller
$this->checkCsrfToken();
}
$this->checkRateLimit();
return true;
}

View File

@ -37,8 +37,6 @@ class LayerController extends \Phalcon\Mvc\Controller
$this->checkCsrfToken();
}
$this->checkRateLimit();
return true;
}

View File

@ -121,7 +121,6 @@ class OrderConfirm extends LogicService
'lesson_count' => $course->lesson_count,
'study_expiry' => $course->study_expiry,
'refund_expiry' => $course->refund_expiry,
'origin_price' => $course->origin_price,
'market_price' => $course->market_price,
'vip_price' => $course->vip_price,
];

View File

@ -1,65 +0,0 @@
<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Services;
class Throttle extends Service
{
public function checkRateLimit()
{
$config = $this->getConfig();
if (!$config->path('throttle.enabled')) {
return true;
}
$cache = $this->getCache();
$sign = $this->getRequestSignature();
$cacheKey = $this->getCacheKey($sign);
if ($cache->ttl($cacheKey) < 1) {
$cache->save($cacheKey, 0, $config->path('throttle.lifetime'));
}
$rateLimit = $cache->get($cacheKey);
if ($rateLimit >= $config->path('throttle.rate_limit')) {
return false;
}
$cache->increment($cacheKey, 1);
return true;
}
protected function getRequestSignature()
{
$authUser = $this->getAuthUser();
if (!empty($authUser['id'])) {
return md5($authUser['id']);
}
$httpHost = $this->request->getHttpHost();
$clientAddress = $this->request->getClientAddress();
if ($httpHost && $clientAddress) {
return md5($httpHost . '|' . $clientAddress);
}
throw new \RuntimeException('Unable to generate request signature');
}
protected function getCacheKey($sign)
{
return "throttle:{$sign}";
}
}

View File

@ -28,13 +28,6 @@ trait Security
$validator->checkHttpReferer();
}
public function checkRateLimit()
{
$validator = new SecurityValidator();
$validator->checkRateLimit();
}
public function isNotSafeRequest()
{
/**

View File

@ -8,9 +8,7 @@
namespace App\Validators;
use App\Exceptions\BadRequest as BadRequestException;
use App\Exceptions\ServiceUnavailable as ServiceUnavailableException;
use App\Library\CsrfToken as CsrfTokenService;
use App\Services\Throttle as ThrottleService;
class Security extends Validator
{
@ -53,17 +51,6 @@ class Security extends Validator
}
}
public function checkRateLimit()
{
$service = new ThrottleService();
$result = $service->checkRateLimit();
if (!$result) {
throw new ServiceUnavailableException('security.too_many_requests');
}
}
protected function getCsrfWhitelist()
{
return [];

View File

@ -147,21 +147,6 @@ $config['cors']['allow_headers'] = '*';
*/
$config['cors']['allow_methods'] = ['GET', 'POST', 'OPTIONS'];
/**
* 限流开启
*/
$config['throttle']['enabled'] = true;
/**
* 有效期(秒)
*/
$config['throttle']['lifetime'] = 60;
/**
* 限流频率
*/
$config['throttle']['rate_limit'] = 60;
/**
* 客户端ping服务端间隔
*/

View File

@ -22,7 +22,6 @@ $error['sys.unknown_error'] = '未知错误';
/**
* 安全相关
*/
$error['security.too_many_requests'] = '请求过于频繁';
$error['security.invalid_csrf_token'] = '无效的CSRF令牌';
$error['security.invalid_http_referer'] = '无效请求来源';