-
Notifications
You must be signed in to change notification settings - Fork 12.9k
fix(telegram): use CSPRNG for pairing codes and lock down store permissions#2722
Open
dweekly wants to merge 1 commit into
Open
fix(telegram): use CSPRNG for pairing codes and lock down store permissions #2722dweekly wants to merge 1 commit into
dweekly wants to merge 1 commit into
Conversation
...ssions Pairing codes are an auth boundary — the first pairer can be promoted to owner — but they were generated with Math.random, whose internal state is recoverable from prior outputs, letting an attacker predict upcoming codes. Switch to crypto.randomInt (uniform, no modulo bias). Also restrict the pairing store to owner-only access: dir 0700, file 0600. writeFileSync's mode only applies at file creation, so a stale .tmp left by a crash would carry its old permissions through the rename — remove it before writing. Add a regression test asserting the store lands at 0600 (skipped on Windows). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jun 10, 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.
Type of Change
Description
Pairing codes gate chat registration, and the first pairer can be promoted to owner — but
generateCodedrew them fromMath.random, which is predictable from observed outputs. Switched tocrypto.randomInt.Also locks down the pairing store, which holds pending codes in plaintext: directory
0700, file0600.writeFileSync'smodeonly applies when the file is created, so a stale.tmpleft by a crash could carry old permissions through the rename; it's now removed before writing.Tested: new regression test asserts the store file lands at
0600(skipped on Windows);telegram-pairing.test.tspasses 27/27. These files also typecheck and pass the full suite when copied into a trunk install. Note for reviewers:tscon thechannelsbranch tip fails for pre-existing, unrelated reasons (telegram.tsreferencesresolveChannelName, absent from this branch'sChannelAdapter), same as noted in #2552.