Skip to content

fix(versioninfo): reject reads with unknown authKey, not just missing-header#160

Merged
CryptoJones merged 1 commit into
masterfrom
fix/versioninfo-reads-require-valid-authkey
May 19, 2026
Merged

fix(versioninfo): reject reads with unknown authKey, not just missing-header#160
CryptoJones merged 1 commit into
masterfrom
fix/versioninfo-reads-require-valid-authkey

Conversation

@CryptoJones
Copy link
Copy Markdown
Owner

Closes #159.

Summary

GET /v1/versioninfo/:id and GET /v1/versioninfo originally gated only on if (!authKey) — header-present-check, no DB validation. Anyone sending any non-empty string in authKey got 200 with the schema/build version records, even though the README's endpoint table promises "yes (authKey)" with the rest-of-codebase semantics of "any valid authKey, master or scoped".

Add a requireValidAuth(req, res) helper that reads the already-resolved req.authKey / req.isMaster / req.companyId populated by attachAuth (mounted at /v1/*). Master keys pass; non-master keys pass when they resolved to a real company id; an unknown header is the reject case (403 "Invalid Authorization Key.").

No extra DB round-trip — attachAuth already did the lookups upstream.

Test plan

  • npm run lint — clean
  • npm test — 614 passed (was 612 + 2 new for unknown-authKey rejection on both reads), 15 skipped
  • Existing tests unchanged: the mounting tests send authKey: any and only assert on body shape, so they continue to pass; the missing-header 403 tests are still 403

Proudly Made in Nebraska. Go Big Red! 🌽 https://xkcd.com/2347/

…-header

`GET /v1/versioninfo/:id` and `GET /v1/versioninfo` originally
gated only on `if (!authKey)` — header-present-check, no DB
validation. Anyone with ANY non-empty string in the `authKey`
header got 200 with the schema/build version records.

The README's endpoint table says "yes (authKey)" for these reads,
which the rest of the API consistently means "any VALID authKey,
master or scoped". A literal presence-check breaks that contract:
the same string `authKey: anything` that reliably 403s every
other v1 endpoint silently let through on versioninfo.

Add a `requireValidAuth(req, res)` helper that reads the already-
resolved `req.authKey` / `req.isMaster` / `req.companyId` populated
by `attachAuth` (mounted at /v1/*). Master keys pass; non-master
keys pass when they resolved to a real company id; an unknown
header is the new reject case (403 with the same
"Invalid Authorization Key." message the other endpoints emit).

No extra DB round-trip — the helper reads req state attachAuth
already produced upstream.

Two new tests pin the tightening: GET 403 for unknown authKey,
GET list 403 for unknown authKey. The existing missing-header
403 tests continue to pass; the mounting tests that send
`authKey: any` continue to pass because they only assert on body
shape, not status code.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@CryptoJones CryptoJones merged commit 75fddc6 into master May 19, 2026
3 checks passed
@CryptoJones CryptoJones deleted the fix/versioninfo-reads-require-valid-authkey branch May 19, 2026 07:48
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.

security(versioninfo): reads accept ANY header value as authKey instead of validating it

1 participant