Repository navigation
fix(telegram): read the whole connect code, not the first displayed group (TASK-153) - #1931
Merged
Merged
Conversation
…roup (TASK-153) The connectors page renders the code grouped in fours for readability (`1964 774b a58c …`), and the webhook split the text on whitespace and read `args[0]` — so typing or selecting the displayed command sent only `1964`, answered "Invalid or expired code", and burned one of the chat's five rate-limited attempts per try. Everything after the command is now the code with whitespace removed. Minted codes are 32 hex chars with no internal whitespace, so joining cannot merge two codes; it can only reassemble the one that was shown. Witnesses: the spaced form binds (and the lookup carries the joined code), a spaced code that matches nothing still refuses, and one displayed command spends one attempt rather than one per group.
This was referenced Sep 27, 2026
lilyshen0722
added a commit
to thantiklermcirony/commonly
that referenced
this pull request
Oct 9, 2026
…tempt (TASK-157) (Team-Commonly#1932) Two follow-ups to Team-Commonly#1931 at the same call site. 1. Lowercase the code after joining it. Codes are minted lowercase (`crypto.randomBytes(16).toString('hex')`) and the lookup is exact, so a keyboard that capitalised one group refused a correct code. 2. Refuse anything that is not 32 hex characters BEFORE `registerEnableAttempt`. A minted code has a checkable shape, so a typo ("/commonly-enable 1964") currently spends one of the chat's five tries for nothing. The malformed path gets its own message and is left to the route's outer rate limiter; guessing stays metered because only a well-formed code can ever match. Order in the handler: usage -> shape -> attempt counter -> lookup. Witnesses assert the counter's value: a well-formed wrong code spends exactly one attempt, and four malformed shapes spend none. Fixture fallout from the shape gate is disclosed in the PR body.
lilyshen0722
added a commit
to thantiklermcirony/commonly
that referenced
this pull request
Oct 9, 2026
…hipped (Team-Commonly#1936) Records the live Telegram re-walk of 2026-09-27 (02:43–02:47Z): the code typed exactly as displayed, spaced and with a capitalised group, binds on the first try (Team-Commonly#1931, Team-Commonly#1932); a second gated pod relays its agent's line to the chat while a typed line goes only to the active pod; C3 and C5 inbound green. Marks the 7ccc6ac C1 red as fixed, TASK-151 as shipped (Team-Commonly#1929 on f5eb556) and TASK-155 as shipped (Team-Commonly#1933 on 9a6253f). Open: TASK-156. Claude-Session: https://claude.ai/code/session_01MCF2UK3EQ6z6EHdvxAkM44 Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
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.
Why
The connectors page renders the Telegram connect code grouped in fours for readability —
V2ConnectorsPage.tsx:191groupCode, rendered at:1262as/commonly-enable 1964 774b a58c …— and the webhook split the text on whitespace and passedargs[0]tohandleEnableCommand(routes/webhooks/telegram.ts:444). So a user who types or selects the command they are shown sends one four-character group, gets "❌ Invalid or expired code. Please request a fresh code from Commonly.", and burns one of the chat's five rate-limited attempts per try (ENABLE_ATTEMPT_LIMIT = 5, ten-minute window). Only the Copy button — which copies the raw code — worked.Reproduced live on
7ccc6ac2at 05:06 PDT by the C1 walk: the spaced command refused, the same code unspaced got past validation.The change
One line, at the call site: everything after the command is the code with its whitespace removed.
Why joining is safe rather than merely convenient: a minted code is 32 hex characters with no internal whitespace (
telegramConnectCode.mintConnectCode,crypto.randomBytes(16).toString('hex')), so joining cannot merge two codes into one — it can only reassemble the one that was displayed. A bare/commonly-enablestill yields''and therefore the same usage message as before, becauseargs[0]was alreadyundefinedthere.handleEnableCommanditself is untouched: it still does one lookup, one attempt registration and one expiry check, so the rate limiter's shape does not move.Not changed, deliberately: the grouped display (the row keeps it — it is readable, and now it is also typeable), the Copy button, and the exact-match lookup. One flag for the gate: the lookup is case-sensitive and codes are minted lowercase, so a keyboard that capitalises a group would still refuse. I did not add a
toLowerCase()— the row's spec isargs.join('')and the walk reproduced only the spacing — but it is the same class of "the displayed form must be accepted", and it is a one-line follow-up if you want it ruled that way.Witnesses
In
telegram.webhook.connectCode.test.js, alongside the existing cases:config.connectCode === JOINED_CODE, so it pins the contract rather than only the happy path;Ledger
Baseline committed first (
6840ed6b), each arm reverted withgit checkout --, all arms green before and after:args[0]M2 is not surgical, and the reason is worth recording rather than smoothing over: a faithful per-token counter registers eight attempts on an eight-group code, which exhausts the five-attempt budget and therefore suppresses the lookup too. So at this limit the counter witness cannot be reddened on its own; its independent contribution is that it pins the counter for a spaced command, which the pre-existing suite (single-token commands only) cannot see. No mutation survived.
Verification
telegram.webhook.connectCode.test.js: 9/9 pass on Node 22.telegram.webhook.test.js+telegramConnectCode.test.js— 2 suites / 30 tests pass (the/commonly-enable abc123cases are unaffected).routes/webhooks/telegram.ts0 errors (its fourmax-lenwarnings are pre-existing and not on the changed line); the touched.jstest file is at exactly its baseline profile — 12 errors, 0 warnings, measured withnpx eslint --stdin --stdin-filenameagainst the same file atHEAD~1rather than assumed, because that corpus is not CI-gated.Gate: Vera.