Skip to content

fix(deployments): read downloads through the handle that was checked - #15022

Merged
ChiragAgg5k merged 2 commits into
mainfrom
fix/download-handle
Oct 27, 2026
Merged

ChiragAgg5k merged 2 commits into
mainfrom
fix/download-handle

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Downloads checked the local artifact path and then reopened it for every chunk, so a build could swap the file in between. The file is now opened once, kept only when the opened file is the one at the checked path, and every range and chunk is read from that handle.

Lint, PHPStan and the touched unit tests passed locally before rebasing on main; e2e runs in CI.

Related: appwrite-labs/cloud#6673

Downloads checked the local artifact path and then reopened it for every
chunk, so a build could swap the file in between. The file is now opened
once, kept only when the opened file is the one at the checked path, and
every range and chunk is read from that handle.
@luxor-code-review

luxor-code-review Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


The change closes a TOCTOU window in deployment downloads: instead of re-reading by path after the safety check, local artifacts are opened once and validated against the path via fstat/lstat inode comparison, so a later link swap cannot redirect reads. Both Functions and Sites download endpoints switch to a shared read() helper that streams through the pinned handle for local devices and keeps the old path-based read for remote devices.

Files Change
src/Appwrite/Deployment/Deployments.php Adds openArtifact(): opens the local file and pins the checked inode via dev/ino comparison before returning the stream.
src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php Uses openArtifact() for local devices and a new read() helper for range/chunked/full-body sends.
src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php Same pattern mirrored from the Functions download endpoint.
tests/unit/Deployment/DeploymentsTest.php Regression test covering symlink/missing/outside-root refusals and the link-swap-after-open scenario.

Reviewed commit: e4f9ac5

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 27, 2026
@ghost

ghost commented Oct 27, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

Local deployment downloads open a validated artifact once and use that stream for range and chunk reads, preventing path swaps between checks and reads. Function and Site handlers retain device-based reads for non-local storage. A unit test covers artifact validation and reading the opened file after its path is replaced.

Latest changes: The newest commit imports StreamInterface and strengthens the artifact test to assert that the opened value implements that stream contract.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
src/Appwrite/Deployment/Deployments.php Adds a helper that opens a validated local deployment artifact as a stream.
src/Appwrite/Platform/Modules/Functions/Http/Deployments/Download/Get.php Reads local function deployment downloads through the opened artifact stream.
src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php Reads local site deployment downloads through the opened artifact stream.
tests/unit/Deployment/DeploymentsTest.php Covers artifact validation and reading the opened artifact after the path is replaced; asserts the stream interface.

Reviewed the commits since e4f9ac5 · 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 S · Looks good to merge. Summary

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/download-handle (after).

Metric Before After Change
🚀 Requests/sec 207.02 204.08 ⚪ -1.4%
⏱️ Latency P50 84.68 ms 84.73 ms ⚪ +0.1%
⏱️ Latency P95 189.25 ms 199.12 ms 🔴 +5.2%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 84.73 199.12 12,540 204.08 +9.87
Account 165.21 300.93 660 11.53 +17.23
TablesDB 80.47 150.37 6,820 114.58 -2.95
Storage 82.45 193.07 3,300 56.66 +14.88
Functions 116.22 231.3 1,760 30.98 +17.66

Top API waits (after)

API request Max wait (ms)
account.name.update 488.48
account.prefs.update 446.92
tablesdb.rows.create 377.92
account.get 373.51
functions.variables.update 366.96

@ChiragAgg5k
ChiragAgg5k merged commit 7d9fea6 into main Oct 27, 2026
117 of 119 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/download-handle branch October 27, 2026 19:18
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.

1 participant