Skip to content

feat(auth): block prod-key sign-in on staging homeserver deploys - #2194

Open
infin1t3 wants to merge 1 commit into
devfrom
feat/2126-prevent-prod-signin-staging
Open

feat(auth): block prod-key sign-in on staging homeserver deploys#2194
infin1t3 wants to merge 1 commit into
devfrom
feat/2126-prevent-prod-signin-staging

Conversation

@infin1t3

Copy link
Copy Markdown
Collaborator

Reject mnemonic, encrypted-file, Ring, and restore when PKARR homeserver does not match the staging deploy; show a clear error toast and avoid republishing mismatched keys.

Resolves #2126

@infin1t3 infin1t3 added this to the v1.8.0 milestone Jul 14, 2026
@infin1t3 infin1t3 self-assigned this Jul 14, 2026
@infin1t3 infin1t3 added the 🐞 bug Something isn't working label Jul 14, 2026
@greptile-apps

greptile-apps Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds staging homeserver checks to auth restore and sign-in flows. The main changes are:

  • Added a wrong-environment auth error and localized toast copy.
  • Added staging homeserver detection and PKARR homeserver validation.
  • Blocked mismatched mnemonic, encrypted-file, Ring, and persisted-session restore paths.
  • Updated restore and route guard handling to show clear feedback after rejection.
  • Added focused tests for the new wrong-environment paths.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
src/config/network.ts Adds canonical staging homeserver detection from runtime config.
src/core/services/homeserver/homeserver.ts Adds PKARR homeserver validation before staging sign-in and restore checks.
src/core/application/auth/auth.ts Checks restored sessions against the staging homeserver guard and avoids retrying terminal environment errors.
src/core/controllers/auth/auth.ts Cleans local auth state and rethrows wrong-environment errors for UI feedback.
src/hooks/useAuthUrl/useAuthUrl.tsx Shows the wrong-environment Ring approval toast and expires the auth URL state.
src/providers/RouteGuardProvider/RouteGuardProvider.tsx Shows the wrong-environment persisted-restore toast from the route guard.
src/components/organisms/DialogRestoreRecoveryPhrase/DialogRestoreRecoveryPhrase.tsx Shows the wrong-environment recovery phrase restore toast.
src/components/organisms/DialogRestoreEncryptedFile/DialogRestoreEncryptedFile.tsx Shows the wrong-environment encrypted-file restore toast.

Reviews (5): Last reviewed commit: "fix(auth): fail closed on staging homese..." | Re-trigger Greptile

Comment thread src/config/network.ts
Comment thread src/core/controllers/auth/auth.ts
@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

🚀 Preview Deployment

URL: https://pubky-app-pr-2194-fzxmjul7ya-oa.a.run.app

pubky-app-pr-219490602c7

@infin1t3
infin1t3 marked this pull request as draft July 14, 2026 12:37
@infin1t3
infin1t3 marked this pull request as ready for review July 16, 2026 11:11
@infin1t3

Copy link
Copy Markdown
Collaborator Author

@greptileai review

@infin1t3 infin1t3 added the 📈 enhancement New feature or request label Aug 5, 2026
Reject mnemonic, encrypted-file, Pubky Ring, and session-restore auth
when the key's PKARR homeserver does not match a staging deploy:

- Declare deploy identity via a required PUBKY_RUNTIME_ENV
  ("production" | "staging") runtime value and drive
  isStagingHomeserverDeploy() from it, so config drift can never
  silently disable the guard. PR previews, the CI smoke test, and local
  dev declare theirs in-repo; deployed configs fail loudly at boot when
  it is missing.
- Fail closed on staging: a mismatched, absent, or unresolvable PKARR
  record blocks sign-in and never republishes the record. Outside
  staging, the sign-in self-heal republishes only a provably absent
  record - a failed lookup now propagates instead of force-overwriting
  a record that may point at another homeserver.
- Enforce the same check when restoring a persisted session: transient
  lookup failures retry like any other restore failure, and definitive
  mismatches clean up local state, surface a wrong-environment toast,
  and sign the rejected session out of its own homeserver (also on the
  Ring path) instead of leaving it dangling.
- Show the rejection toast across both restore dialogs and the Ring QR
  flow (expiring the stale auth URL), localized in all nine locales.

Closes #2126
@infin1t3
infin1t3 force-pushed the feat/2126-prevent-prod-signin-staging branch from c530ee6 to 90602c7 Compare August 5, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working 📈 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: Prevent accidental sign in with prod key on staging

1 participant