Skip to content

fix(telegram): read the whole connect code, not the first displayed group (TASK-153) - #1931

Merged
lilyshen0722 merged 1 commit into
mainfrom
kai/task153-enable-joined-code
Sep 27, 2026
Merged

lilyshen0722 merged 1 commit into
mainfrom
kai/task153-enable-joined-code

Conversation

@lilyshen0722

Copy link
Copy Markdown
Contributor

Why

The connectors page renders the Telegram connect code grouped in fours for readability — V2ConnectorsPage.tsx:191 groupCode, rendered at :1262 as /commonly-enable 1964 774b a58c … — and the webhook split the text on whitespace and passed args[0] to handleEnableCommand (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 7ccc6ac2 at 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.

await handleEnableCommand(chat, args.join(''));

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-enable still yields '' and therefore the same usage message as before, because args[0] was already undefined there.

handleEnableCommand itself 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 is args.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:

  1. the spaced form binds — and the assertion is on the lookup key, config.connectCode === JOINED_CODE, so it pins the contract rather than only the happy path;
  2. a spaced code that matches nothing still refuses — asserting the joined query and the refusal copy, so the fix cannot pass by short-circuiting into "always accept";
  3. one displayed command spends one attempt, not one per group — after a spaced attempt the chat has four of its five attempts left; the sixth command is refused with too many attempts.

Ledger

Baseline committed first (6840ed6b), each arm reverted with git checkout --, all arms green before and after:

mutation red
M1 the join reverted to args[0] the spaced-binds witness + the spaced-refuses witness (both assert the joined query); the counter witness stays green — correct, since reading only the first token still spends one attempt
M2 the join kept, but one attempt registered per token the counter witness and the pre-existing rate-limit test and the spaced-binds witness

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.
  • Siblings: telegram.webhook.test.js + telegramConnectCode.test.js — 2 suites / 30 tests pass (the /commonly-enable abc123 cases are unaffected).
  • eslint: routes/webhooks/telegram.ts 0 errors (its four max-len warnings are pre-existing and not on the changed line); the touched .js test file is at exactly its baseline profile — 12 errors, 0 warnings, measured with npx eslint --stdin --stdin-filename against the same file at HEAD~1 rather than assumed, because that corpus is not CI-gated.

Gate: Vera.

…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.
@lilyshen0722
lilyshen0722 added this pull request to the merge queue Sep 27, 2026
Merged via the queue into main with commit 912e6a1 Sep 27, 2026
14 checks passed
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]>
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.

1 participant