Skip to content

fix: prevent crash in NIP-11 response when payments settings are absent#682

Open
Priyanshubhartistm wants to merge 1 commit into
cameri:mainfrom
Priyanshubhartistm:fix/root-handler-crash-payments-disabled
Open

fix: prevent crash in NIP-11 response when payments settings are absent#682
Priyanshubhartistm wants to merge 1 commit into
cameri:mainfrom
Priyanshubhartistm:fix/root-handler-crash-payments-disabled

Conversation

@Priyanshubhartistm

Copy link
Copy Markdown
Collaborator

Description

rootRequestHandler builds the NIP-11 relay information document's fees field by calling Object.getOwnPropertyNames(settings.payments.feeSchedules) with no guard on settings.payments being present. Since payments is an optional field on Settings, any relay running without a payments block in settings.yaml throws a TypeError on every request with an Accept: application/nostr+json header. The fix mirrors the optional-chaining pattern already used elsewhere in this same file (e.g. hasAdmissionRestriction, payment_required): when
settings.payments is absent, fees now resolves to {} instead of crashing.

Related Issue

Issue #681

Motivation and Context

Any relay operator who omits the payments block from settings.yaml (rather than setting payments.enabled: false, which ships with a full block by default) has their worker crash on every NIP-11 discovery request, since payments?: Payments is typed as optional but was accessed without a null check.

How Has This Been Tested?

  • Added a new unit test (returns empty fees instead of crashing when the payments block is absent)
    that strips payments from the stubbed settings object and asserts rootRequestHandler does not
    throw and returns fees: {}.
  • Ran the full unit suite: pnpm run test:unit — 1394 passing (up from 1393 with the new test).
  • Ran the CLI test suite: pnpm run test:cli — 73 passing.
  • Ran unit coverage: pnpm run cover:unit — passes; root-request-handler.ts at 98.21% statement coverage.
  • Ran the full integration suite via Docker: pnpm run docker:test:integration — 99 scenarios / 489
    steps passing, including the existing umber features that exercise
    this handler.
  • Ran pnpm lint, pnpm exec biome format (on the touched files), pnpm check:deps,
    pnpm run build:check, pnpm run build, and pnpm run verify:cli:build — all clean.

Screenshots (if appropriate):

N/A — backend-only change, no UI impact.

Types of changes

  • Non-functional change (docs, style
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change w
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my cod
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

rootRequestHandler accessed settings.payments.feeSchedules unconditionally

Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0fafd85

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

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

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

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

Coverage is 67.671%Priyanshubhartistm:fix/root-handler-crash-payments-disabled into cameri:main. No base build found for cameri:main.

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.

2 participants