尝试请求 Woocommerce 端点时,支付网关被 mod_security 阻止

Payment gateway blocked by mod_security when trying to request Woocommerce endpoint

我的支付网关在尝试访问 Woocommerce 端点时被 mod_security 阻止。
尝试访问“/wc-api/my_gateway_payment_callback”端点时收到 403 权限被拒绝。 我在 Litespeed 共享主机上。

从 .htaccess

中禁用 mod_security
<IfModule mod_security.c>
  SecFilterEngine Off
  SecFilterScanPOST Off
</IfModule>

它解决了问题,但使 Wordpress 管理员受到攻击,所以我想更具体一点。 我尝试添加 LocationMatch

<LocationMatch "/wc-api/my_gateway_payment_callback">
    <IfModule mod_security.c>
        SecRule REQUEST_URI "@beginsWith /wc-api/my_gateway_payment_callback/" \"phase:2,id:1000,nolog,pass, allow, msg:'Update URI accessed'"  
    </IfModule>
</LocationMatch>

<IfModule mod_security.c>
    SecRule REQUEST_URI "@beginsWith /my_gateway_payment_callback" \"phase:2,id:1000,nolog,pass, allow, msg:'Update URI accessed'"  
</IfModule>

但它们不起作用,我仍然收到 403 错误。

我可以在这里发现多个问题:

<IfModule mod_security.c>
 SecFilterEngine Off
 SecFilterScanPOST Off
</IfModule>

您真的在使用 ModSecurity v1 吗?这是非常古老的,建议您使用 Apache 1,因为 ModSecurity v1 与 ModSecurity v1 不兼容。如果不是这应该是:

<IfModule mod_security2.c>
 SecRuleEngine Off
</IfModule>

接下来你说:

it solves the issue but exposes Wordpress admin to attacks

除非您使用的是非常旧的软件,否则我看不出它如何解决问题,所以怀疑这是一个转移注意力的问题。

so i want to be more specific. i tried to add a LocationMatch

更具体的好主意。然而,LocationMatch 运行 在 Apache 进程中相当晚 - 在 ModSecurity 规则将具有 运行 之后,因此这将不起作用。但是,您实际上并不需要 LocationMatch,因为您的规则已经将其范围限定到该位置。那么让我们看看接下来的两篇:

   SecRule REQUEST_URI "@beginsWith /wc-api/my_gateway_payment_callback/" \"phase:2,id:1000,nolog,pass, allow, msg:'Update URI accessed'"  
   SecRuleRemoveById 3000

如果您在前几行 allow 规则,则不需要删除规则。通常你只会做其中之一。

or

<IfModule mod_security.c>
    SecRule REQUEST_URI "@beginsWith /my_gateway_payment_callback" > \
      "phase:2,id:1000,nolog,pass, allow, msg:'Update URI accessed'"  
</IfModule>

but they dont work and im still getting the 403 error.

您有 pass(这意味着继续下一个规则)和 allow(这意味着跳过所有未来的规则)。在我看来你只想要后者而不是前者。由于这些相互矛盾,我怀疑 ModSecurity 会首先对前者采取行动,因此它不起作用。

然而,更好的方法是查看 Apache 错误日志以查看它失败的规则(根据您的其他 LocationMatch 解决方法,它是规则 3000 吗?)并且只禁用该规则而不是禁用该规则的所有规则路线。

所以总而言之,我对你的问题很困惑,因为其中似乎有很多不一致和错误的地方......