Variable reference

ModSecurity variables and collections

Reference request, response, connection, rule, transaction, persistent, and file variables used by SecRule.

Adapted ModSecurity documentationThis page has been reorganized, rewritten, and supplemented by Atomicorp from upstream ModSecurity reference material. Source, license, and attribution details.

Variables are the inputs to a SecRule. A scalar represents one value; a collection can expand into many values. Select the narrowest data that expresses the security decision.

Request variables

VariableContains
REQUEST_URIRequest path, generally including the query string.
REQUEST_URI_RAWOriginal request URI before normalization.
REQUEST_FILENAMERequest path without the query string.
REQUEST_LINEFull request line.
REQUEST_METHODHTTP method.
REQUEST_PROTOCOLProtocol from the request line.
QUERY_STRINGRaw query string.
REQUEST_HEADERSRequest-header collection.
REQUEST_HEADERS_NAMESNames of received request headers.
REQUEST_COOKIESParsed request-cookie collection.
REQUEST_BODYRaw or processor-dependent request body when available.

Arguments and files

VariableContains
ARGSAll parsed request arguments.
ARGS_GETQuery-string arguments.
ARGS_POSTBody arguments.
ARGS_NAMESArgument names across request sources.
FILESTemporary paths for intercepted uploads.
FILES_NAMESClient-supplied upload names.
FILES_SIZESUpload sizes.
FILES_TMPNAMESTemporary upload filenames.
FILES_COMBINED_SIZECombined upload size.

Select one member with ARGS:username. Use a regular-expression selector when names follow a controlled pattern. A negated target such as !ARGS:known_safe removes one member from a larger target list.

Connection and server data

Common inputs include REMOTE_ADDR, REMOTE_HOST, REMOTE_PORT, SERVER_ADDR, SERVER_NAME, SERVER_PORT, UNIQUE_ID, and TIME. Reverse proxies can change what the connector sees as the remote address; configure trusted proxy handling before relying on client IP policy.

Response variables

VariableContains
RESPONSE_STATUSHTTP response status.
RESPONSE_HEADERSResponse-header collection.
RESPONSE_HEADERS_NAMESNames of response headers.
RESPONSE_BODYBuffered response content when enabled and eligible.
RESPONSE_CONTENT_TYPEParsed content type.

Response-body data is unavailable unless response inspection is enabled and the MIME type and size fall within configured limits.

Match and rule context

MATCHED_VAR contains the value associated with a match, while MATCHED_VAR_NAME identifies its variable. RULE exposes metadata for the current rule. TX is a per-transaction collection commonly used for flags, captured values, and scores.

SecRule ARGS "@rx attack" \
  "id:100010,phase:2,log,pass,setvar:'tx.reason=%{MATCHED_VAR_NAME}'"

Persistent collections

IP, SESSION, USER, RESOURCE, and GLOBAL can retain state beyond one transaction when initialized and supported. Persistent state can implement counters and expiration, but it adds locking, storage, cleanup, and distributed-consistency concerns. Do not assume counters are a complete DDoS system.

Counting and exclusions

Prefix a collection with & to inspect how many members it contains. Prefix a target with ! to exclude it from the rule target list. Both change what reaches the operator; neither changes the underlying request.

See the exhaustive upstream variable reference for individual syntax and version support.