Skip to content

Chunked upload content-type is causing trouble with ModSecurity WAF #1942

@ne20002

Description

@ne20002

I've set up a ModSecurity Web Application Firewall to protect my Nextcloud instance. I now face a lot of errors in the WAF log (which would cause a lot af blocking once I disable detection only mode).

The cause for all errors listed can be boiled down to file upload requests with chunk files like this one:
PUT /remote.php/dav/uploads/ag/23C6E9FC-E70D-4F88-89DF-47FD58AA44BF/22-03-18%2018-30-34%20F8EB.mov0000000000 HTTP/1.1
As far as I see, the encoding of the upload data is
content-type: application/x-www-form-urlencoded
which seems a bit strange for file uploads.
I would expect to have it content-type: application/octet-stream.

The url-encoded body data is heavily causing trouble with the WAF when it tries to analyze the body data.

Steps to reproduce

Set up a ModSecurity WAF with nginx. Try to upload a file in chunks with iOS app.

Expected behaviour

File uploads, as it is binary data, shall be uploaded as content-type: application/octet-stream.

Actual behaviour

Uploaded Data is endoded as content-type: application/x-www-form-urlencoded and is confusing the web application firewall.

Logs

---6Y2eSSKW---A--
[31/Mar/2022:09:17:26 +0000] 1648718246 2a02:aa12:a682:880:6860:219d:34c7:e16b 0 10.0.2.100 80
---6Y2eSSKW---B--
PUT /remote.php/dav/uploads/ag/23C6E9FC-E70D-4F88-89DF-47FD58AA44BF/22-03-18%2018-30-34%20F8EB.mov0000000000 HTTP/1.1
accept: */*
Content-Length: 20000000
X-Real-IP: 2a02:aa12:a682:880:6860:219d:34c7:e16b
Host: xxxxxxxx
Connection: close
X-Forwarded-Proto: https
X-Forwarded-By: xxxxxxxxxxxxx
user-agent: Mozilla/5.0 (iOS) Nextcloud-iOS/4.3.1
content-type: application/x-www-form-urlencoded
X-Forwarded-Port: 443
X-Forwarded-For: 2a02:aa12:a682:880:6860:219d:34c7:e16b
Forwarded: for=2a02:aa12:a682:880:6860:219d:34c7:e16b; proto=https; by=xxxxxxx
accept-language: de-CH;q=1.0, en-CH;q=0.9, en-GB;q=0.8
authorization: Basic YWc6TWJDakQtS0tpSjgtWkdzUFktNnEzZEEtTmc0MkQ=
ocs-apirequest: true
accept-encoding: br;q=1.0, gzip;q=0.9, deflate;q=0.8

---6Y2eSSKW---F--
HTTP/1.1 200

---6Y2eSSKW---H--
ModSecurity: Warning. Matched "Operator `ValidateUrlEncoding' with parameter `' against variable `REQUEST_BODY' (Value: `\x00\x00\x00\x1cftypmp42\x00\x00\x00\x01isommp41mp42\x00\x00}\x91moov\x00\x00\x00lmvhd\x00\x00\x00\x (45429380 characters omitted)' ) [file "/etc/modsecurity.d/owasp-crs/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf"] [line "375"] [id "920240"] [rev ""] [msg "URL Encoding Abuse Attack Attempt"] [data "\x00\x00\x00\x1cftypmp42\x00\x00\x00\x01isommp41mp42\x00\x00}\x91moov\x00\x00\x00lmvhd\x00\x00\x00\x00\xdeZrv\xdeZr~\x00\x00\x02X\x00\x00vg\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00)\xdctrak\x00\x00\x00\tkhd\x00\x00\x00\x01\xdeZrv\xdeZr~\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00vf\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00 (15728440 characters omitted)"] [severity "4"] [ver "OWASP_CRS/3.3.2"] [maturity "0"] [accuracy "0"] [tag "modsecurity"] [tag "modsecurity"] [tag "modsecurity"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-protocol"] [tag "paranoia-level/1"] [tag "OWASP_CRS"] [tag "capec/1000/255/153/267/72"] [hostname "10.0.2.100"] [uri "/remote.php/dav/uploads/ag/23C6E9FC-E70D-4F88-89DF-47FD58AA44BF/22-03-18 18-30-34 F8EB.mov0000000000"] [unique_id "1648718246"] [ref "o0,33v489,33o979,1v1051,15728640o979,15728640v1051,15728640"]
ModSecurity: Warning. Matched "Operator `ValidateByteRange' with parameter `1-255' against variable `ARGS_NAMES' (Value: `\x8awU2'\xc5\x11\xd5W\xdf\xbaj\xe0vAEK\xfb\xb7\x92\x933@\x80L\xa8\xdfS\xfb\xab\xbb\xf0\xa6\xcdF\xc5\ (1978 characters omitted)' ) [file "/etc/modsecurity.d/owasp-crs/rules/REQUEST-920-PROTOCOL-ENFORCEMENT.conf"] [line "500"] [id "920270"] [rev ""] [msg "Invalid character in request (null character)"] [data "ARGS_NAMES=\x8awU2'\xc5\x11\xd5W\xdf\xbaj\xe0vAEK\xfb\xb7\x92\x933@\x80L\xa8\xdfS\xfb\xab\xbb\xf0\xa6\xcdF\xc5\x8e\x12,a\xbe\xfd\L-\xeb\xb9\xf5\xb6\xeb\x05Df\xa5\x8f\xbc \x00\x00\xecx\xa9\x0a#%\x8as\x84\x92\x84}Wu9\xcc \xf0\x17\xe0\x1eg\xed]9@\x8f\xf9\xde\xaf\x9d1\x87\xdb\xd0\xfc5zv\xf7\xbe\x85\x08d\xaf1\xa3\xae\xd0\xca\x8eC\x0c\xea\x9f.O\x0d\xc2Igs\xd9?\xcf\x9d\xb6C\x9e\xac\x98\xd1$\xa4{e\x92\x01\xeaI\x03R^X\xbe\xeb\x1f\x00\xee\xaf\x05cs\xea\x17)\x0c\x00\x01\x15\xa4k\x05\x85\x90\xc62\xae\xf7\xb2\x93L\xea\x09$\x8c0>\xce\xaa\x07\x84J\xd4Jd\x92o\x9e\xfe (515 characters omitted)"] [severity "2"] [ver "OWASP_CRS/3.3.2"] [maturity "0"] [accuracy "0"] [tag "modsecurity"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-protocol"] [tag "paranoia-level/1"] [tag "OWASP_CRS"] [tag "capec/1000/210/272"] [hostname "10.0.2.100"] [uri "/remote.php/dav/uploads/ag/23C6E9FC-E70D-4F88-89DF-47FD58AA44BF/22-03-18 18-30-34 F8EB.mov0000000000"] [unique_id "1648718246"] [ref

Reasoning or why should it be changed/implemented?

This makes using a web application firewall a pain (as it needs to disable lots of rules that are very valid in other cases).

Environment data

iOS version: e.g. iOS 15.4

Nextcloud iOS app version: 4.3.1

Server operating system: Debian Bullseye, Nextcloud docker image

Web server: Nginx

Database: Postgres

Nextcloud version: 22.2.6

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