Skip to content

Persist the signed download token in files.token#18

Merged
acoshift merged 1 commit into
mainfrom
claude/store-download-token
May 24, 2026
Merged

Persist the signed download token in files.token#18
acoshift merged 1 commit into
mainfrom
claude/store-download-token

Conversation

@acoshift
Copy link
Copy Markdown
Member

Summary

  • Store the full signed download token (fn-{hmac}) in a new files.token column at upload time, so the api's dropbox.List can rebuild working download URLs without holding sign_key.

Why

PR #17 made the HMAC signature mandatory: GET /files/{token} runs parseToken first and 404s anything without a valid tag. But dropbox.List (in apiserver) builds its downloadUrl from the bare fn — it has no sign_key, so every link it returns is a dead /files/{fn} that fails the HMAC check. Persisting the token dropbox already computes is the simplest fix; the alternative (sharing sign_key with the api) couples key rotation across services.

How

  • schema/03_token.sql + schema.sql: add token text not null default ''. The default keeps the migration safe for existing rows — they carry an empty token until they self-expire (≤7-day max TTL), which is no worse than today (links are already broken).
  • uploadHandler computes the token once, writes it to the new column, and reuses it for the response downloadUrl (previously recomputed inline).

Schema migration

alter table files add column token text not null default '';

(dropbox's schema/*.sql migrator is not run at startup — apply out-of-band, same as other columns.)

Deploy ordering

  1. Apply the migration above.
  2. Deploy dropbox (this PR) — new uploads start populating token.
  3. Deploy apiserver (deploys-app/apiserver companion PR) — reads token for dropbox.List.

Test plan

  • go test ./... passes
  • TestUpload_Success now asserts the token in downloadUrl is persisted verbatim to files.token.

🤖 Generated with Claude Code

The api's dropbox.List builds download URLs but has no sign_key, so it
could only emit the bare fn — which /files/{fn} rejects in parseToken
(no HMAC), giving a dead link. Store the full signed token at upload
time so dropbox.List can rebuild the working URL as base_url + token.

- schema/03_token.sql migration + schema.sql add `token text not null
  default ''` (default keeps the migration safe for existing rows; they
  self-expire within the 7-day max TTL).
- uploadHandler computes the token once, writes it, and reuses it for
  the response downloadUrl.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@acoshift acoshift merged commit 058b8e2 into main May 24, 2026
2 checks passed
@acoshift acoshift deleted the claude/store-download-token branch May 24, 2026 06:46
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