Skip to content

fix(http): neutralize client-controlled upload tmp_name in Swoole adapter - #14897

Merged
ChiragAgg5k merged 5 commits into
appwrite:mainfrom
ChiragAgg5k:fix/swoole-upload-file-marker
Oct 24, 2026
Merged

ChiragAgg5k merged 5 commits into
appwrite:mainfrom
ChiragAgg5k:fix/swoole-upload-file-marker

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Neutralizes client-controlled Swoole upload paths in the HTTP adapter. This closes an arbitrary file read and an arbitrary file deletion against Swoole-based consumers such as Appwrite.

The bug. Swoole's multipart parser trusts an internal part header, Swoole-Upload-File: <path> (swoole/swoole-src#6309, originally #6161/#6162). Any remote client can send it, and Swoole then:

  • reports the part as a completed upload whose tmp_name is the client-chosen path (error: 0, real size of the target);
  • registers that path for is_uploaded_file(), so Utopia\Storage\Validator\Upload accepts it and the file's contents are stored and served back to the attacker (e.g. /etc/passwd);
  • adds the path to $request->tmpfiles, which Swoole unlink()s when the request object is freed. In the API container (uid 0), one unauthenticated multipart request to any route deletes the target file.

Upstream status. Fixed on Swoole master (#6309, commit 0306f5360, requires the new upload_preprocessed context), but not in any released version: 6.2.x (we run 6.2.3) is unguarded.

The fix. The adapter constructor reads every Swoole-Upload-File header value from the raw multipart body (Swoole matches the name case-insensitively at the start of a header line, and so does the scan). Any entry in Swoole's tmpfiles list equal to one of those values is:

  • removed from tmpfiles, so Swoole no longer unlinks it;
  • blanked in files (tmp_name: '', error: UPLOAD_ERR_CANT_WRITE, size: 0), walking nested name[] / name[0][part] entries with their matching error / size trees.

Matching is exact, so a marker that names another request's in-flight swoole.upfile.* is caught too. Genuine uploads, ordinary failed uploads (e.g. UPLOAD_ERR_NO_FILE), and files whose content merely contains the marker text are left untouched. The spoofed path stays in the worker's rfc1867_uploaded_files table (it can't be cleared from PHP), but no consumer receives it anymore.

Also fixes the Checks / Workflows lane (failing on main too): the docker/login-action v4 tag moved to v4.7.0, so zizmor flagged the pinned v4.6.0 hash's # v4 comment.

Test plan

Regression tests run the real Swoole parser (SwooleRequest::parse()) against a fixture file, never system files:

  • a spoofed marker is reported by Swoole, blanked by the adapter, dropped from tmpfiles, and the target survives the request being freed;
  • a mixed-case marker inside file[0][part] is dropped while the genuine sibling stays an upload and an empty file part keeps UPLOAD_ERR_NO_FILE;
  • a genuine upload whose content contains the marker text stays intact.

The first two fail with the constructor hook disabled. The package unit suite (161 tests) is green under Swoole 6.2.3, and bin/monorepo check http (Pint, PHPStan max, Rector) passes. A real Swoole\Http\Server probe confirmed markers naming /tmp/victim and an existing /tmp/swoole.upfile.abc123 are blanked and both files survive, while normal uploads still work and are cleaned up.

Example request reproducing the bug

POST /v1/storage/buckets/{bucketId}/files HTTP/1.1
Host: target
Content-Type: multipart/form-data; boundary=----bnd

------bnd
Content-Disposition: form-data; name="fileId"

some-id
------bnd
Content-Disposition: form-data; name="file"; filename="x.txt"
Content-Type: text/plain
Swoole-Upload-File: /etc/passwd

DECOY
------bnd--

The response carries the server's /etc/passwd as the uploaded file's content, and the file is then deleted from the container.

Related: appwrite-labs/cloud#6674

…pter

Swoole's multipart parser honors an internal `Swoole-Upload-File` part
header and pins part metadata to a client-chosen `tmp_name` with
`error: 0` and the real size of the target file
(swoole/swoole-src#6309). Because `is_uploaded_file()` trusts Swoole
metadata, a remote unauthenticated request can make upload-handling code
read an arbitrary server-local file (e.g. /etc/passwd) as if it were a
standard multipart upload. No released Swoole version contains the
upstream fix yet (`upload_preprocessed` lands with 6.3/master).

The Swoole adapter is the single choke point: genuine uploads are always
written to `<upload_tmp_dir>/swoole.upfile.XXXXXX`, so getFiles() now
rejects any `tmp_name` outside those directories/that naming scheme,
neutralizing spoofed entries into UPLOAD_ERR_CANT_WRITE with no size,
while real uploads (flat or bracketed list form) pass through untouched.

Parser-level regression tests cover the spoofed marker through
SwooleRequest::parse(), genuine uploads, mixed lists, wrong-dir and
nonexistent paths.
@ChiragAgg5k ChiragAgg5k self-assigned this Oct 23, 2026
@ghost

ghost commented Oct 23, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental change is documentation-only and introduces no behavior that needs fixing.

The PR hardens the Swoole HTTP adapter against client-supplied Swoole-Upload-File paths by removing spoofed paths from Swoole cleanup and neutralizing matching upload metadata, including nested fields. It adds parser-backed regression tests for spoofed and genuine uploads, and updates the Docker login-action version annotations in the Console workflows. The latest commit documents when the temporary upload guard can be removed.

Latest changes: The newest commit adds a note to dropSpoofedUploads() to remove the guard and marker scan once a released Swoole version containing the upstream fix is required.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
packages/http/src/Adapter/Swoole/Request.php Detects client-controlled multipart upload paths, removes them from Swoole cleanup, and neutralizes matching upload metadata; the latest commit documents the guard’s removal condition.
packages/http/tests/SwooleRequestTest.php Adds real-parser regression coverage for spoofed, nested, and genuine multipart uploads.
.github/workflows/console-production.yml Updates Docker login-action version annotations in the production Console workflow.
.github/workflows/console-staging.yml Updates Docker login-action version annotations in the staging Console workflow.

Reviewed the commits since f41077f · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Tier A · See the inline comments. Summary

Sanitizing only the getFiles() copy left the spoofed path in Swoole's
tmpfiles list, which Swoole unlinks when the request is freed, so the
marker still deleted arbitrary files. Scrub tmpfiles and files once in
the constructor, walk nested bracketed entries, keep the errors of
ordinary failed uploads, and require the exact upload directory.
The v4 tag moved to v4.7.0, so zizmor flagged the pinned v4.6.0 hash as
carrying a mismatched version comment.
ghost
ghost previously requested changes Oct 23, 2026

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Tier B · 1 blocking finding to address. Summary

A marker naming another request's in-flight swoole.upfile passed the
name and directory checks. The raw body carries every marker, so match
those values exactly and drop the path heuristics and their tests.
@ghost
ghost dismissed their stale review October 23, 2026 17:56

The findings that requested changes are resolved. See the summary comment for what is still open.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@ChiragAgg5k
ChiragAgg5k merged commit 1d15ef8 into appwrite:main Oct 24, 2026
68 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/swoole-upload-file-marker branch October 24, 2026 11:12
Tapraj-Pathak pushed a commit to Tapraj-Pathak/appwrite that referenced this pull request Oct 24, 2026
…file-marker

fix(http): neutralize client-controlled upload tmp_name in Swoole adapter

(cherry picked from commit 1d15ef8)
sarbojitrana pushed a commit to sarbojitrana/appwrite that referenced this pull request Nov 2, 2026
…lues (backport appwrite#14897, appwrite#14792)

Swoole accepts a Swoole-Upload-File part header as a ready temp file, so a client could name any server path as its upload and have it unlinked. The framework also calls any callable argument, so a request value such as ["Class", "method"] ran as code. The 1.9 dependency set caps utopia-php/http below the releases that fix both, so the request wrapper applies the guards.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants