Skip to content

fix: migrate Telegram pairing allowFrom to default account only - #58165

Merged
jacobtomlinson merged 3 commits into
openclaw:mainfrom
pgondhi987:fix/fix-141
Mar 31, 2026
Merged

jacobtomlinson merged 3 commits into
openclaw:mainfrom
pgondhi987:fix/fix-141

Conversation

@pgondhi987

Copy link
Copy Markdown
Contributor

Summary

  • Problem: The legacy Telegram pairing allowFrom migration fanned out the store to every configured named account, requiring a read of all Telegram account IDs at migration time.
  • Why it matters: This created an unnecessary dependency on listTelegramAccountIds and could over-copy the allowFrom store to accounts that may not need it, causing unintended access broadening.
  • What changed: Migration now copies the legacy allowFrom store to only the default account, removing the fan-out logic and the listTelegramAccountIds dependency.
  • What did NOT change: WhatsApp auth migration, session migrations, and all other state migration paths are unaffected.

Change Type (select all)

  • Bug fix
  • Security hardening

Scope (select all touched areas)

  • Auth / tokens
  • Memory / storage

Linked Issue/PR

  • Related to upstream tracking issue

Root Cause / Regression History (if applicable)

  • Root cause: Fan-out migration logic read configured Telegram account IDs and copied the allowFrom store to each, which could spread pairing permissions more broadly than intended.
  • Missing detection / guardrail: No test verified that only the intended account received the migrated store.
  • Prior context: Introduced as part of multi-account Telegram support.
  • Why this regressed now: Security review identified the over-copy risk.
  • If unknown, what was ruled out: N/A

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
  • Target test or file: src/infra/state-migrations.test.ts, src/commands/doctor-state-migrations.test.ts
  • Scenario the test should lock in: Legacy Telegram allowFrom is copied only to the default account path; alpha and beta account paths do not receive a copy.
  • Why this is the smallest reliable guardrail: Directly exercises migration detection and execution paths.
  • Existing test that already covers this: Tests updated to reflect corrected behavior.
  • If no new test is added, why not: N/A — tests updated.

User-visible / Behavior Changes

Users running openclaw doctor on an instance with a legacy Telegram pairing allowFrom store will now migrate it to the default account only, rather than to every configured named Telegram account.

Diagram (if applicable)

Before:
legacy allowFrom.json → copy to telegram-alpha-allowFrom.json
                      → copy to telegram-beta-allowFrom.json

After:
legacy allowFrom.json → copy to telegram-default-allowFrom.json

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? Yes — migration now scopes copied pairing allowlist to default account only, reducing over-broad access propagation.
  • If any Yes, explain risk + mitigation: The change narrows the blast radius of the migration. No new access is granted; access to non-default named accounts is no longer auto-migrated.

Repro + Verification

Environment

  • OS: Linux
  • Runtime/container: Node 22+
  • Model/provider: N/A
  • Integration/channel: Telegram
  • Relevant config (redacted): Multi-account Telegram config with named accounts

Steps

  1. Have a legacy Telegram pairing allowFrom store at the legacy path
  2. Run openclaw doctor migration
  3. Verify only telegram-default-allowFrom.json is created

Expected

  • Only telegram-default-allowFrom.json created

Actual

  • Before fix: telegram-<accountId>-allowFrom.json created for every configured account

Evidence

  • Failing test/log before + passing after (tests updated to verify corrected behavior)

Human Verification (required)

  • Verified scenarios: Unit tests pass verifying correct migration target
  • Edge cases checked: No legacy file → no copy plans; already-migrated default → no copy plans
  • What you did not verify: Live gateway migration on a real multi-account Telegram instance

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Risks and Mitigations

  • Risk: Users with multiple named Telegram accounts will not have their allowFrom store migrated to those accounts automatically.
    • Mitigation: The default account migration covers the common case; named accounts can be configured manually if needed. The prior behavior (over-copying) posed a broader security risk.

🤖 AI-assisted PR (generated by Claude/Codex). Degree of testing: unit tests updated and verified passing. Author has reviewed the code changes and understands the behavior.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S labels Mar 31, 2026
@greptile-apps

greptile-apps Bot commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a security over-copy issue in the legacy Telegram pairing allowFrom migration. Previously, the migration fanned out the legacy allowFrom store to every configured named Telegram account ID (read via listTelegramAccountIds), which could spread pairing permissions more broadly than intended. The fix simplifies the migration to copy only to the DEFAULT_ACCOUNT_ID ("default") path — consistent with how WhatsApp auth migration already works — and removes the listTelegramAccountIds dependency from state-migrations.ts.

  • Core change: detectLegacyStateMigrations now unconditionally targets telegram-default-allowFrom.json instead of one file per configured account.
  • Idempotency preserved: The filter !fileExists(targetPath) still prevents re-copying if the default file already exists, so repeated migration runs are safe.
  • Side effect improvement: The old code silently skipped migration entirely if listTelegramAccountIds returned an empty list even when a legacy file existed; the new code always migrates as long as the legacy file is present and the default target is absent.
  • Tests updated: Both state-migrations.test.ts and doctor-state-migrations.test.ts are updated to assert the new single-target behavior and verify that alpha/beta named-account paths are NOT written.

Confidence Score: 5/5

This PR is safe to merge — the change is minimal, targeted, well-tested, and narrows (rather than expands) access.

No P0 or P1 issues found. The migration logic is correct and idempotent, the removed listTelegramAccountIds dependency was the only usage in this file, and all three changed files have consistent, comprehensive test coverage verifying both the positive case (default path written) and the negative case (named-account paths not written).

No files require special attention.

Important Files Changed

Filename Overview
src/infra/state-migrations.ts Removed listTelegramAccountIds import and replaced the fan-out copy-plan generation with a single plan targeting DEFAULT_ACCOUNT_ID. Logic is correct and idempotent.
src/infra/state-migrations.test.ts Tests correctly updated to expect a single default copy plan, and now additionally assert that alpha and beta paths do NOT exist after migration.
src/commands/doctor-state-migrations.test.ts Fan-out test updated to assert no copy to named bot accounts and verify only telegram-default-allowFrom.json is created; test name updated to reflect corrected behavior.

Reviews (1): Last reviewed commit: "fix: migrate Telegram pairing allowFrom ..." | Re-trigger Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 245a1be7df

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/infra/state-migrations.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dca9ada94c

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/infra/state-migrations.ts Resolved
@pgondhi987
pgondhi987 requested a review from a team as a code owner March 31, 2026 11:11
@openclaw-barnacle openclaw-barnacle Bot added channel: nostr Channel integration: nostr channel: telegram Channel integration: telegram agents Agent runtime and tooling size: L and removed size: XS labels Mar 31, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e359faa4d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread extensions/browser/src/browser/cdp.ts Resolved
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed channel: nostr Channel integration: nostr channel: telegram Channel integration: telegram agents Agent runtime and tooling size: L labels Mar 31, 2026
@jacobtomlinson
jacobtomlinson merged commit d8c68c8 into openclaw:main Mar 31, 2026
9 checks passed
singleGanghood pushed a commit to singleGanghood/openclaw that referenced this pull request Mar 31, 2026
…claw#58165)

* fix: migrate Telegram pairing allowFrom to default account only

* fix: address PR review feedback

* fix: address PR review feedback
vincentkoc pushed a commit that referenced this pull request Mar 31, 2026
* fix: migrate Telegram pairing allowFrom to default account only

* fix: address PR review feedback

* fix: address PR review feedback
steipete pushed a commit to Mlightsnow/openclaw that referenced this pull request Apr 1, 2026
…claw#58165)

* fix: migrate Telegram pairing allowFrom to default account only

* fix: address PR review feedback

* fix: address PR review feedback
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…claw#58165)

* fix: migrate Telegram pairing allowFrom to default account only

* fix: address PR review feedback

* fix: address PR review feedback
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…claw#58165)

* fix: migrate Telegram pairing allowFrom to default account only

* fix: address PR review feedback

* fix: address PR review feedback
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…claw#58165)

* fix: migrate Telegram pairing allowFrom to default account only

* fix: address PR review feedback

* fix: address PR review feedback
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
…claw#58165)

* fix: migrate Telegram pairing allowFrom to default account only

* fix: address PR review feedback

* fix: address PR review feedback
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…claw#58165)

* fix: migrate Telegram pairing allowFrom to default account only

* fix: address PR review feedback

* fix: address PR review feedback
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…claw#58165)

* fix: migrate Telegram pairing allowFrom to default account only

* fix: address PR review feedback

* fix: address PR review feedback
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…claw#58165)

* fix: migrate Telegram pairing allowFrom to default account only

* fix: address PR review feedback

* fix: address PR review feedback
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
…claw#58165)

* fix: migrate Telegram pairing allowFrom to default account only

* fix: address PR review feedback

* fix: address PR review feedback
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…claw#58165)

* fix: migrate Telegram pairing allowFrom to default account only

* fix: address PR review feedback

* fix: address PR review feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants