Skip to content

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

Merged
Anshumancanrock merged 7 commits into
cameri:mainfrom
Anshumancanrock:feat/nip98-admin-auth
Aug 20, 2026
Merged

feat(admin): accept NIP-98 auth on admin API routes#730
Anshumancanrock merged 7 commits 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-botBot commented Aug 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e643772

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

This PR includes changesets to release 1 package
NameType
nostreamMinor

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 threadsrc/routes/admin/index.ts Dismissed
Comment threadsrc/routes/admin/index.ts Dismissed
Comment threadsrc/routes/admin/index.ts Dismissed
Comment threadsrc/routes/admin/index.ts Dismissed
Comment threadsrc/routes/admin/index.ts Dismissed
Comment threadsrc/routes/admin/index.ts Dismissed
Comment threadsrc/routes/admin/index.ts Dismissed
Comment threadsrc/routes/admin/index.ts Dismissed
Comment threadsrc/routes/admin/index.ts Dismissed
Comment threadsrc/routes/admin/index.ts Fixed
@coveralls

coveralls commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

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

@Anshumancanrock

Copy link
Copy Markdown
CollaboratorAuthor

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
@cameri
cameri requested a balanced review from CopilotAugust 14, 2026 17:20
@Anshumancanrock
Anshumancanrock marked this pull request as ready for review August 14, 2026 17:21

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds optional NIP-98 authentication to protected admin APIs while preserving session authentication.

Changes:

  • Adds NIP-98 verification, allowlisting, payload binding, and Redis replay protection.
  • Introduces pre-body authentication gates and raw-body capture.
  • Adds configuration, documentation, and tests.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
src/handlers/request-handlers/admin-auth-middleware.tsImplements NIP-98 admin authentication.
src/handlers/request-handlers/admin-json-body-middleware.tsCaptures raw JSON bodies.
src/utils/nip98-replay.tsAdds Redis-backed replay claims.
src/routes/admin/index.tsWires authentication and body middleware.
src/@types/settings.tsDefines NIP-98 settings types.
resources/default-settings.yamlAdds disabled-by-default settings.
CONFIGURATION.mdDocuments configuration.
test/unit/handlers/request-handlers/admin-auth-middleware.spec.tsTests authentication behavior.
test/unit/utils/nip98-replay.spec.tsTests replay claims.
.knip.jsonRecognizes the now-used verifier.
.changeset/nip98-admin-middleware.mdRecords the feature release.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment threadsrc/handlers/request-handlers/admin-auth-middleware.ts Outdated
Comment threadCONFIGURATION.md Outdated
Comment threadsrc/handlers/request-handlers/admin-auth-middleware.ts Outdated
Comment threadsrc/handlers/request-handlers/admin-auth-middleware.ts Outdated
Comment threadsrc/handlers/request-handlers/admin-auth-middleware.ts Outdated
Comment threadsrc/handlers/request-handlers/admin-auth-middleware.ts Outdated
Comment threadsrc/routes/admin/index.ts Dismissed
@Anshumancanrock
Anshumancanrock merged commit ef4123e into cameri:mainAug 20, 2026
16 of 18 checks passed
Sign up for freeto 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.

6 participants

@Anshumancanrock@coveralls@Ferryx349@cameri@github-advanced-security