Skip to content

Sign the /path proxy URL; fall back to it for unreachable vocabulary - #1841

Closed
michielbdejong wants to merge 1 commit into
claude/unsigned-cross-origin-vocabfrom
claude/vocab-proxy-signing
Closed

michielbdejong wants to merge 1 commit into
claude/unsigned-cross-origin-vocabfrom
claude/vocab-proxy-signing

Conversation

@michielbdejong

Copy link
Copy Markdown
Contributor

Closes #1838
Stacked on #1840 (base claude/unsigned-cross-origin-vocab).

Root cause

Client.fetchResourceHTTP signed the request first and swapped in {server}/path?path=<subject> afterwards. So the signature covered the external subject. The server checks it against the full URL it receives (get_client_agent(headers, …, &full_url)), so it answered 401. It only seemed to work for https://atomicdata.dev subjects, and only because those were never signed at all.

Separately, a browser that couldn't reach a vocabulary host never asked its own server. A cold browser with Pages down showed a table with only #.

Fix

Signing (browser/lib/src/client.ts)

  • The proxy URL is built first, by the new proxyPathUrl(). Exactly that URL is signed.
  • The cookie and atomicdata.dev checks look at the requested URL for proxied fetches.
  • Every 5xx, not only 500, is now typed ErrorType.Server.

Fallback (Store._fetchResourceFromServerImpl)

  • A direct GET of a foreign plain document (no query string) that fails with a transport error (network, DNS, CORS) or a 5xx is retried once through the own server's /path. That server fetches the external class on first use and keeps it.
  • The proxied answer takes the same applyIncoming path as a direct one, so it is stored and cached the same way.
  • An origin the proxy served goes to the proxy first for the rest of the session: one failed request per origin, not one per term. If the proxy then fails, the origin is tried once.
  • It doesn't loop: at most two requests per fetch.
  • A 404 or 401 is not retried. Queries, collections, POSTs and the own server are never proxied. (A legacy server's 500 on ?drive= still has to reach the collection code.)

No server changes were needed. The server already accepts a correctly signed /path request.

Tests

  • browser/lib/src/vocab-proxy-fallback.test.ts (vitest):
    • The signature equals createSignature(proxyURL, ts), not the subject's.
    • Order: direct first, then the proxy after a CORS or network error, a 500 or a 503.
    • No retry on a 404, and one proxy attempt when both routes fail.
    • Proxy-first on later terms from the same origin.
    • Query URLs and the own server are never proxied.
    • The result is cached under the original subject.
  • browser/lib/tests/vocab-proxy.integration.test.ts runs a real atomic-server against a local stub origin that behaves like Pages (GET with ACAO: *, 405 on a preflight):
    • A proxy request signed over the proxy URL is accepted and returns the external class.
    • A request signed over the external subject gets a 401: this is the old bug.
    • Store.fetchResourceFromServer falls back to the proxy when the stub returns 503 to the browser.

Also run: the browser/lib suite (1034 tests), the data-browser vitest suite, lint and typecheck.

🤖 Generated with Claude Code

fetchResourceHTTP signed the request before swapping in the /path proxy
URL, so the signature covered the external subject while the server
verified it against the proxy URL it received, and refused it (401).
Build the proxy URL first and sign exactly that.

When a direct fetch of a foreign plain document fails (network, CORS,
5xx), the Store now retries once through the own server's /path proxy,
which fetches and keeps external vocabulary. The answer takes the same
applyIncoming path as a direct one, so it is cached the same way. An
origin the proxy served goes to the proxy first for the rest of the
session; if that fails, the origin itself is tried once. Queries,
collections, POSTs and the own server are never proxied.

5xx responses other than 500 are now typed as server errors too.

Closes #1838

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@michielbdejong michielbdejong added bug Something isn't working server atomic-server @tomic/lib @tomic/lib labels Sep 25, 2026
joepio added a commit that referenced this pull request Sep 25, 2026
joepio added a commit that referenced this pull request Sep 25, 2026
#1826, #1787, #1783, #1791, #1840, #1841) (#1844)

Combined batch, green on Mancave in run 4645 on 3346a6c (CI and Downstream).

Includes #1826, #1787, #1783, #1791, #1840 and #1841, plus settled
translation catalogs.

joepio commented Sep 25, 2026

Copy link
Copy Markdown
Member

Landed on develop in ef161c3 via the combined batch #1844 (green on Mancave, run 4645). Closing.


Generated by Claude Code

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

Labels

bug Something isn't working server atomic-server @tomic/lib @tomic/lib

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants