[PR #4535] [CLOSED] [GUI] Shared listener: compare the API key in constant time (as the engine since #213) #5079

Closed
opened 2026-11-07 16:32:32 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4535
Author: @schmittcn
Created: 10/28/2026
Status: ❌ Closed

Base: main ← Head: pr/host-key-constant-time


📝 Commits (1)

  • ae6283c apps/host: the shared listener compares the API key in constant time (as the engine since #213)

📊 Changes

2 files changed (+32 additions, -2 deletions)

View changed files

📝 apps/host/server/serving.mjs (+6 -2)
➕ apps/host/tests/serving-key-compare.test.mjs (+26 -0)

📄 Description

Problem and result

serving.authorized() in apps/host/server/serving.mjs compares the API key with ===. The local share listener and the Cloudflare tunnel origin use this check. On the tunnel it faces the internet, and SECURITY.md says the key "is compared in constant time". The engine has done that since #213 (key_matches, hmac.compare_digest); the app's host never did.

Both values are now hashed with SHA-256 and compared with crypto.timingSafeEqual. Neither the key's content nor its length can end the comparison early. Both the Bearer and the x-api-key header are compared on every request, so the time doesn't show which one was sent. Nothing else changes: the same headers pass, and no key set still means open access (the 0.2.2 decision).

This is hardening, not an observed attack. Timing a single === over a network and through Cloudflare is hard, and the generated key has 96 random bits.

Validation

Revision: upstream/main at 46c152a1, Linux, Node 26.9.0.

  • Passed: node --test tests/serving-key-compare.test.mjs tests/serving-key-optional.test.mjs in apps/host. The new test covers: Bearer passes; x-api-key passes; a missing header, an empty Bearer, a wrong key, a prefix of the key, the key plus one character, and a key without Bearer all fail; a wrong Bearer together with the right x-api-key passes, as before.
  • Full npm test in apps/host (after npm ci): 1226 tests, 1119 passed, 2 failed, 105 skipped. Unmodified main gives the same two failures (1225 tests, 1118 passed), so they are not from this change:
    • packaged: an update job an OLDER host left running is finished when the app program file is newer than the job
    • Stop ends the job and everything it started, deletes the copies, leaves the person's files alone, and the run then reads as cancelled
  • Not measured: timing. The test checks behaviour only.

🤖 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/4535 **Author:** [@schmittcn](https://github.com/schmittcn) **Created:** 10/28/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/host-key-constant-time` --- ### 📝 Commits (1) - [`ae6283c`](https://github.com/Niko1221/Strata/commit/ae6283cecf23bcbccb60ad6ae0cbba4eeaddb5de) apps/host: the shared listener compares the API key in constant time (as the engine since #213) ### 📊 Changes **2 files changed** (+32 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `apps/host/server/serving.mjs` (+6 -2) ➕ `apps/host/tests/serving-key-compare.test.mjs` (+26 -0) </details> ### 📄 Description ## Problem and result `serving.authorized()` in `apps/host/server/serving.mjs` compares the API key with `===`. The local share listener and the Cloudflare tunnel origin use this check. On the tunnel it faces the internet, and `SECURITY.md` says the key "is compared in constant time". The engine has done that since #213 (`key_matches`, `hmac.compare_digest`); the app's host never did. Both values are now hashed with SHA-256 and compared with `crypto.timingSafeEqual`. Neither the key's content nor its length can end the comparison early. Both the Bearer and the `x-api-key` header are compared on every request, so the time doesn't show which one was sent. Nothing else changes: the same headers pass, and no key set still means open access (the 0.2.2 decision). This is hardening, not an observed attack. Timing a single `===` over a network and through Cloudflare is hard, and the generated key has 96 random bits. ## Validation Revision: `upstream/main` at `46c152a1`, Linux, Node 26.9.0. - **Passed:** `node --test tests/serving-key-compare.test.mjs tests/serving-key-optional.test.mjs` in `apps/host`. The new test covers: Bearer passes; `x-api-key` passes; a missing header, an empty Bearer, a wrong key, a prefix of the key, the key plus one character, and a key without `Bearer ` all fail; a wrong Bearer together with the right `x-api-key` passes, as before. - **Full `npm test` in `apps/host` (after `npm ci`):** 1226 tests, 1119 passed, 2 failed, 105 skipped. Unmodified `main` gives the same two failures (1225 tests, 1118 passed), so they are not from this change: - `packaged: an update job an OLDER host left running is finished when the app program file is newer than the job` - `Stop ends the job and everything it started, deletes the copies, leaves the person's files alone, and the run then reads as cancelled` - **Not measured:** timing. The test checks behaviour only. 🤖 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-07 16:32:32 +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#5079
No description provided.