|
| 1 | +# -- Rule engine initialization ---------------------------------------------- |
| 2 | + |
| 3 | +# Enable ModSecurity, attaching it to every transaction. Use detection |
| 4 | +# only to start with, because that minimises the chances of post-installation |
| 5 | +# disruption. |
| 6 | +# |
| 7 | +SecRuleEngine DetectionOnly |
| 8 | + |
| 9 | + |
| 10 | +# -- Request body handling --------------------------------------------------- |
| 11 | + |
| 12 | +# Allow ModSecurity to access request bodies. If you don't, ModSecurity |
| 13 | +# won't be able to see any POST parameters, which opens a large security |
| 14 | +# hole for attackers to exploit. |
| 15 | +# |
| 16 | +SecRequestBodyAccess On |
| 17 | + |
| 18 | + |
| 19 | +# Enable XML request body parser. |
| 20 | +# Initiate XML Processor in case of xml content-type |
| 21 | +# |
| 22 | +SecRule REQUEST_HEADERS:Content-Type "^(?:application(?:/soap\+|/)|text/)xml" \ |
| 23 | + "id:'200000',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=XML" |
| 24 | + |
| 25 | +# Enable JSON request body parser. |
| 26 | +# Initiate JSON Processor in case of JSON content-type; change accordingly |
| 27 | +# if your application does not use 'application/json' |
| 28 | +# |
| 29 | +SecRule REQUEST_HEADERS:Content-Type "^application/json" \ |
| 30 | + "id:'200001',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON" |
| 31 | + |
| 32 | +# Sample rule to enable JSON request body parser for more subtypes. |
| 33 | +# Uncomment or adapt this rule if you want to engage the JSON |
| 34 | +# Processor for "+json" subtypes |
| 35 | +# |
| 36 | +#SecRule REQUEST_HEADERS:Content-Type "^application/[a-z0-9.-]+[+]json" \ |
| 37 | +# "id:'200006',phase:1,t:none,t:lowercase,pass,nolog,ctl:requestBodyProcessor=JSON" |
| 38 | + |
| 39 | +# Maximum request body size we will accept for buffering. If you support |
| 40 | +# file uploads then the value given on the first line has to be as large |
| 41 | +# as the largest file you are willing to accept. The second value refers |
| 42 | +# to the size of data, with files excluded. You want to keep that value as |
| 43 | +# low as practical. |
| 44 | +# |
| 45 | +SecRequestBodyLimit 13107200 |
| 46 | +SecRequestBodyNoFilesLimit 131072 |
| 47 | + |
| 48 | +# Store up to 128 KB of request body data in memory. When the multipart |
| 49 | +# parser reaches this limit, it will start using your hard disk for |
| 50 | +# storage. That is slow, but unavoidable. |
| 51 | +# |
| 52 | +SecRequestBodyInMemoryLimit 131072 |
| 53 | + |
| 54 | +# What do do if the request body size is above our configured limit. |
| 55 | +# Keep in mind that this setting will automatically be set to ProcessPartial |
| 56 | +# when SecRuleEngine is set to DetectionOnly mode in order to minimize |
| 57 | +# disruptions when initially deploying ModSecurity. |
| 58 | +# |
| 59 | +SecRequestBodyLimitAction Reject |
| 60 | + |
| 61 | +# Maximum parsing depth allowed for JSON objects. You want to keep this |
| 62 | +# value as low as practical. |
| 63 | +# |
| 64 | +SecRequestBodyJsonDepthLimit 512 |
| 65 | + |
| 66 | +# Verify that we've correctly processed the request body. |
| 67 | +# As a rule of thumb, when failing to process a request body |
| 68 | +# you should reject the request (when deployed in blocking mode) |
| 69 | +# or log a high-severity alert (when deployed in detection-only mode). |
| 70 | +# |
| 71 | +SecRule REQBODY_ERROR "!@eq 0" \ |
| 72 | +"id:'200002', phase:2,t:none,log,deny,status:400,msg:'Failed to parse request body.',logdata:'%{reqbody_error_msg}',severity:2" |
| 73 | + |
| 74 | +# By default be strict with what we accept in the multipart/form-data |
| 75 | +# request body. If the rule below proves to be too strict for your |
| 76 | +# environment consider changing it to detection-only. You are encouraged |
| 77 | +# _not_ to remove it altogether. |
| 78 | +# |
| 79 | +SecRule MULTIPART_STRICT_ERROR "!@eq 0" \ |
| 80 | +"id:'200003',phase:2,t:none,log,deny,status:400, \ |
| 81 | +msg:'Multipart request body failed strict validation: \ |
| 82 | +PE %{REQBODY_PROCESSOR_ERROR}, \ |
| 83 | +BQ %{MULTIPART_BOUNDARY_QUOTED}, \ |
| 84 | +BW %{MULTIPART_BOUNDARY_WHITESPACE}, \ |
| 85 | +DB %{MULTIPART_DATA_BEFORE}, \ |
| 86 | +DA %{MULTIPART_DATA_AFTER}, \ |
| 87 | +HF %{MULTIPART_HEADER_FOLDING}, \ |
| 88 | +LF %{MULTIPART_LF_LINE}, \ |
| 89 | +SM %{MULTIPART_MISSING_SEMICOLON}, \ |
| 90 | +IQ %{MULTIPART_INVALID_QUOTING}, \ |
| 91 | +IP %{MULTIPART_INVALID_PART}, \ |
| 92 | +IH %{MULTIPART_INVALID_HEADER_FOLDING}, \ |
| 93 | +FL %{MULTIPART_FILE_LIMIT_EXCEEDED}'" |
| 94 | + |
| 95 | +# Did we see anything that might be a boundary? |
| 96 | +# |
| 97 | +SecRule MULTIPART_UNMATCHED_BOUNDARY "!@eq 0" \ |
| 98 | +"id:'200004',phase:2,t:none,log,deny,msg:'Multipart parser detected a possible unmatched boundary.'" |
| 99 | + |
| 100 | +# PCRE Tuning |
| 101 | +# We want to avoid a potential RegEx DoS condition |
| 102 | +# |
| 103 | +SecPcreMatchLimit 1000 |
| 104 | +SecPcreMatchLimitRecursion 1000 |
| 105 | + |
| 106 | +# Some internal errors will set flags in TX and we will need to look for these. |
| 107 | +# All of these are prefixed with "MSC_". The following flags currently exist: |
| 108 | +# |
| 109 | +# MSC_PCRE_LIMITS_EXCEEDED: PCRE match limits were exceeded. |
| 110 | +# |
| 111 | +SecRule TX:/^MSC_/ "!@streq 0" \ |
| 112 | + "id:'200005',phase:2,t:none,log,deny,msg:'ModSecurity internal error flagged: %{MATCHED_VAR_NAME}'" |
| 113 | + |
| 114 | + |
| 115 | +# -- Response body handling -------------------------------------------------- |
| 116 | + |
| 117 | +# Allow ModSecurity to access response bodies. |
| 118 | +# You should have this directive enabled in order to identify errors |
| 119 | +# and data leakage issues. |
| 120 | +# |
| 121 | +# Do keep in mind that enabling this directive does increases both |
| 122 | +# memory consumption and response latency. |
| 123 | +# |
| 124 | +SecResponseBodyAccess On |
| 125 | + |
| 126 | +# Which response MIME types do you want to inspect? You should adjust the |
| 127 | +# configuration below to catch documents but avoid static files |
| 128 | +# (e.g., images and archives). |
| 129 | +# |
| 130 | +SecResponseBodyMimeType text/plain text/html text/xml |
| 131 | + |
| 132 | +# Buffer response bodies of up to 512 KB in length. |
| 133 | +SecResponseBodyLimit 524288 |
| 134 | + |
| 135 | +# What happens when we encounter a response body larger than the configured |
| 136 | +# limit? By default, we process what we have and let the rest through. |
| 137 | +# That's somewhat less secure, but does not break any legitimate pages. |
| 138 | +# |
| 139 | +SecResponseBodyLimitAction ProcessPartial |
| 140 | + |
| 141 | + |
| 142 | +# -- Filesystem configuration ------------------------------------------------ |
| 143 | + |
| 144 | +# The location where ModSecurity stores temporary files (for example, when |
| 145 | +# it needs to handle a file upload that is larger than the configured limit). |
| 146 | +# |
| 147 | +# This default setting is chosen due to all systems have /tmp available however, |
| 148 | +# this is less than ideal. It is recommended that you specify a location that's private. |
| 149 | +# |
| 150 | +SecTmpDir /tmp/ |
| 151 | + |
| 152 | +# The location where ModSecurity will keep its persistent data. This default setting |
| 153 | +# is chosen due to all systems have /tmp available however, it |
| 154 | +# too should be updated to a place that other users can't access. |
| 155 | +# |
| 156 | +SecDataDir /tmp/ |
| 157 | + |
| 158 | + |
| 159 | +# -- File uploads handling configuration ------------------------------------- |
| 160 | + |
| 161 | +# The location where ModSecurity stores intercepted uploaded files. This |
| 162 | +# location must be private to ModSecurity. You don't want other users on |
| 163 | +# the server to access the files, do you? |
| 164 | +# |
| 165 | +#SecUploadDir /opt/modsecurity/var/upload/ |
| 166 | + |
| 167 | +# By default, only keep the files that were determined to be unusual |
| 168 | +# in some way (by an external inspection script). For this to work you |
| 169 | +# will also need at least one file inspection rule. |
| 170 | +# |
| 171 | +#SecUploadKeepFiles RelevantOnly |
| 172 | + |
| 173 | +# Uploaded files are by default created with permissions that do not allow |
| 174 | +# any other user to access them. You may need to relax that if you want to |
| 175 | +# interface ModSecurity to an external program (e.g., an anti-virus). |
| 176 | +# |
| 177 | +#SecUploadFileMode 0600 |
| 178 | + |
| 179 | + |
| 180 | +# -- Debug log configuration ------------------------------------------------- |
| 181 | + |
| 182 | +# The default debug log configuration is to duplicate the error, warning |
| 183 | +# and notice messages from the error log. |
| 184 | +# |
| 185 | +#SecDebugLog /opt/modsecurity/var/log/debug.log |
| 186 | +#SecDebugLogLevel 3 |
| 187 | + |
| 188 | + |
| 189 | +# -- Audit log configuration ------------------------------------------------- |
| 190 | + |
| 191 | +# Log the transactions that are marked by a rule, as well as those that |
| 192 | +# trigger a server error (determined by a 5xx or 4xx, excluding 404, |
| 193 | +# level response status codes). |
| 194 | +# |
| 195 | +SecAuditEngine RelevantOnly |
| 196 | +SecAuditLogRelevantStatus "^(?:5|4(?!04))" |
| 197 | + |
| 198 | +# Log everything we know about a transaction. |
| 199 | +SecAuditLogParts ABIJDEFHZ |
| 200 | + |
| 201 | +# Use a single file for logging. This is much easier to look at, but |
| 202 | +# assumes that you will use the audit log only ocassionally. |
| 203 | +# |
| 204 | +#SecAuditLogType Serial |
| 205 | +#SecAuditLog /var/log/modsec_audit.log |
| 206 | + |
| 207 | +# Specify the path for concurrent audit logging. |
| 208 | +#SecAuditLogStorageDir /opt/modsecurity/var/audit/ |
| 209 | + |
| 210 | + |
| 211 | +# -- Miscellaneous ----------------------------------------------------------- |
| 212 | + |
| 213 | +# Use the most commonly used application/x-www-form-urlencoded parameter |
| 214 | +# separator. There's probably only one application somewhere that uses |
| 215 | +# something else so don't expect to change this value. |
| 216 | +# |
| 217 | +SecArgumentSeparator & |
| 218 | + |
| 219 | +# Settle on version 0 (zero) cookies, as that is what most applications |
| 220 | +# use. Using an incorrect cookie version may open your installation to |
| 221 | +# evasion attacks (against the rules that examine named cookies). |
| 222 | +# |
| 223 | +SecCookieFormat 0 |
| 224 | + |
| 225 | +# Specify your Unicode Code Point. |
| 226 | +# This mapping is used by the t:urlDecodeUni transformation function |
| 227 | +# to properly map encoded data to your language. Properly setting |
| 228 | +# these directives helps to reduce false positives and negatives. |
| 229 | +# |
| 230 | +SecUnicodeMapFile unicode.mapping 20127 |
| 231 | + |
| 232 | +# Improve the quality of ModSecurity by sharing information about your |
| 233 | +# current ModSecurity version and dependencies versions. |
| 234 | +# The following information will be shared: ModSecurity version, |
| 235 | +# Web Server version, APR version, PCRE version, Lua version, Libxml2 |
| 236 | +# version, Anonymous unique id for host. |
| 237 | +# NB: As of April 2022, there is no longer any advantage to turning this |
| 238 | +# setting On, as there is no active receiver for the information. |
| 239 | +SecStatusEngine Off |
| 240 | + |
0 commit comments