Skip to content

File uploads Since v0.1 ​

File protection checks the files clients upload, on the paths you name. It finds the type by content, never by the file name, and refuses files that are not what they claim: a script named photo.jpg, a script hidden in an image, a web shell, an archive bomb or a file on a hash deny list. It can also send files to an antivirus server over ICAP.

Before you begin ​

  • Role: operator for the application. Adding antivirus servers needs admin with access to every application; shared hash lists need operator with access to every application.
  • The application's request body limit applies first. For upload paths, raise it with an exception (limits: {request_body: 12MiB}, at most 64 MiB), or the upload is refused with file.limit before its files are checked.
  • For antivirus: an ICAP server you run yourself (for example ClamAV behind c-icap) that the inspection nodes can reach.

Add an upload rule ​

Only the paths of the rules are checked. Requests elsewhere are not touched. Start in detect: events show what would be refused.

text
1. Open Applications > All applications > the application > Request checks > File uploads.
2. On the Checks and hash lists tab, set Protection mode to detect.
3. On the Upload rules tab, add a rule: paths, allowed and refused types, largest file, where the files are.
4. Select Preview changes, add a comment and select Apply.
sh
waap files set -app shop -m "file uploads" mode=detect
waap files list set -app shop -list rules -f rules.yaml -m "upload rule"
yaml
# rules.yaml (waap files list set), or applications[].policy.files.rules
- paths: ["/upload/*"]
  allow: [image, pdf]
  deny: [executable, script]
  max_size: 5MiB
  archives: inspect

An allow or deny entry is a family (image, pdf, office, text, archive, audio, video, executable, script) or an exact type such as image/svg+xml. The console offers the families as checkboxes.

Say where the files are ​

WhereHow
Multipart formsalways checked
The whole body is the file (PUT, application/octet-stream)raw: true
Base64 file contents in JSONjson_fields with JSON pointers such as /document/content

A raw body sent as a form, JSON or XML is still inspected as arguments by signatures. Any other raw body is one file, judged by this module.

Open archives ​

archives: inspect opens zip, tar and gzip uploads and checks every member. Bombs are refused: deep nesting, more than 1,000 members, or an unpacked size over 10 times the file. Encrypted members are refused unless encrypted: allow.

Choose the checks ​

Each check is off, log or block: mismatch (the content contradicts the name or declared type), scripts (script markers at the start of an image or PDF), names (.htaccess, web.config, double extensions such as x.php.jpg, path separators) and webshells.

text
1. On the Checks and hash lists tab, set each check to off, log or block.
2. Select Preview changes, then Apply.
sh
waap files set -app shop -m "checks" webshells=block names=log
yaml
files:
  mismatch: block
  scripts: block
  names: block
  webshells: block

Try a file first ​

The Test a file tab checks a file as if uploaded to a path. It shows the type found, the SHA-256 (to add to a list) and what each check finds. Nothing is sent to the application.

sh
waap files test -app shop -path /upload/avatar -f photo.jpg

Use hash lists ​

A file list holds SHA-256 values, written in the list or fetched from an https URL by the active node (one value per line, or sha256sum output). Name lists under Refused hashes (hash_lists.deny) or Trusted hashes (hash_lists.allow: the other checks are skipped for them). A list in use cannot be removed.

text
1. Open Shared lists > File lists and add a list: values, or a URL with a refresh time.
2. Select Preview changes, then Apply.
3. In the application's Checks and hash lists tab, name the list under Refused hashes or Trusted hashes.
4. For a URL list, select Fetch now to download it at once.
sh
waap file-lists set -f lists.yaml -m "hash lists"
waap file-lists refresh -name badfiles
waap files set -app shop -m "deny hashes" hash_lists.deny=badfiles
yaml
# file_lists (shared)
- name: badfiles
  url: https://intel.example.com/hashes.txt
  refresh: 6h

The table shows each list's count, last fetch and last error. The last good copy is kept when a fetch fails.

Scan files with an antivirus server ​

Two steps. First an administrator adds the server. Then each application uses it.

text
1. Open System > Settings > Antivirus servers and add a server: a name and its icap:// or icaps:// URL.
2. For TLS, upload a CA bundle and, for mutual TLS, a client certificate in the TLS files of a server form. The key is never shown again.
3. Select Test to send the harmless EICAR string and a clean file through the inspection node's own connection.
4. In the application, open File uploads > Checks and hash lists > Antivirus (ICAP), choose the ICAP server and set the options.
sh
waap icap set -f servers.yaml -m "antivirus"
waap icap test -name av
waap files set -app shop -m "scan uploads" icap.server=av
yaml
# icap_servers (shared)
- name: av
  url: icap://av.internal/avscan

Run the test after adding a server and after changing its TLS files: EICAR must be reported infected and the clean file clean. The table shows each server's state (reachable, failing, not applied yet), last scan, latency and last error.

What is sent: each file once, decoded (also base64 in JSON), inside a synthetic request that carries only the method, path, host and declared type. Cookies and credentials never reach the antivirus server. Files already refused by another check, and files on a trusted list, are not sent. Verdicts are remembered for an hour per server signature version.

The data plane waits for the scan, up to the server's timeout, so users see a slower upload, not an error. Large files and archives take longest.

Events

file.av.infected is always refused in block mode. file.av.unavailable (server unreachable, busy or too slow) is refused with 503 when the failure mode is closed, and reported when open. file.av.not_scanned is a file larger than Largest file scanned, or more than 32 files in one request.

Settings reference ​

General and checks ​

SettingWhat it doesDefaultAllowed valuesApplies in
File protection (policy.files.enabled)Checks files on the upload rules' paths.truetrue, falseall
Protection mode (mode)detect reports; block refuses.empty (same as the application)detect, block, emptydetect wins
Content contradicts name or type (mismatch)The content is not what the name or type says.blockoff, log, blockblock mode
Scripts hidden in images and documents (scripts)Script markers (<?php, <%, <script, #!) at the start of an image or PDF.blockoff, log, blockblock mode
Dangerous file names (names).htaccess, web.config, double extensions, path separators, NUL bytes.blockoff, log, blockblock mode
Web shells (webshells)Text files and archive members that look like web shells.blockoff, log, blockblock mode
Refused hashes (hash_lists.deny)File lists whose SHA-256 values are refused.nonenames of defined listsall
Trusted hashes (hash_lists.allow)File lists whose files skip the other checks.nonenames of defined listsall

Upload rule ​

SettingWhat it doesDefaultAllowed valuesApplies in
pathsPaths the rule checks.none (required)1 to 64; exact or prefix ending in *all
max_sizeLargest file.10MiB1 byte to 64MiBall
allow, denyTypes accepted or refused.noneup to 64 families or typesall
json_fieldsJSON pointers to base64 file contents.noneup to 16 pointersall
rawThe whole body is the file.falsetrue, falseall
archivesOpen archives.skipskip, inspectall
encryptedEncrypted archive members.blockallow, blockarchives: inspect

Antivirus (ICAP) ​

SettingWhat it doesDefaultAllowed valuesApplies in
ICAP server (icap.server)The server that scans files.none (files are not sent)name of a defined serverall
Largest file scanned (icap.max_size)Larger files are not sent.32MiBup to 64MiBserver set
Files too large to scan (icap.oversize)What happens to a larger file.blockblock, allow (reported as not scanned)server set
Server unavailable (icap.on_failure)What happens when it cannot be used.inheritinherit (the application's failure policy), open, closedserver set
Scan archive members (icap.members)Also send members, for servers that do not unpack archives.falsetrue, falseserver set

ICAP server (shared) ​

SettingWhat it doesDefaultAllowed valuesApplies in
nameIdentifies the server.none (required)unique nameall
urlWhere it is.none (required)icap://host[:1344]/service or icaps://host[:11344]/serviceall
timeoutBounds one scan.10sup to 61sall
max_concurrentScans in flight per inspection node.32up to 256all

File list (shared) ​

SettingWhat it doesDefaultAllowed valuesApplies in
nameIdentifies the list.none (required)unique nameall
sha256Inline values.noneup to 10,000not with url
urlFetches the values.nonehttps URLnot with inline values
refreshHow often it is fetched.1h5m to 168hurl only

Examples ​

Accept only images and PDFs on the upload path, scan with ClamAV, refuse above 5 MiB:

yaml
files:
  mode: block
  icap: {server: av, on_failure: open}
  rules:
    - paths: ["/upload/*"]
      allow: [image, pdf]
      max_size: 5MiB

Limits ​

LimitValue
Upload rules per application64, each with up to 64 paths
File lists200
ICAP servers16
Files sent to an antivirus per request32
Archives1,000 members; unpacked size at most 10 times the file
Metricswaap_file_findings_total{app,rule,action}, waap_icap_requests_total{server,result}, waap_icap_duration_seconds

Events have rule IDs file.*, naming the file (sanitised), the field, the type found and declared, the size and the SHA-256, and the archive member. File content is never kept: an event's request capture omits a body that carries files (body_omitted: files).

Troubleshooting ​

Uploads fail with file.limit ​

  • Cause: the request body limit is smaller than the upload.
  • Fix: raise the limit for the upload path with an exception, up to 64 MiB.

file.av.unavailable events ​

  • Cause: the ICAP server is unreachable, busy or too slow.
  • Check: the server's state and last error in System > Settings > Antivirus servers, then Test.
  • Fix: repair the server, raise timeout or max_concurrent, or choose open for Server unavailable.