Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

WAF Malicious Upload Detection, Content Scan Fields, and Custom Rules

How edge WAF content scanning finds malware in uploads, which rule fields to use, limits on multipart bodies, and how to block or log infected files.

This page summarises Cloudflare documentation on malicious uploads detection (WAF content scanning): scanning uploaded files and other content objects at the edge, exposing results as Rules language fields, and acting on them with custom rules—not blocking by itself.

Malicious uploads detection: what it does on incoming traffic

Section titled “Malicious uploads detection: what it does on incoming traffic”

Malicious uploads detection is a traffic detection that scans files and other content uploaded to your application for malware.

The malicious uploads detection is a traffic detection that scans files and other content uploaded to your application for malware.

— Cloudflare, Malicious uploads detection

When the feature is on, the WAF inspects incoming uploads and checks them for malicious signatures. Scan results are available as fields you can use in custom rules and rate limiting rules. It is available on an Enterprise plan with a paid add-on; see Get started and WAF get started.

Enabling scanning can add latency because content objects are scanned; latency varies with object size (Get started).

How content scanning works: buffering, AV scan, and rule fields

Section titled “How content scanning works: buffering, AV scan, and rule fields”

Once you turn on this detection, Cloudflare inspects incoming traffic and identifies content objects automatically. When Cloudflare detects one or more content objects in a request, it sends them to an antivirus (AV) scanner—the same one used in Cloudflare Zero Trust.

When Cloudflare detects one or more content objects in a request, it sends them to an antivirus (AV) scanner for analysis. The AV scanner is the same one used in Cloudflare Zero Trust.

— Cloudflare, Malicious uploads detection — How it works

Cloudflare buffers upload content at the edge for scanning before forwarding it to your origin. For large uploads, slow forwarding to the origin can delay the request long enough for the connection to time out.

Based on scan results, the detection populates cf.waf.content_scan.* fields for rule expressions—for example, block malicious files or match on file size, type, or URI path (Example rules).

The Cloudflare Security Architecture notes that when Uploaded Content Scanning is enabled, scan results and metadata are exposed as WAF custom rule fields for fine-grained mitigation.

What counts as a content object (not every request body)

Section titled “What counts as a content object (not every request body)”

A content object is a file or binary payload Cloudflare treats as scannable content. Identification uses heuristics and does not rely on Content-Type, which can be manipulated.

Excluded from scanning: text/html, text/x-shellscript, application/json, text/csv, and text/xml. Other detected content is treated as a content object—executables, documents, archives, images, audio, and video (Malicious uploads detection — What is a content object?). If type cannot be determined, cf.waf.content_scan.obj_types may report application/octet-stream (cf.waf.content_scan.obj_types).

Scanned locations include:

For multipart parsing in rules (separate from the scanner), Enterprise plans expose fields such as http.request.body.multipart and http.request.body.multipart.filenames; body fields share plan-specific size limits (128 KB on Enterprise for http.request.body.* values—see field docs).

Content scan size limit: 50 MB, multipart boundaries, and cf.waf.content_scan.truncated

Section titled “Content scan size limit: 50 MB, multipart boundaries, and cf.waf.content_scan.truncated”

The content scanner inspects up to the first 50 MB of a request body. Multiple objects in one form share that 50 MB budget.

The content scanner inspects up to the first 50 MB of a request body. When a request contains more than one content object, for example a submitted HTML form with several file inputs, all the content objects share this 50 MB.

— Cloudflare, Malicious uploads detection — Size limit

For multipart bodies larger than 50 MB total, objects entirely within the first 50 MB are scanned; an object straddling the boundary and anything after it are not scanned—and those unscanned objects are not reflected in cf.waf.content_scan.num_obj, obj_results, or has_failed. A partly scanned request can look like a fully clean scan.

Use cf.waf.content_scan.truncated to detect these requests and decide how to handle them.

— Cloudflare, Malicious uploads detection — Size limit

cf.waf.content_scan.truncated is true when the body exceeded the scanning size limit and results may be incomplete. cf.waf.content_scan.has_failed means the scanner attempted but could not complete analysis on some objects—it is not set for content never reached because of the 50 MB cap.

When ruling on files at the 50 MB cap, Example rules document that objects at or above 52,428,800 bytes are reported at that size, so use >= not > for “over 50 MB” style rules.

Password-protected uploads: cf.waf.content_scan.has_encrypted_obj

Section titled “Password-protected uploads: cf.waf.content_scan.has_encrypted_obj”

The scanner detects password-protected objects for ZIP, RAR, PDF, and Microsoft Office types. It cannot judge whether encrypted content is malicious; obj_results reports not scanned, and has_failed is not set for encrypted content alone (Encrypted content).

cf.waf.content_scan.has_encrypted_obj is true when at least one encrypted object is present—useful to block encrypted uploads on sensitive paths.

The AV scanner also skips archives with more than three recursion levels, archives with more than 300 files, and PGP-encrypted files (Size limit notes).

cf.waf.content_scan fields: meanings for WAF custom rules

Section titled “cf.waf.content_scan fields: meanings for WAF custom rules”

When content scanning is enabled, these fields appear in WAF rule expressions (Content scanning fields, field reference pages):

Field Type Role in rules
cf.waf.content_scan.has_obj Boolean At least one content object
cf.waf.content_scan.has_malicious_obj Boolean At least one malicious object
cf.waf.content_scan.num_malicious_obj Integer Count of malicious objects
cf.waf.content_scan.num_obj Integer Count of detected objects
cf.waf.content_scan.obj_results Array clean, suspicious, infected, not scanned (per object, in detection order)
cf.waf.content_scan.obj_types Array MIME types per object
cf.waf.content_scan.obj_sizes Array Sizes in bytes per object
cf.waf.content_scan.has_failed Boolean Scan attempted but did not complete for some objects
cf.waf.content_scan.truncated Boolean Body exceeded scan size limit
cf.waf.content_scan.has_encrypted_obj Boolean Password-protected object present

cf.appsec.request.failed_detections can list waf_content_scan when content scanning reports a failure, so you can branch on detection failures before or alongside has_failed (array order not guaranteed; the field defaults to an empty array).

Managed transform: Malicious-Uploads-Detection request header

Section titled “Managed transform: Malicious-Uploads-Detection request header”

The Add malicious uploads detection header managed transform adds a request header summarising the scan:

Header value Meaning
Malicious-Uploads-Detection: 1 Malicious object (cf.waf.content_scan.has_malicious_obj true)
Malicious-Uploads-Detection: 2 Scan failed for some objects (cf.waf.content_scan.has_failed true)
Malicious-Uploads-Detection: 3 At least one content object (cf.waf.content_scan.has_obj true)

Use this when the origin or downstream services need a simple signal without evaluating Rules language at the app layer.

Turn on malicious uploads detection: dashboard and API

Section titled “Turn on malicious uploads detection: dashboard and API”
  1. In the Cloudflare dashboard, open Security → Settings, filter by detection tools if needed, and turn on Malicious uploads detection (Get started).

  2. Confirm the zone status with the API (Common API calls — Get WAF content scanning status); use the GET example in the next subsection.

  3. Validate with Security Analytics and HTTP logs; the EICAR anti-malware test file (ZIP format) is commonly used for tests.

  4. Add a Log action rule with (cf.waf.content_scan.has_obj) before switching to Block, so security events prove fields populate as expected (Get started — Validate).

Confirm settings with the API (Common API calls — Get WAF content scanning status):

curl "https://api.cloudflare.com/client/v4/zones/\$ZONE_ID/content-upload-scan/settings" \
--request GET \
--header "Authorization: Bearer \$CLOUDFLARE_API_TOKEN"

To enable via API (Common API calls):

curl "https://api.cloudflare.com/client/v4/zones/\$ZONE_ID/content-upload-scan/enable" \
--request POST \
--header "Authorization: Bearer \$CLOUDFLARE_API_TOKEN"

Terraform examples use cloudflare_content_scanning (Terraform configuration examples).

Custom scan expressions: Base64 in JSON and nested payloads

Section titled “Custom scan expressions: Base64 in JSON and nested payloads”

Default heuristics may miss file bytes inside JSON. Add a custom scan expression so the scanner knows where to read content—for example a Base64 string in a file property:

{ "file": "BASE64_ENCODED_STRING" }

The content scanner will automatically decode Base64 strings.

— Cloudflare, Malicious uploads detection — Custom scan expressions

Configure in the dashboard under Malicious uploads detection → Configurations → Add content location, or POST to the zone payloads API (Get started, Common API calls — Add a custom scan expression):

curl "https://api.cloudflare.com/client/v4/zones/\$ZONE_ID/content-upload-scan/payloads" \
--request POST \
--header "Authorization: Bearer \$CLOUDFLARE_API_TOKEN" \
--json '[{"payload": "lookup_json_string(http.request.body.raw, \"file\")"}]'

Example expression: lookup_json_string(http.request.body.raw, "file") (Get started). http.request.body.raw supplies the unaltered body (subject to plan body limits for rule evaluation).

WAF custom rules: block malicious uploads by path, type, and size

Section titled “WAF custom rules: block malicious uploads by path, type, and size”

Start with a broad block on malicious objects (Get started):

(cf.waf.content_scan.has_malicious_obj)

Narrow scope with path and other fields (Example rules):

Scenario Example expression
Block malware on /upload.php cf.waf.content_scan.has_malicious_obj and http.request.uri.path eq "/upload.php"
Allow only PDFs on /upload any(cf.waf.content_scan.obj_types[*] != "application/pdf") and http.request.uri.path eq "/upload"
Reject files over 500 KB any(cf.waf.content_scan.obj_sizes[*] > 512000) and http.request.uri.path eq "/upload"
Reject incomplete scan at size cap any(cf.waf.content_scan.obj_sizes[*] >= 52428800) (use >=)
Block when scan truncated cf.waf.content_scan.truncated and http.request.uri.path eq "/upload"
Log any upload object cf.waf.content_scan.has_obj (action: Log)

Combine with bot signals—for example uploads from low bot scores (Get started): cf.waf.content_scan.has_obj and cf.bot_management.score lt 10 (requires Enterprise Bot Management; see cf.bot_management.score context in bot field docs).

Terraform can deploy a block rule with cf.waf.content_scan.has_malicious_obj (Terraform configuration examples).

Common mistakes when writing content-scan rules

Section titled “Common mistakes when writing content-scan rules”
  • Assuming scanning blocks by default—it only sets fields until a rule acts (Malicious uploads detection).
  • Treating clean field values as proof the entire body was scanned—check cf.waf.content_scan.truncated on large multipart uploads.
  • Using has_failed for objects beyond the 50 MB window—they are omitted from counts and arrays, not flagged as failed.
  • Blocking on has_malicious_obj only: suspicious and infected both count as malicious per product behaviour described in Get started (rule matches “suspicious or malicious”); use obj_results when you need finer gradations.
  • Relying on Content-Type alone; scanning uses content heuristics instead (What is a content object?).
  • Forgetting add-on and Enterprise requirements before enabling API or dashboard toggles (Get started).
  1. Confirm Malicious uploads detection is enabled under Security Settings and the content-upload-scan settings API returns an enabled state for your zone.
  2. Upload the EICAR test file to an endpoint covered by your upload paths; review Security Analytics for matched custom rules.
  3. Run a Log rule with (cf.waf.content_scan.has_obj) and confirm obj_types, obj_sizes, and obj_results in sampled HTTP or security logs match the uploaded file.
  4. Upload a file larger than 50 MB or a multipart form that exceeds the cap and verify cf.waf.content_scan.truncated behaves as documented in Size limit.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about, and we will correct or clarify it.