Skip to content

Match rule transform POST in GET #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
cello86 opened this issue Dec 15, 2021 · 4 comments
Closed

Match rule transform POST in GET #258

cello86 opened this issue Dec 15, 2021 · 4 comments

Comments

@cello86
Copy link

cello86 commented Dec 15, 2021

Hi All,
we noticed on modsecurity for Nginx connector a strange behavior. If a rule is matched before the normal CRS rules engine the HTTP method is noticed like GET instead the original POST.

We already had some issues with the internal redirects but the matching on different phases can generate this type of error?

Thanks,
Marcello

@martinhsv
Copy link
Contributor

Hello @cello86 ,

I'm not sure I understand the use case that you are describing.

Note that ModSecurity (including the nginx connector) is the "engine". CRS is a generic rule set that is often used with ModSecurity.

From what have included, however, what you are seeing sounds like it might be expected behaviour related to error redirects. You may wish to have a look at the following for more detail: #152 (comment)

If you think what you are experiencing is unrelated to that, please provide additional detail.

@cello86
Copy link
Author

cello86 commented Dec 23, 2021

Hi @cello86,
we configured the nginx instance with the error page without mod_security enabled to avoid the internal redirect.

    server {
	server_name test.local;

        modsecurity on;
        modsecurity_rules_file /usr/local/nginx/conf/modsecurity.conf;
 
        error_page 403 /error/403.json;

        location ^~ /error {
            modsecurity_rules 'SecRule REQUEST_URI "@beginsWith /" "id:1,pass,phase:2,log,ctl:ruleEngine=DetectionOnly"';
            alias "/usr/local/nginx/error";
        }

 
        location / {
            root   html;
        }
    }

Marcello

@martinhsv
Copy link
Contributor

Hello @cello86 ,

Perhaps I've misunderstood something but how does that configuration result in 'without mod_security enabled'?

You explicitly have 'modsecurity on' within the outside server block. So it will still be 'on' inside the 'location ^~ /error' -- which it seems you understand because you include an extra modsecurity_rules entry there.

That extra rule includes an action 'ctl:ruleEngine=DetectionOnly', so rules that are impacted by that will, of course, use Detection Only.

However even for rule detections after that point, you will still see the effect of the GET requests that were originally POSTs (e.g. in logging). Note also that your "id:1" rule will run later than at least some other rules (you have it as a phase:2 rule), you could have a look at the DebugLog output to confirm which rules are being run in which order.

If none of the above clarifies things for you, I think you're going to have to describe in more detail, what effects exactly you are seeing and how you expect them to be different.

@martinhsv
Copy link
Contributor

Was there anything further on this?

liudongmiao added a commit to liudongmiao/ModSecurity-nginx that referenced this issue Feb 24, 2022
Nginx handles `error_page` via `ngx_http_internal_redirect`, and audit log in `ModSecurity-nginx` is trigged in the next handler.

In nginx's code, it's harded to `GET` for non-`HEAD`, refers https://github.com/nginx/nginx/blob/master/src/http/ngx_http_special_response.c#L618-L621:

```c
        if (r->method != NGX_HTTP_HEAD) {
            r->method = NGX_HTTP_GET;
            r->method_name = ngx_http_core_get_method;
        }
```

This patch use `method_name` from `request_line` to fix this issue.

This should fix method name in owasp-modsecurity#182, and solve owasp-modsecurity#258.
liudongmiao added a commit to liudongmiao/ModSecurity-nginx that referenced this issue Feb 24, 2022
Nginx handles `error_page` via `ngx_http_internal_redirect`, and audit log in `ModSecurity-nginx` is trigged in the next handler.

In nginx's code, it's harded to `GET` for non-`HEAD`, refers https://github.com/nginx/nginx/blob/master/src/http/ngx_http_special_response.c#L618-L621:

```c
        if (r->method != NGX_HTTP_HEAD) {
            r->method = NGX_HTTP_GET;
            r->method_name = ngx_http_core_get_method;
        }
```

This patch use `method_name` from `request_line` to fix this issue.

This should fix method name in owasp-modsecurity#182, and solve owasp-modsecurity#258.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants