Skip to content

execute: send the upload JWT to the asset upload endpoints - #429

Open
acoyfellow wants to merge 4 commits into
cloudflare:mainfrom
acoyfellow:fix/execute-asset-upload-jwt
Open

acoyfellow wants to merge 4 commits into
cloudflare:mainfrom
acoyfellow:fix/execute-asset-upload-jwt

Conversation

@acoyfellow

@acoyfellow acoyfellow commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

execute replaced the upload JWT with the MCP session token on the static asset upload endpoints, which only accept the upload JWT. Pages direct upload failed at check-missing with 403 8000013 Authorization failed, and Workers asset uploads could not work. Fixes #386. Fixes #389.

What changed

  • Send the caller's upload JWT on the four asset upload POSTs (/pages/assets/check-missing, /pages/assets/upload, /pages/assets/upsert-hashes, /accounts/{id}/workers/assets/upload). Everything else keeps the session token.
  • From Fix Pages and Workers static asset uploads in Code Mode #439 by @irvinebroque (cherry-picked, his authorship kept): fail closed. A missing, malformed, expired or session-token bearer on those POSTs is refused without sending. No redirects followed, no retries, no OAuth scope prompt for upload refusals. The API base check now compares origin and base path, not just hostname.
  • Added here after testing Fix Pages and Workers static asset uploads in Code Mode #439 on staging: Workers assets-upload-session returns a JWT prefixed cfwau_ (cfwau_eyJ...). Fix Pages and Workers static asset uploads in Code Mode #439's check decoded cfwau_eyJ... as the header and refused the real token, so Workers uploads were still blocked. One optional cfwau_ prefix is now stripped before the check; the token is sent unchanged.

Proof (staging, execute)

Before (main):

Pages:   check-missing (upload JWT): HTTP 403 {"code":8000013,"message":"Authorization failed"}

With #439 only (d22ac98):

Pages:   check-missing / upload / upsert-hashes: ok, deployment: ok
Workers: assets/upload (upload JWT): request not sent, "requires an upload JWT"

This PR (d5618a5):

Pages:   check-missing / upload / upsert-hashes (upload JWT): ok
         create deployment (session): ok
         no JWT / not a JWT: request not sent
Workers: assets-upload-session (session): ok
         assets/upload (cfwau_ upload JWT): ok
         upload script with assets (session): ok

Reproduce

In execute against staging:

  1. Pages: create a project, GET .../pages/projects/<name>/upload-token, then POST /pages/assets/check-missing with Authorization: Bearer <jwt>.
  2. Workers: POST .../workers/scripts/<name>/assets-upload-session, then POST /accounts/<id>/workers/assets/upload?base64=true with Authorization: Bearer <result.jwt>.

Tests

  • tests/asset-upload-token.test.ts: a cfwau_ JWT is kept with its prefix (fails before the fix).
  • tests/execute-requests.test.ts: the Workers flow's session returns a cfwau_ JWT and the upload carries Bearer cfwau_... (fails before the fix).
  • tests/scope-challenge.test.ts: the Workers upload path uses an account ID, not a zone ID.

Pages Direct Upload and Workers static assets need a short-lived JWT as the
bearer on the asset endpoints. execute always sent the session's token, so
every upload failed with 403 (8000013).

Forward the code's bearer only on the four asset upload POSTs, and only when it
is an unexpired JWT other than the session token.
@acoyfellow
acoyfellow requested review from a team as code owners November 21, 2026 23:39
@acoyfellow

Copy link
Copy Markdown
Contributor Author

Updated to include #439 (@irvinebroque's fail-closed handling, cherry-picked) plus one fix found testing it live on staging: Workers assets-upload-session returns a cfwau_-prefixed JWT, which #439's check refused, so Workers uploads were still blocked. The prefix is now stripped before the check and the token is sent unchanged. Pages and Workers both pass end to end on staging at d5618a5; before/after is in the description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants