Defend against nsec exposure in signup flow#3712
Draft
Conversation
Add a warning when users accidentally paste their private key (nsec or raw 64-char hex) into the Name or Bio fields during account creation. - Add `containsPrivateKeyMaterial(_:)` helper that detects bech32 nsec keys and 64-character hex strings - Add `fieldsContainPrivateKey()` method on CreateAccountView that tokenises each profile field and calls the helper - Intercept the "Next" button tap; show a destructive alert when private-key material is detected, giving the user a chance to go back and remove it before continuing - Add unit tests for `containsPrivateKeyMaterial` covering nsec, hex, npub (should NOT warn), plain names, and short hex strings Closes: #2209 Signed-off-by: copilot <copilot@github.com> Co-authored-by: danieldaquino <24692108+danieldaquino@users.noreply.github.com> Agent-Logs-Url: https://github.com/damus-io/damus/sessions/cc25c1af-ec5e-4365-b71d-98177c7779e5
Copilot
AI
changed the title
[WIP] Add detection mechanism for nsec keys in signup
Defend against nsec exposure in signup flow
Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Users who click "Sign Up" instead of "Login" sometimes paste their
nsecprivate key into profile fields (Name, Bio), inadvertently publishing it on Nostr. This adds detection and a blocking warning before they can proceed.Changes
CreateAccountView.swiftcontainsPrivateKeyMaterial(_ text: String) -> Bool— detects bech32nsec1…keys (viadecode_bech32_key) and raw 64-char hex strings (viahex_decode); explicitly ignoresnpub, NIP-05, and plain textfieldsContainPrivateKey() -> Bool— tokenisesaccount.nameandaccount.abouton whitespace, applies the helper to each tokenfieldsContainPrivateKey()before navigating; shows a destructive alert on a hit with Go Back (cancel) / Continue Anyway (destructive) optionsdamusTests/CreateAccountTests.swift— unit tests covering: nsec detected, 64-char hex detected, npub not flagged, plain names not flagged, short hex not flagged.Checklist
Standard PR Checklist
Closes:orFixes:tags in the commit messages wherever applicable, or made sure those are not needed. See Submitting patchesTest report
Device: iPhone 16 Simulator
iOS: 18.x
Damus:
f6fdef1Steps:
nsec1…key into the Name field, tap Next → warning alert appearsResults:
Other notes
The 64-char hex heuristic will also catch pubkeys in raw hex form. This is intentional and conservative — raw hex in a display name is almost certainly a paste mistake regardless of key type.
Original prompt
⌨️ Start Copilot coding agent tasks without leaving your editor — available in VS Code, Visual Studio, JetBrains IDEs and Eclipse.