编辑私信时尝试保存草稿,Mini Profiler 导致 403 错误

自更新到 v2026.8.0-latest +28(从某个 v2026.7 版本)以来,作为“开发者”,在编辑私信时,我看到:

{52B46C2B-8166-4B02-92C9-936558B256BA}

在浏览器控制台中,我看到:

20:54:29.425 includes.js?v=e0bcc9ce0ae3bb5d6b736b6f282f601f:840  POST https://dietpi.com/forum/drafts.json 403 (Forbidden)
(anonymous) @ includes.js?v=e0bcc9ce0ae3bb5d6b736b6f282f601f:840
send @ jquery.js:9940
ajax @ jquery.js:9521
i @ ajax.js:233
Z @ ajax.js:252
save @ draft.js:37
saveDraft @ composer.js:1535
_saveDraft @ composer.js:1963
_shouldSaveDraft @ composer.js:1999
sendEvent @ cache-DtDz7X5V.js:471
(anonymous) @ cache-DtDz7X5V.js:665
invoke @ index.js:262
flush @ index.js:180
flush @ index.js:334
_end @ index.js:762
(anonymous) @ index.js:499
Promise.then
(anonymous) @ index.js:18
flush @ index.js:29
_scheduleAutorun @ index.js:928
_end @ index.js:768
(anonymous) @ index.js:499
Promise.then
(anonymous) @ index.js:18
flush @ index.js:29
_scheduleAutorun @ index.js:928
_end @ index.js:768
(anonymous) @ index.js:499
Promise.then
(anonymous) @ index.js:18
flush @ index.js:29
_scheduleAutorun @ index.js:928
_end @ index.js:768
(anonymous) @ index.js:499
Promise.then
(anonymous) @ index.js:18
flush @ index.js:29
_scheduleAutorun @ index.js:928
_end @ index.js:768
(anonymous) @ index.js:499
Promise.then
(anonymous) @ index.js:18
flush @ index.js:29
_scheduleAutorun @ index.js:928
_ensureInstance @ index.js:919
ensureInstance @ index.js:731
scheduleRevalidate @ index-DaCZcoCY.js:4146
dirtyTag @ index.js:229
dirtyTagFor @ index.js:848
setter @ index.js:871
set @ cache-DtDz7X5V.js:1886
_setProp @ property_set-n9lAuzYY.js:47
set @ property_set-n9lAuzYY.js:42
(anonymous) @ set_properties-D2_u0phU.js:94
changeProperties @ cache-DtDz7X5V.js:802
(anonymous) @ set_properties-D2_u0phU.js:88
setProperties @ observable.js:30
_hydrate @ store.js:446
_hydrateFindResults @ store.js:106
(anonymous) @ store.js:124
Promise.then
find @ store.js:123
(anonymous) @ composer.js:1110
mu @ rsvp-ziM3qQyS.js:412
(anonymous) @ rsvp-ziM3qQyS.js:468
invoke @ index.js:264
flush @ index.js:180
flush @ index.js:334
_end @ index.js:762
end @ index.js:565
_runExpiredTimers @ index.js:869
setTimeout
setTimeout @ index.js:39
_installTimerTimeout @ index.js:912
_reinstallTimerTimeout @ index.js:896
_later @ index.js:829
later @ index.js:652
next @ index.js:562
_triggerAction @ d-button.gts:212
click @ d-button.gts:166
20:54:31.380 includes.js?v=e0bcc9ce0ae3bb5d6b736b6f282f601f:840  POST https://dietpi.com/forum/drafts.json 403 (Forbidden)
(anonymous) @ includes.js?v=e0bcc9ce0ae3bb5d6b736b6f282f601f:840
send @ jquery.js:9940
ajax @ jquery.js:9521
i @ ajax.js:233
Z @ ajax.js:252
save @ draft.js:37
saveDraft @ composer.js:1535
_saveDraft @ composer.js:1963
invoke @ index.js:264
flush @ index.js:180
flush @ index.js:334
_end @ index.js:762
end @ index.js:565
_runExpiredTimers @ index.js:869
setTimeout
setTimeout @ index.js:39
_installTimerTimeout @ index.js:912
_scheduleExpiredTimers @ index.js:892
_runExpiredTimers @ index.js:868
setTimeout
setTimeout @ index.js:39
_installTimerTimeout @ index.js:912
_scheduleExpiredTimers @ index.js:892
_runExpiredTimers @ index.js:868
setTimeout
setTimeout @ index.js:39
_installTimerTimeout @ index.js:912
_scheduleExpiredTimers @ index.js:892
_runExpiredTimers @ index.js:868
setTimeout
setTimeout @ index.js:39
_installTimerTimeout @ index.js:912
_scheduleExpiredTimers @ index.js:892
_runExpiredTimers @ index.js:868
setTimeout
setTimeout @ index.js:39
_installTimerTimeout @ index.js:912
_reinstallTimerTimeout @ index.js:896
_later @ index.js:829
debounce @ index.js:680
debounce @ index.js:713
(anonymous) @ debounce.js:26
debouncedRecalculateHeaderOffset @ glimmer-site-header.gjs:96
_run @ index.js:804
_join @ index.js:783
join @ index.js:605
join @ index.js:152
(anonymous) @ index.js:250
20:54:34.397 7:1 The resource https://dietpi.com/matomo/matomo.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.
20:54:39.457 7:1 The resource https://dietpi.com/matomo/matomo.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.

这个 403 错误似乎来自 mini profiler:

    if (!window.MiniProfiler || !window.MiniProfiler.patchesApplied) {
      var send = XMLHttpRequest.prototype.send;

      XMLHttpRequest.prototype.send = function(data) {
        ajaxStartTime = new Date();
        this.addEventListener("load", function() {
          // responseURL isn't available in IE11
          if (
            this.responseURL &&
            this.responseURL.indexOf(window.location.origin) !== 0
          ) {
            return;
          }
          if (this.__miniProfilerSkipResultsFetch) {
            return;
          }
          // getAllResponseHeaders isn't available in Edge.
          var allHeaders = this.getAllResponseHeaders
            ? this.getAllResponseHeaders()
            : null;
          if (
            allHeaders &&
            allHeaders.toLowerCase().indexOf("x-miniprofiler-ids") === -1
          ) {
            return;
          }
          // should be a string of comma-separated ids
          var stringIds = this.getResponseHeader("X-MiniProfiler-Ids");

          if (stringIds) {
            var ids = stringIds.split(",");
            fetchResults(ids);
          }
        });
        send.call(this, data);
      }; // fetch results after ASP Ajax calls

据我理解,当尝试向 drafts.json 发送 POST 请求时,send.call(this, data) 收到了 403 错误。我猜 data 是无效数据,导致了 403 错误?浏览器中没有关于 CSP 或其他安全规则/标头阻止任何请求的信息。

编辑公开帖子或向对话中添加新私信时不会发生这种情况,仅在编辑私信对话中的帖子时发生。

通过 ALT+P 隐藏分析器并不能阻止此问题。我可能应该以非开发者用户身份进行测试。

由于该错误,我猜保存编辑也失败了,因为数据不是有效的 JSON。

我们使用官方 Docker 容器,但如所见,在 /forum 子路径后面运行它(通过代理 Apache2)。这可能有影响。

啊,这只是 Cloudflare 防火墙的误报,属于“Cloudflare 托管规则集”中的 95a84ab1645a49c685648c17761e7a4c 规则,以防其他人也遇到同样的问题。这已经是我为了 Discourse 而需要禁用的默认规则集中的第 7 条规则了,因为它会扫描 JSON 内容(即帖子内容)以查找特定模式。由于我经常编写或粘贴 Shell(及其他)代码,这些规则就会被触发。