CheckRule

The CheckRule directive defines rules to validate incoming requests against specified patterns to mitigate XSS and SQL Injection attacks.

SyntaxCheckRule rule_name;
Defaultnone
Contexthttp, server, location, limit_except
Arguments1+

Description

The CheckRule directive is a part of the NGINX Anti XSS & SQL Injection module (Naxsi), which is designed to protect web applications from common web vulnerabilities. When invoked, it inspects incoming requests and matches them against a predefined set of rules or patterns that indicate potential security threats, such as XSS or SQL Injection attempts. This directive allows for custom rule definitions that can be tailored to suit the application's specific security requirements, thereby enhancing the overall security posture of the site.

One of the key features of CheckRule is its flexibility; it can accept one or more arguments that specify the rules to be applied. These rules can comprise various patterns, allowing administrators to create complex rule sets that account for legitimate user behavior while blocking malicious inputs. The directive can be employed in various contexts including 'http', 'server', 'location', and 'limit_except', thus providing a wide range of configuration options for NGINX users.

In practice, Naxsi operates on a whitelist basis, meaning that all requests are denied by default and only those matching explicitly defined rules are allowed through. This approach minimizes the risk of undetected web vulnerabilities, as it focuses on known good behaviors rather than constantly trying to identify bad ones. The administrator can either define rules manually or utilize an auto-learning mode that generates whitelisting rules based on the site’s typical behavior, thus improving user experience while maintaining strict security standards.

Config Example

location /submit {
    CheckRule "Request_Validation_Rules";
}

Ensure that the rules are correctly defined to avoid unintentionally blocking legitimate requests.

Overly generic rules can lead to false positives, where valid requests might be blocked.

Always test configurations in a staging environment before applying in production to prevent downtime.

← Back to all directives