SecRuleEngine On 似乎在 mod_security 中阻止了 PUT 和 DELETE 请求

SecRuleEngine On seem to block PUT and DELETE requests in mod_security

我启用了 SecRuleEngine 以便在 apache 的 mod_security 中按照本教程实施每个 IP 请求突发限制。

https://johnleach.co.uk/words/2012/05/15/rate-limiting-with-apache-and-mod-security/

经过一些测试后,它似乎在 GET 和 POST 请求上按预期工作,但是单独启用 SecRuleEngine(没有启用任何规则)似乎会阻止 PUT 和 DELETE 请求。这似乎不是预期的行为。

https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#SecRuleEngine

我使用带有 mod_security 版本 2 的 Apache 2.4,但如果它碰巧是其中的一个错误,我愿意放弃 mod_security,并且我有一个替代方法来限制它.

如何在使用或不使用 mod_security 的情况下修复限速系统?

ModSecurity 只阻止它被告知要阻止的内容。

我的猜测是,尽管说您没有启用任何规则,但您包含了明确阻止这些方法的 OWASP CRS。

版本 2 在其 modsecurity_crs_10_setup.conf.example 配置文件中有以下规则,例如:

#
# Set the following policy settings here and they will be propagated to the 30 rules
# file (modsecurity_crs_30_http_policy.conf) by using macro expansion.  
# If you run into false positves, you can adjust the settings here.
#
SecAction \
  "id:'900012', \
  phase:1, \
  t:none, \
  setvar:'tx.allowed_methods=GET HEAD POST OPTIONS', \
  setvar:'tx.allowed_request_content_type=application/x-www-form-urlencoded|multipart/form-data|text/xml|application/xml|application/x-amf|application/json', \
  setvar:'tx.allowed_http_versions=HTTP/0.9 HTTP/1.0 HTTP/1.1', \
  setvar:'tx.restricted_extensions=.asa/ .asax/ .ascx/ .axd/ .backup/ .bak/ .bat/ .cdx/ .cer/ .cfg/ .cmd/ .com/ .config/ .conf/ .cs/ .csproj/ .csr/ .dat/ .db/ .dbf/ .dll/ .dos/ .htr/ .htw/ .ida/ .idc/ .idq/ .inc/ .ini/ .key/ .licx/ .lnk/ .log/ .mdb/ .old/ .pass/ .pdb/ .pol/ .printer/ .pwd/ .resources/ .resx/ .sql/ .sys/ .vb/ .vbs/ .vbproj/ .vsdisco/ .webinfo/ .xsd/ .xsx/', \
  setvar:'tx.restricted_headers=/Proxy-Connection/ /Lock-Token/ /Content-Range/ /Translate/ /via/ /if/', \
  nolog, \
  pass"

如您所见,只有 GETHEADPOSTOPTIONS 被设置为允许的方法。

较新的版本 3 在 crs-setup.conf.example 中有类似的配置:

# HTTP methods that a client is allowed to use.
# Default: GET HEAD POST OPTIONS
# Example: for RESTful APIs, add the following methods: PUT PATCH DELETE
# Example: for WebDAV, add the following methods: CHECKOUT COPY DELETE LOCK
#          MERGE MKACTIVITY MKCOL MOVE PROPFIND PROPPATCH PUT UNLOCK
# Uncomment this rule to change the default.
#SecAction \
# "id:900200,\
#  phase:1,\
#  nolog,\
#  pass,\
#  t:none,\
#  setvar:'tx.allowed_methods=GET HEAD POST OPTIONS'"

在这两种情况下,作为后续规则使用此设置来阻止 PUTDELETE 等方法。

无论您使用的是这些规则还是其他规则集,ModSecurity 都应该在 Apache 错误日志中记录它阻止请求的原因。检查它以了解它被阻止的原因。

将偏执狂级别更改为 1 或 2 或 3 或 4 在 News OWASP CRS 中没关系 - Mod_Security, 偏执狂级别永远不应该是“0”

cd /usr/share/modsecurity-crs

SecAction \
"id:900000,\
phase:1,\
nolog,\
pass,\
t:none,\
setvar:tx.paranoia_level=1"
enter code here

添加 RESTful API 方法

允许客户端使用的 HTTP 方法。 默认值:GET HEAD POST OPTIONS 示例:对于 RESTful 个 API,添加以下方法:PUT PATCH DELETE 示例:对于 WebDAV,添加以下方法:CHECKOUT COPY DELETE LOCK MERGE MKACTIVITY MKCOL MOVE PROPFIND PROPPATCH PUT UNLOCK

只需取消注释 HTTP 方法的 HTTP 策略:

sudo nano /usr/share/modsecurity-crs/crs-setup.conf

SecAction \
"id:900200,\
phase:1,\
nolog,\
pass,\
t:none,\
setvar:'tx.allowed_methods=GET HEAD POST OPTIONS PUT PATCH DELETE'"