【问题标题】:Mod_security issue with DELETE and PUT request?删除和放置请求的 Mod_security 问题?
【发布时间】:2013-06-17 18:37:37
【问题描述】:

大家好,

我构建了一个简单的 API,并且在我的本地主机上一切正常。当我将它放在我的服务器上时,当我尝试执行 PUT 或 DELETE 请求时,我开始收到此错误。 我查看了 NOYB 的东西,发现我启用了 Mod_Security 并且这导致了错误。我尝试为域关闭此功能,但要么我做错了,要么这不是问题。

我希望你们能在这里快速帮助我,因为这需要在晚上结束之前工作。 任何帮助表示赞赏。

【问题讨论】:

    标签: web-services api rest http-headers mod-security


    【解决方案1】:

    虽然对于您的需求来说有点晚了,但这里的答案可能会帮助您遇到的其他人。

    首先创建测试解决方案所需的工具,假设使用 PHP 进行配置:

    //server-side script test-put.php
    < ?php
    parse_str(file_get_contents('php://input'), $vars);
    print_r($vars);
    

    //client-side script send-put-req.php
    < ?php 
    $result = file_get_contents(
       'http://www.testsite.ro/test-put.php', 
        false, 
        stream_context_create(array(
           'http' => array(
           'method' => 'PUT' 
           )
        ))
    );
    
    print_r($result);
    

    然后查看 error_log 文件 (/usr/local/apache/logs/error_log) 中的 mod_security 行,每次请求来自上述脚本时。在我的配置中,我不得不更改这个(/usr/local/apache/conf/modsec2.user.conf):

    # allow request methods
    SecRule REQUEST_METHOD "!^((?:(?:POS|GE|PU)T|OPTIONS|HEAD**|DELETE))$" \
    "phase:2,t:none,log,auditlog,status:501,msg:'Method is not allowed by policy', severity:'2',id:'960032',tag:'POLICY/METHOD_NOT_ALLOWED'"
    

    【讨论】:

      猜你喜欢
      • 2018-09-15
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多