Skip to content

Commit d0812a1

Browse files
fix: separate CLI auth gate from persisted approvals
Persisted approvals no longer activate the authorisation gate on their own. Only CLI --authorized-keys controls whether the gate is active. This prevents open-mode bunkers from silently switching to restricted mode after a restart.
1 parent 5326716 commit d0812a1

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

src/bunker.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ export function startBunker(opts: BunkerOptions): BunkerInstance {
4949
const bunkerPk = getPublicKey(bunkerSk)
5050
const bunkerNpub = npubEncode(bunkerPk)
5151

52-
// Authorised clients: CLI flag + persisted approvals
52+
// Authorised clients: CLI flag controls the gate, persisted approvals supplement
5353
const APPROVALS_FILE = 'approved-clients.json'
5454
const persisted = readStateFile<Record<string, string[]>>(APPROVALS_FILE, opts.stateDir)
5555
const bunkerApprovals = persisted[bunkerPk] ?? []
56+
const cliAuthorizedKeys = new Set(opts.authorizedKeys ?? [])
5657
const authorizedKeys = new Set([
57-
...(opts.authorizedKeys ?? []),
58+
...cliAuthorizedKeys,
5859
...bunkerApprovals,
5960
])
6061

@@ -78,8 +79,8 @@ export function startBunker(opts: BunkerOptions): BunkerInstance {
7879
async function handleRequest(event: NostrEvent): Promise<void> {
7980
const clientPk = event.pubkey
8081

81-
// Check authorization
82-
if (authorizedKeys.size > 0 && !authorizedKeys.has(clientPk)) {
82+
// Check authorization — gate only activates when CLI --authorized-keys were set
83+
if (cliAuthorizedKeys.size > 0 && !authorizedKeys.has(clientPk)) {
8384
log(`Rejected request from unauthorized key: ${clientPk.slice(0, 12)}...`)
8485
return
8586
}
@@ -234,8 +235,8 @@ export function startBunker(opts: BunkerOptions): BunkerInstance {
234235
log(`Bunker started: ${bunkerNpub}`)
235236
log(`URI: ${bunkerUrl}`)
236237
log(`Signing as: ${ctx.activeNpub}`)
237-
if (authorizedKeys.size > 0) {
238-
log(`Authorized keys: ${authorizedKeys.size}`)
238+
if (cliAuthorizedKeys.size > 0) {
239+
log(`Authorized keys: ${authorizedKeys.size} (${cliAuthorizedKeys.size} CLI + ${bunkerApprovals.length} persisted)`)
239240
} else {
240241
log('WARNING: No authorized keys set — accepting requests from anyone')
241242
}

0 commit comments

Comments
 (0)