Skip to content

fix(admin): refuse pubkeys in settings lists that cannot match - #1240

Merged
cameri merged 1 commit into
cameri:mainfrom
Priyanshubhartistm:fix/settings-canonicalize-pubkey-lists
Nov 26, 2026
Merged

cameri merged 1 commit into
cameri:mainfrom
Priyanshubhartistm:fix/settings-canonicalize-pubkey-lists

Conversation

@Priyanshubhartistm

@Priyanshubhartistm Priyanshubhartistm commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The pubkey blacklist, the pubkey whitelist and the rate-limit bypass list (limits.event.pubkey.blacklist, limits.event.pubkey.whitelist, limits.event.whitelists.pubkeys) are compared with the pubkey of each event as they are written (blacklist.includes(event.pubkey) in EventMessageHandler). An event's pubkey is always 64 lowercase hex characters, because the event schema requires it.

The settings API saved any value in these lists. A blacklist entry in uppercase hex was stored, never matched an event, and so the pubkey it was meant to ban could still publish. The moderation endpoints already normalize what they save (normalizePubkeyList), but the generic PATCH /admin/settings does not.

validateSettings now rejects an entry that is not a 64-character lowercase hex pubkey and names the entry (for example limits.event.pubkey.blacklist[1]). It runs for every path that saves settings: the settings API, the CLI config set, backup restore, the moderation and notification controllers, and the validate endpoint, so there is one check instead of one per path. A value that is not a list is already reported by the existing shape check.

A deliberate limit: I reject an entry instead of converting it, because converting would change what an operator wrote without telling them. validateSettings is not run at startup, so a settings file that already holds such an entry still starts. The next settings change made through the paths above is refused until the entry is fixed, and the message says which one. That entry was not enforcing anything, so I preferred making it visible.

Related Issue

Partly addresses #1022 (F-011). The other findings in that issue are handled separately.

Motivation and Context

A blacklist that silently does not ban is worse than an error. CodeRabbit's scan did not establish reachability, so I checked the code: the comparison is exact, the event pubkey is always lowercase, and the generic PATCH saved the list unchanged.

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Non-functional change (docs, style, minor refactor)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • 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 code changes.
  • I added a changeset, or this is docs-only and I added an empty changeset.
  • All new and existing tests passed.

Summary by CodeRabbit

  • Bug Fixes
    • Settings validation now checks event pubkey blacklist, whitelist, and event-whitelist entries. Keys must be exactly 64 lowercase hexadecimal characters; invalid entries are rejected with a validation issue.
    • The validation applies when updating settings through the API and when using related settings workflows, including the CLI, backup restore, and validation endpoint.

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

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bbf014e

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

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds validation for three settings pubkey lists. Entries must be 64-character lowercase hexadecimal strings. Utility and admin API tests cover accepted and rejected entries, including whether the API saves them.

Changes: Settings pubkey-list validation

Layer / File(s) Summary
Validate settings pubkey lists
src/utils/settings-config.ts, test/unit/utils/settings-config.spec.ts
validateSettings checks the event pubkey blacklist, event pubkey whitelist, and event whitelists’ pubkeys. Tests cover valid lowercase keys, empty or absent lists, and invalid entries.
Verify admin API handling
test/unit/routes/admin-settings.spec.ts, .changeset/settings-pubkey-lists-lowercase-hex.md
Admin API tests verify that uppercase entries are rejected without being saved and lowercase entries are accepted and saved. The Changesets note describes the validation and its stated effects.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • cameri/nostream#1022: This change rejects uppercase and otherwise invalid blacklist entries through settings validation. It does not canonicalize entries as the issue suggests.
Merge Risk: Minimal · up to bbf01

This change rejects settings pubkey-list entries that could never match an event pubkey. Existing settings files still start, and the next update through the listed paths is refused until the invalid entry is fixed. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: settings lists now refuse pubkeys that cannot match. The changeset validates blacklist, whitelist, and event-whitelist pubkey entries as 64-character lowercase hex. Th…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: settings lists now refuse pubkeys that cannot match. The changeset validates blacklist, whitelist, and event-whitelist pubkey entries as 64-character lowercase hex. The title uses the fix(admin) scope, which matches the admin settings API and CLI paths in the changeset.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit checks each key in line,
Sixty-four small marks must shine.
Lowercase hex can pass the gate,
Uppercase keys must hesitate.
The saved list now follows suit,
And hops away with keys checked out.

Recent review info

Automatic approval policy

Commit: bbf014e4b356.

Setting Effective value Source
Automatic approvals Enabled Global configuration
Merge risk Minimal Global configuration
Security risk Not set Global configuration

Not set means no limit was configured after inheritance. Use @coderabbitai configuration to inspect the resolved settings and their sources.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: afdad15f-b853-44c4-9cd6-9f0ad9ee650e
Commits

Reviewing files that changed from the base of the PR and between 549a97d and bbf014e.

Files selected for processing: 4

  • .changeset/settings-pubkey-lists-lowercase-hex.md
  • src/utils/settings-config.ts
  • test/unit/routes/admin-settings.spec.ts
  • test/unit/utils/settings-config.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] This PR appears safe to merge.

Summary

Adds shared checks for the event pubkey blacklist, whitelist, and rate-limit bypass list.

  • Settings reject pubkeys that event lists cannot match.

Priyanshubhartistm explicitly acknowledges that existing invalid entries block later settings changes until corrected, while startup remains unchanged.

Reviews (1) · Last reviewed commit: "fix(admin): refuse pubkeys in settings l..." · Reviewed by Greptile

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 45591051949

Coverage increased (+0.01%) to 80.26%

Details

  • Coverage increased (+0.01%) from the base build.
  • Patch coverage: 11 of 11 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 15113
Covered Lines: 12637
Line Coverage: 83.62%
Relevant Branches: 8403
Covered Branches: 6237
Branch Coverage: 74.22%
Branches in Coverage %: Yes
Coverage Strength: 642.1 hits per line

💛 - Coveralls

@cameri
cameri merged commit 37e327f into cameri:main Nov 26, 2026
21 checks passed
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.

3 participants