Skip to content

ModSecurity header phase runs before nginx rate limiting #293

@brandonpayton

Description

@brandonpayton

As a user, we would like to skip the cost of ModSecurity rule processing for requests that are rate-limited by nginx. Today, the ModSecurity header phase is processed before the ngx_http_limit_req_module considers rate limiting.

This is due to how each module hooks into the nginx request phases. The ngx_http_limit_req_module enforces rate limiting in the NGX_HTTP_PREACCESS_PHASE, but ModSecurity-nginx processes the ModSecurity header phase earlier, during the NGX_HTTP_REWRITE_PHASE.

Some workarounds are:

  • Move all rules to the ModSecurity request body, but this is not a great option when using large, shared rulesets like the OWASP ModSecurity Core Rule Set.
  • Make a custom build that runs the ModSecurity request header phase in the PREACCESS phase. This is the same nginx phase used to run the ModSecurity request body phase, but unlike the request body phase, the header phase wouldn't have to wait to receive the request body.

Even with these workarounds, it seems like it might make sense to be able to rate-limit prior to ModSec processing. Is this something we could consider changing or making configurable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions