首页 > 解决方案 > 服务器对 ajax 调用的响应为 200,但在浏览器上我在 Safari 上收到错误 400

问题描述

我在 WordPress 网站上有一个奇怪的行为。它工作得很好,但几个用户(在 safari 上)报告看到错误 400。在使用 safari 进行测试时,我设法通过更改浏览器的用户代理来重现问题。然后我开始在每个 ajax 调用上收到错误 400。我已经检查了access.log对 admin-ajax.php 的所有请求,其中状态为 200。但是当我在 Safari 中检查检查器时,相同的 ajax 请求的状态为 400。这发生在每个 ajax 请求上网站的页面。我尝试注销/登录,清除所有 cookie、缓存等,但错误仍然存​​在。该站点使用 CloudFlare,所以我去那里检查了所有的安全和防火墙规则,我没有发现我的 IP 在任何地方都被阻止。

所以现在的问题是代码 200 的响应如何变成 400?

这里也是ajax调用的请求和响应:

Summary

URL: https://www.example.com.com/wp-admin/admin-ajax.php
Status: 400
Source: Local Override
Address: yyy.yyy.yyy.yyy:zzz
Initiator: some-script.min.js:1:2080

Request

:method: POST
:scheme: https
:authority: www.example.com.com
:path: /wp-admin/admin-ajax.php
Accept: application/json, text/plain, */*
Content-Type: application/x-www-form-urlencoded
Origin: https://www.example.com.com
Cookie: some-cookies
Content-Length: 88
Accept-Language: en-us
Host: www.example.com.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15
Referer: https://www.example.com.com/units/main/
Accept-Encoding: gzip, deflate, br
Connection: keep-alive

Response

:status: 400
Date: Wed, 27 Jan 2021 12:27:47 GMT
Referrer-Policy: strict-origin-when-cross-origin
X-Content-Type-Options: nosniff
Cache-Control: no-cache, must-revalidate, max-age=0, no-store
X-Frame-Options: SAMEORIGIN
Content-Type: text/html
Access-Control-Allow-Credentials: true
Pragma: no-cache
Set-Cookie: some-cookies
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Access-Control-Allow-Origin: https://www.example.com.com
cf-edge-cache: cache,platform=wordpress
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
nel: {"max_age":604800,"report_to":"cf-nel"}
report-to: {"group":"cf-nel","endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=some-token"}],"max_age":604800}
cf-cache-status: DYNAMIC
cf-request-id: 07e569767900001c377fb67000000001
cf-ray: 618278372fc81c37-SOF
x-robots-tag: noindex
Server: cloudflare

Request Data

MIME Type: application/x-www-form-urlencoded
action: my_ajax_callback
term_id: 1209
page_id

这是来自access.log

xx.xxx.xx.xxx - - [24/Mar/2021:10:16:46 +0000] "POST /wp-admin/admin-ajax.php HTTP/1.0" 200 12203 "https://example.com/some-page/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.3 Safari/605.1.15"

更新

我不得不说这只发生在 Safari 上,没有其他浏览器。此外,我正在使用 Mojave 在 VM 中运行 Safari,不确定这是否相关,但我认为值得一提。

我试图暂停 CF 服务,并且此更改在所有其他浏览器上都可见,但 Safari 继续通过 CF 为站点提供服务(我可以在响应标头server中看到它的值cloudflare在其他浏览器上是nginx)。我已经刷新了终端中的 DNS 并重新启动了几次 VM,但这并没有改变。

再次启用 CloudFlare 后,我还禁用了 CloudFlare 上的所有安全和防火墙功能,但这也没有解决问题。我开始相信问题出在Safari而不是CF中。

标签: ajaxwordpresssafarihttpresponsecloudflare

解决方案


尝试关闭 Cloudflare,该设置称为“在站点上暂停 Cloudflare”以将其隔离,看看是否有影响。也许你有一些愚蠢的 modsec 规则?


推荐阅读