Skip to content

feat(admin): accept NIP-98 auth on admin API routes - #730

Draft
Anshumancanrock wants to merge 1 commit into
cameri:mainfrom
Anshumancanrock:feat/nip98-admin-auth
Draft

feat(admin): accept NIP-98 auth on admin API routes#730
Anshumancanrock wants to merge 1 commit into
cameri:mainfrom
Anshumancanrock:feat/nip98-admin-auth

Conversation

@Anshumancanrock

Copy link
Copy Markdown
Collaborator

Description

Protected admin API routes now accept Authorization: Nostr on top of the existing session cookie.

Off by default. Set admin.nip98.enabled and put hex pubkeys in admin.nip98.allowedPubkeys. Empty allowlist means nobody gets in that way.

For PATCH/POST we check the header (sig + allowlist) before parsing JSON, so a junk Nostr token never hits the 1mb body parser. After the body is read we check the payload hash and store the event id in Redis with SET NX (TTL = maxSkewSeconds). Same event twice, or Redis down → 401.

GETs don't parse a body. Same session-or-NIP-98 check, including the one-time event id.

Clients still sign u against info.relay_url (not the request Host). Password login / dashboard / cookie session are unchanged; /login stays 100kb.

Related Issue

Follows #722 (verifier), #725 (absolute URL), #726 (Redis NX).

Motivation and Context

#722 only verifies a header. This is the part that actually lets you call the admin API with a signed event instead of sharing the password.

@changeset-bot

changeset-bot Bot commented Aug 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5ca12e7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
nostream Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment thread src/routes/admin/index.ts
router.get('/metrics', adminRateLimitMiddleware, adminAuthMiddleware, withAdminController(createGetAdminMetricsController))
router.get('/settings', adminRateLimitMiddleware, adminAuthMiddleware, withAdminController(createGetAdminSettingsController))
router.get(
'/session',
Comment thread src/routes/admin/index.ts
router.get(
'/session',
adminRateLimitMiddleware,
adminAuthMiddleware,
Comment thread src/routes/admin/index.ts
withAdminController(createGetAdminSessionController),
)
router.get(
'/health',
Comment thread src/routes/admin/index.ts
router.get(
'/health',
adminRateLimitMiddleware,
adminAuthMiddleware,
Comment thread src/routes/admin/index.ts
router.get(
'/metrics',
adminRateLimitMiddleware,
adminAuthMiddleware,
Comment thread src/routes/admin/index.ts
router.get(
'/settings',
adminRateLimitMiddleware,
adminAuthMiddleware,
Comment thread src/routes/admin/index.ts
router.patch(
'/settings',
adminRateLimitMiddleware,
adminAuthGateMiddleware,
Comment thread src/routes/admin/index.ts
adminRateLimitMiddleware,
adminAuthGateMiddleware,
adminJsonBodyMiddleware,
adminAuthMiddleware,
Comment thread src/routes/admin/index.ts
router.post(
'/settings/validate',
adminRateLimitMiddleware,
adminAuthGateMiddleware,
Comment thread src/routes/admin/index.ts
router.post(
'/settings/restore',
adminRateLimitMiddleware,
adminAuthGateMiddleware,
@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 70.044% (+0.2%) from 69.832% — Anshumancanrock:feat/nip98-admin-auth into cameri:main

@Anshumancanrock

Copy link
Copy Markdown
Collaborator Author

I think CodeQL doesn’t recognize our Redis adminRateLimitMiddleware (it only models express-rate-limit etc). These routes still run that limiter before auth, same as the rest of this file.

@Ferryx349

Copy link
Copy Markdown
Collaborator

@Anshumancanrock totally agree, its a codeql false positive, it was happening same with me too, had tried a fix in #692.

@Anshumancanrock
Anshumancanrock marked this pull request as draft August 13, 2026 14:35
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.

4 participants