when throttling is active, in addition to front-end pages, ACT requests returning json packets are also throttled.

未關閉
#5,190 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
3/5
預估耗時
1-2 天
新手友好度
50/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
php
領域
backend

研究方向

Start by reading the throttling guard around line 340 of system/ee/libraries/Core.php, which currently excludes REQ == 'CP', and the banish() method in system/ee/libraries/Throttling.php that builds the current plain-text/404/redirect response. Reproduce with a low max_page_loads/time_interval pair, then hit an ACT endpoint with X-Requested-With: XMLHttpRequest to see the non-JSON body. Decide between the two proposed fixes on the thread — the simpler REQ == 'ACTION' && AJAX_REQUEST exclusion in Core.php, or a JSON 429 response in banish() — and verify AJAX-driven control panel elements no longer break; done means an AJAX ACT call gets a usable response instead of plain text.

由索引模型根據 Issue 內容生成。

描述

Description of the problem
ExpressionEngine throttling currently applies to ACT requests and appears to return responses intended for normal page requests (plain text/redirect/404), even when the request is AJAX and expects JSON.

This causes AJAX driven elements in CP pages to fail when throttling is triggered.

This in turn causes problems for some add-ons (e.g. JCOGS Image Pro) that use ACT based AJAX requests to generate dynamic parts of some control panel pages.

A better response would be either for throttling to return an API-safe response to AJAX/JSON-accepting requests, or to simply allow ACT based AJAX requests to run.

How To Reproduce
Steps to reproduce the behaviour:

  1. Enable throttling in EE settings.
  2. Configure low values (example):
    • max_page_loads = 2
    • time_interval = 5
    • lockout_time = 30
  3. Call an ACT endpoint repeatedly using AJAX (X-Requested-With: XMLHttpRequest) expecting JSON.
  4. Observe that after threshold is exceeded, response body is plain text/404/redirect style rather than JSON.

Error Messages
Plaintext:"You have exceeded the allowed page load frequency."

Environment Details:

  • Version: 7.5.21
  • PHP Version 8.2.30.

Possible Solution
It appears that the throttling code makes no attempt to identify AJAX requests.

  • One solution would be to modify the banish() method in system/ee/libraries/Throttling.php to include a check to see if call being processed is both an ACT request (REQ='ACTION') and an AJAX request (AJAX_REQEST defined) and use this to generate a fourth type of output with appropriate HTTP headers and message body ... for example:
    • HTTP 429 Too Many Requests
    • Content-Type: application/json; charset=utf-8
    • JSON body with a stable error shape such as:
{
  "status": "error",
  "error": "Request throttled. Please try again later.",
  "error_code": "throttled"
} 
  • A second (better, and easier) solution would be to exclude AJAX based ACT from throttling - along lines of current exclusion of CP activities by changing the conditional on line 340 of system/ee/libraries/Core.php to include REQ='ACTION' and AJAX_REQEST - e.g. if (REQ != 'CP' && ! (REQ == 'ACTION' && AJAX_REQUEST)) {
主要語言
PHP
星號
505
分支
135
平均合併
3 天 7 小時
30 天內合併 PR
7

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

ExpressionEngine/ExpressionEngine 的其他 Issue

查看 ExpressionEngine/ExpressionEngine 的全部 Issue

相似的 Issue

更多 PHP Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。