Skip to content

web: require same-app origin for session-changing requests and store unknown upload types as downloads - #4345

Merged
richiemcilroy merged 3 commits into
mainfrom
fix/web-same-app-writes-upload-types
Nov 18, 2026
Merged

richiemcilroy merged 3 commits into
mainfrom
fix/web-same-app-writes-upload-types

Conversation

@richiemcilroy

@richiemcilroy richiemcilroy commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Two small changes to how the web app treats requests and uploads that come from places other than the app itself.

Same-site cookie writes must come from the app

isCrossSiteCookieWrite decides whether a non-GET request may use the session cookie. When the browser sent Sec-Fetch-Site: same-site, it accepted the write without looking at Origin. But same-site covers every sibling subdomain of the app's domain, not just the app. It now also needs an Origin that is the app itself or its www counterpart.

flowchart TD
    A[cookie write] --> B{Sec-Fetch-Site}
    B -- cross-site --> X[no cookie user]
    B -- same-origin / none --> OK[cookie user]
    B -- same-site --> C{Origin is the request host,<br/>WEB_URL, or WEB_URL's www counterpart<br/>on the same scheme?}
    C -- yes --> OK
    C -- no, null or missing --> X
    B -- absent --> D[unchanged Origin fallback]
Loading
  • packages/database/auth/request-site.ts:38 isOwnSiteOrigin, used only for same-site at :63.
  • Behaviour is unchanged for cross-site, same-origin, none, requests without fetch metadata (plain-http self-hosted installs), and anything authenticated with a bearer key. The desktop app, the iOS app, the CLI and the Chrome extension all use bearer keys and send no Sec-Fetch-Site.
  • Custom share domains and preview deployments post to their own host, which is same-origin and not affected.
  • One check covers every caller: the Hono withAuth/withOptionalAuth wrappers, the Effect HttpApi and RPC auth middleware, and the App Router routes that call it directly. Server actions don't go through it.

Uploads keep only media content types

Multipart /initiate and mobile upload create stored whatever contentType the client sent, and the media host serves objects with their stored type. Now, anything that isn't audio, video or a raster image is stored as application/octet-stream.

toStoredUploadContentType("video/webm;codecs=vp9,opus"); // unchanged
toStoredUploadContentType("audio/mp4");                  // unchanged
toStoredUploadContentType("image/png");                  // unchanged (jpeg, png, gif, webp)
toStoredUploadContentType("text/html");                  // "application/octet-stream"
toStoredUploadContentType("image/svg+xml");              // "application/octet-stream"
  • apps/web/lib/media-processing-policy.ts:80, applied at apps/web/app/api/upload/[...route]/multipart.ts:140 (replacement upload), :243 (normal upload) and apps/web/app/api/mobile/[...route]/route.ts:3430.
  • Unknown types are normalized, not rejected, so no client gets a new error.
  • First-party uploads keep their real types: desktop sends video/mp4, the web recorder and the extension send their MediaRecorder type (video/webm or video/mp4), and iOS sends video/* or a png/jpeg screenshot. iOS PUTs with the Content-Type header returned by the server, so the signed type and the sent type always match.
  • Loom import and the signed, comment-media and developer upload routes set their types server-side and aren't touched.
  • Objects that are already stored keep their stored type.

RetriggerView in GreptileConfidence Score: 5/5

The latest commit appears safe to merge.

Summary

The latest commit preserves the download type when ordinary S3 uploads finish, addressing the previously reported page.html case.

  • Same-site cookie writes now need an origin from the app.
  • Unknown upload types now reach the media host as downloads.

No new actionable issues were found.

Reviews (2) · Last reviewed commit: "fix(web): keep the download type when co..." · Reviewed by Greptile

@vercel
vercel Bot temporarily deployed to Preview – cap-status November 18, 2026 02:24 Inactive
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
cap-status Skipped Skipped Nov 18, 2026 2:51am UTC

@capy-ai capy-ai Bot 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.

Capy found no issues.

Open in Capy

Completion copies the object onto itself and set video/mp4 on every upload. It now keeps application/octet-stream when that was stored at the start and the key does not name a video file; every other upload still completes as video/mp4.
@vercel
vercel Bot temporarily deployed to Preview – cap-status November 18, 2026 02:51 Inactive
@richiemcilroy

Copy link
Copy Markdown
Member Author

@greptileai please re-review the latest commit.

@sandchest-com

sandchest-com Bot commented Nov 18, 2026

Copy link
Copy Markdown

Sandchest

Sandchest reviewed 53a063e: nothing exploitable found in this change.

Sandchest reviews every change for vulnerabilities an attacker could use · Review details

@capy-ai capy-ai Bot 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.

Capy found no issues.

View 2 other findings in Capy.

Open in Capy

@richiemcilroy
richiemcilroy merged commit 0f73981 into main Nov 18, 2026
41 checks passed

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cap-web — 53a063e7 Deployed Nov 18, 2026 by vercel[bot]
Preview – cap-status — 53a063e7 Deployed Nov 18, 2026 by vercel[bot]
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