openwork icon indicating copy to clipboard operation
openwork copied to clipboard

bug: `requireClient()` rejects valid localhost bearer tokens with 401

Open pedrohx26 opened this issue 8 months ago • 2 comments

Summary

Tauri generates a fresh UUID4 client_token on each launch and passes it to the server via --token <uuid>. The server's requireClient() function calls tokens.scopeForToken(token) which returns null for any token not in its internal store, causing a 401 rejection. The UI shows "disconnected" or "limited" — even though the connection is from 127.0.0.1 and is inherently trusted.

To Reproduce

  1. Launch OpenWork
  2. Server starts with token A (from --token CLI arg)
  3. UI sends requests with token B (fresh UUID from Tauri, or stale localStorage token)
  4. Server rejects with 401 — scopeForToken() returns null
  5. UI shows "Not connected"

This is especially reproducible when:

  • The fallback server restarts with a different token
  • hostInfo has not yet arrived from Tauri (race condition)

Expected behavior

Since the server only binds to 127.0.0.1, any non-empty bearer token should be accepted. scopeForToken() should fall back to a default scope (e.g., "collaborator") rather than returning null and triggering a 401.

Actual behavior

The server rejects any bearer token not in its internal token store with a 401, even from localhost. The UI intermittently or permanently shows "disconnected".

OW version & Desktop info

  • OpenWork: 0.11.194-1 (AUR)
  • OS: Arch Linux x86_64

Additional context

Suggested fix in packages/server/src/server.ts:

// Before:
const scope = await tokens.scopeForToken(token);

// After:
const scope = await tokens.scopeForToken(token) ?? "collaborator";

This makes the first requireClient() call fall back to "collaborator" scope for any valid bearer token from localhost.

pedrohx26 avatar Mar 30 '26 17:03 pedrohx26

can you try this in latest versions and report back if it still exists

src-opn avatar Apr 13 '26 19:04 src-opn

closed due to age, please reopen and tag me if still valid

OmarMcAdam avatar Oct 28 '26 22:10 OmarMcAdam