[PR #956] [CLOSED] serve: an API key with spaces around it or outside Latin-1 works, and a refused key is not called a missing one (#725) #2935

Closed
opened 2026-11-04 02:04:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/956
Author: @BGonnermann
Created: 10/5/2026
Status: ❌ Closed

Base: main ← Head: fix/ui-api-key-725


📝 Commits (10+)

  • fa16567 setup: an earlier config that does not parse is skipped, not a crash; configs are written atomically (#459)
  • 749d957 setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446)
  • 5a30024 calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447)
  • 9f60d13 serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448)
  • eb8da1d /metrics: each request's speculative draft counts, and their sums in the totals (#457)
  • 6a09387 setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444)
  • d6a91e2 docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438)
  • d8d4ad3 Merge branch 'f-135-eng' into rel-0.1.35
  • 7b600d5 Merge branch 'f-135-small' into rel-0.1.35
  • d9ab843 Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it

📊 Changes

3 files changed (+89 additions, -9 deletions)

View changed files

📝 serve/server.py (+30 -2)
📝 serve/test_server.py (+49 -2)
📝 serve/web/app.js (+10 -5)

📄 Description

For #725 (the web app keeps asking for the API key after one is saved).

What I could and could not reproduce. On current main (6f32ec0) the plain case of the issue works: with --api-key test-key-123 the key saves under About > Settings and chat answers. So I have not reproduced the reporter's exact case and cannot say which of the causes below they hit. Trying ten key shapes through the web app found three defects that give the reported behaviour.

The three defects

  1. A key with a space or a line end around it matched no request. An HTTP header loses those characters (and the server strips the Bearer value, the web app trims its field), but the server kept its own key as given. A key from a config or environment file with CRLF line ends, or a quoted " key ", gave every client 401 with the right key. The server now keeps the key without them. A key that is only such characters stops the start, as an empty one does (#213); it never turns the check off.
  2. A key outside Latin-1 never worked. The web app's fetch() throws on such a header value (the pill went to "Server not reachable"), and the server re-encoded the header's bytes before comparing, so a UTF-8 key from curl did not match either. The web app now sends the key as UTF-8, and the server accepts the UTF-8 and the Latin-1 form of the right key. The comparison is still hmac.compare_digest.
  3. A refused key was called a missing one. With a saved key the server refuses, the web app said "API key needed: add it under About > Settings". It now says "API key not accepted" and to check the key. A newly saved key shows the note again if it is refused too.

A number as "api_key" in the config file ("api_key": 12345) is read as text now; before, .encode() failed on each request.

Measured

Windows 11, Python 3.14, --engine mock, headless Edge driven by Playwright; one server per key, the key typed into About > Settings, the status pill read 3.5 s later.

key before after
sk-abc123 Idle Idle
p@ss w0rd! Idle Idle
" padded " API key needed Idle
"trail\r" API key needed Idle
q"uote\ Idle Idle
clé-ünï Idle Idle
пароль Server not reachable Idle
12345 Idle Idle
true Idle Idle
200 x a Idle Idle

With a wrong key saved: pill "API key not accepted" (before: "API key needed"); with the right key after it: Idle.

python -m unittest serve.test_server: 143 tests, OK (4 new, ApiKeyForms).

Not measured: Firefox and Safari, and a blank "api_key" in a config file on a real start (only --api-key " " was run; the config path goes through the same api_key_of, which the unit test covers).

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/956 **Author:** [@BGonnermann](https://github.com/BGonnermann) **Created:** 10/5/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/ui-api-key-725` --- ### 📝 Commits (10+) - [`fa16567`](https://github.com/Niko1221/Strata/commit/fa165679f9860552ac97ebd07118bb8db286be4a) setup: an earlier config that does not parse is skipped, not a crash; configs are written atomically (#459) - [`749d957`](https://github.com/Niko1221/Strata/commit/749d957a1790b1a171dd4a01ab3e31b3882c9892) setup (--backend hip): a system ROCm without the HIP development files falls back to the wheels (#446) - [`5a30024`](https://github.com/Niko1221/Strata/commit/5a3002446dbb9dfcabb7d0bd9f113da90cc2f3c0) calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447) - [`9f60d13`](https://github.com/Niko1221/Strata/commit/9f60d13246e46b02b1dd0841980b4d18b0faaea7) serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448) - [`eb8da1d`](https://github.com/Niko1221/Strata/commit/eb8da1d8c26ec41e6ffb084fdf579dba7cad10bd) /metrics: each request's speculative draft counts, and their sums in the totals (#457) - [`6a09387`](https://github.com/Niko1221/Strata/commit/6a093874fe037020f49bd5cf053879ff6a133c21) setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444) - [`d6a91e2`](https://github.com/Niko1221/Strata/commit/d6a91e2d1770d0f469d6ec15890acc7ee93e764c) docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438) - [`d8d4ad3`](https://github.com/Niko1221/Strata/commit/d8d4ad337d3c98ba21d3bd0af1a16e9177e112b6) Merge branch 'f-135-eng' into rel-0.1.35 - [`7b600d5`](https://github.com/Niko1221/Strata/commit/7b600d55ff801caaaa11542af1523050992e049b) Merge branch 'f-135-small' into rel-0.1.35 - [`d9ab843`](https://github.com/Niko1221/Strata/commit/d9ab8435f654c368c586340d490915f6addf56a3) Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it ### 📊 Changes **3 files changed** (+89 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+30 -2) 📝 `serve/test_server.py` (+49 -2) 📝 `serve/web/app.js` (+10 -5) </details> ### 📄 Description For #725 (the web app keeps asking for the API key after one is saved). **What I could and could not reproduce.** On current main (`6f32ec0`) the plain case of the issue works: with `--api-key test-key-123` the key saves under About > Settings and chat answers. So I have not reproduced the reporter's exact case and cannot say which of the causes below they hit. Trying ten key shapes through the web app found three defects that give the reported behaviour. ## The three defects 1. **A key with a space or a line end around it matched no request.** An HTTP header loses those characters (and the server strips the Bearer value, the web app trims its field), but the server kept its own key as given. A key from a config or environment file with CRLF line ends, or a quoted `" key "`, gave every client 401 with the right key. The server now keeps the key without them. A key that is only such characters stops the start, as an empty one does (#213); it never turns the check off. 2. **A key outside Latin-1 never worked.** The web app's `fetch()` throws on such a header value (the pill went to "Server not reachable"), and the server re-encoded the header's bytes before comparing, so a UTF-8 key from curl did not match either. The web app now sends the key as UTF-8, and the server accepts the UTF-8 and the Latin-1 form of the right key. The comparison is still `hmac.compare_digest`. 3. **A refused key was called a missing one.** With a saved key the server refuses, the web app said "API key needed: add it under About > Settings". It now says "API key not accepted" and to check the key. A newly saved key shows the note again if it is refused too. A number as `"api_key"` in the config file (`"api_key": 12345`) is read as text now; before, `.encode()` failed on each request. ## Measured Windows 11, Python 3.14, `--engine mock`, headless Edge driven by Playwright; one server per key, the key typed into About > Settings, the status pill read 3.5 s later. | key | before | after | |---|---|---| | `sk-abc123` | Idle | Idle | | `p@ss w0rd!` | Idle | Idle | | `" padded "` | API key needed | Idle | | `"trail\r"` | API key needed | Idle | | `q"uote\` | Idle | Idle | | `clé-ünï` | Idle | Idle | | `пароль` | Server not reachable | Idle | | `12345` | Idle | Idle | | `true` | Idle | Idle | | 200 x `a` | Idle | Idle | With a wrong key saved: pill "API key not accepted" (before: "API key needed"); with the right key after it: Idle. `python -m unittest serve.test_server`: 143 tests, OK (4 new, `ApiKeyForms`). Not measured: Firefox and Safari, and a blank `"api_key"` in a config file on a real start (only `--api-key " "` was run; the config path goes through the same `api_key_of`, which the unit test covers). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:04:18 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2935
No description provided.