Skip to content

fix(rest): accept the session cookie on PUT /file with a required Origin (R-56, S-37) - #35

Merged
TurkerMertkan merged 1 commit into
developfrom
s37-file-put-cookie
Nov 23, 2026
Merged

TurkerMertkan merged 1 commit into
developfrom
s37-file-put-cookie

Conversation

@TurkerMertkan

Copy link
Copy Markdown
Collaborator

Summary

  • The editor uploads kits with a same-origin PUT /file/sedona/... carrying only its sandstar_session cookie; PUT /file/* accepted bearer only, so with auth on kit uploads got 401 (R-56).
  • New check_write_auth (only PUT /file/*): bearer passes; a valid cookie passes only with an Origin matching the Host or --ws-allowed-origins (missing/foreign Origin → 403); otherwise 401; auth off → open.
  • Every other write route stays bearer-only. No editor change.

Routes / auth

PUT /file/* moves from require_auth to require_write_auth. GET /file/* and safe_join unchanged.

Test plan

  • Cookie/Origin matrix on PUT /file/* (fails on old gate), other write routes reject the cookie, open with auth off
  • bash tools/gates.sh: 2910 passed / 0 failed
  • Local E2E, real binary with --auth-token and a temp file root: status matrix as expected, file written and read back
  • security-reviewer: no significant findings; suggested regression cases added
  • Real kit upload from the editor with auth on

🤖 Generated with Claude Code

https://claude.ai/code/session_01QKRNiek8qYRoRt7dcrDDVC

…gin (R-56, S-37)

The editor uploads kit manifests and .kit files with a same-origin
fetch PUT to /file/sedona/..., carrying only its sandstar_session
cookie. PUT /file/* sat behind check_auth (bearer only), so with auth
on every kit upload got 401. Reads already accept the cookie (S-33).

New check_write_auth / require_write_auth, used only by PUT /file/*:
- auth not configured: every request passes (field default);
- valid bearer: passes, Origin not checked (as before);
- valid session cookie: passes only with an Origin header that matches
  the Host or --ws-allowed-origins; missing or foreign Origin gets 403.
  Browsers always send Origin on PUT, so this backs up the cookie's
  SameSite=Strict against cross-site request forgery;
- otherwise 401.

Routes/auth: PUT /file/* moves from require_auth to require_write_auth
(still inside an auth layer). Every other write route stays
bearer-only; a test checks they reject the cookie. GET /file/* and
path handling (safe_join) are unchanged. Editor: no change needed.

Tests: cookie/Origin matrix on PUT /file/* (none, forged cookie,
same-host, allowlisted, missing, foreign, null, other port, subdomain,
ftp scheme, case, duplicate cookie, second Cookie header, bearer with
and without Origin); it failed on the old gate. Other write routes
reject the cookie; open when auth is off. gates: 2910 passed / 0
failed. Local E2E with the real binary (--auth-token, temp
SANDSTAR_FILE_ROOT): 401 / 200 / 200 / 403 / 403 / 401 / 200, file
written and read back with the cookie. Largest kit in the repo is
189 KB, under the 1 MiB body limit. Not tried: a real kit upload from
the editor.

Docs: OVERVIEW §3 PUT /file row, HowToUses/03_WEB_EDITOR.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QKRNiek8qYRoRt7dcrDDVC
@TurkerMertkan
TurkerMertkan merged commit 8df1b97 into develop Nov 23, 2026
2 checks passed
@TurkerMertkan
TurkerMertkan deleted the s37-file-put-cookie branch November 23, 2026 14:06
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