Repository navigation
fix(telegram): resolve local Bot API container file paths against trustedLocalFileRoots [AI-assisted] - #91984
Conversation
c7a96c2 to
c673c34
Compare
|
Codex review: stale review; fresh review needed. Summary Next step Review history (1 earlier review cycle)
|
…stedLocalFileRoots When the self-hosted telegram-bot-api server runs with --local inside a container, getFile returns absolute file_path values rooted at the container data dir (/var/lib/telegram-bot-api/...). The host process mounts that volume at a different path, so the absolute path never matches a trustedLocalFileRoots entry and inbound media fails to materialize (messages reach the agent as bare <media:document> placeholders without bytes). Map container-absolute paths back to relative candidates and resolve them under each trusted root, trying both with and without the per-token directory segment the local server uses. Relative file_path values are now also resolved against trusted roots before falling back to the HTTP file endpoint, which keeps large-file (>20MB) local-mode downloads working. Path traversal protections: candidates are normalized, NUL bytes and dot-segments are rejected, and reads stay behind the trusted-roots file-access sandbox. AI-assisted (Claude Code), validated with targeted vitest run. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Dizesales <[email protected]>
Co-authored-by: Lucas Magalhaes <[email protected]>
c673c34 to
353e3bf
Compare
|
Land-ready maintainer rebuild completed on exact head
Live proof: the contributor reproduced and fixed the path against a production OpenClaw gateway plus |
|
Merged via squash.
|
…stedLocalFileRoots [AI-assisted] (openclaw#91984) * fix(telegram): resolve local Bot API container file paths against trustedLocalFileRoots When the self-hosted telegram-bot-api server runs with --local inside a container, getFile returns absolute file_path values rooted at the container data dir (/var/lib/telegram-bot-api/...). The host process mounts that volume at a different path, so the absolute path never matches a trustedLocalFileRoots entry and inbound media fails to materialize (messages reach the agent as bare <media:document> placeholders without bytes). Map container-absolute paths back to relative candidates and resolve them under each trusted root, trying both with and without the per-token directory segment the local server uses. Relative file_path values are now also resolved against trusted roots before falling back to the HTTP file endpoint, which keeps large-file (>20MB) local-mode downloads working. Path traversal protections: candidates are normalized, NUL bytes and dot-segments are rejected, and reads stay behind the trusted-roots file-access sandbox. AI-assisted (Claude Code), validated with targeted vitest run. Co-Authored-By: Claude Fable 5 <[email protected]> Co-Authored-By: Dizesales <[email protected]> * fix(telegram): map local Bot API container media paths Co-authored-by: Lucas Magalhaes <[email protected]> * chore(config): refresh channel metadata --------- Co-authored-by: Lucas Magalhaes <[email protected]> Co-authored-by: Dizesales <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
Related: #100092
What Problem This Solves
Fixes an issue where users of a Dockerized self-hosted Telegram Bot API would have inbound documents reach the agent as placeholders without bytes when
getFilereturned the container-absolute/var/lib/telegram-bot-api/...path but OpenClaw saw the same volume at a different trusted host path.The contributor reproduced this on a production OpenClaw gateway with
aiogram/telegram-bot-api:latest,TELEGRAM_LOCAL=1, and a host volume configured intrustedLocalFileRoots. Before the fix, the message reached the agent butmedia/inboundstayed empty.Why This Change Was Made
The maintainer rebuild maps only the official local Bot API absolute-path contract into operator-configured trusted roots. It supports data-root and per-token-root mounts, including the upstream colon-to-tilde token-directory behavior, while keeping ordinary relative paths on the existing HTTP download path.
Every local read still goes through
fsRoot().read(). Missing mapped candidates may try the next bounded mount shape; policy, symlink, permission, and size failures remain visible instead of being swallowed. Unknown absolute roots, empty segments, NULs, and dot segments are rejected.No new config is added. The existing
trustedLocalFileRootsdocumentation and generated channel metadata now explain the container-volume mapping.User Impact
Operators can mount a self-hosted Telegram Bot API data directory at a different host path and still receive the actual attachment bytes. Existing cloud Bot API and relative-path downloads are unchanged, and configured trusted roots remain the filesystem authority.
Evidence
aiogram/telegram-bot-api:latest; a 499 KB zip materialized undermedia/inboundafter the path mapping was applied as a dist-level hotfix.tdlib/telegram-bot-apidocuments absolutefile_pathvalues in--localmode; upstreamClient.cppat0a9e5696ba149c99bedf972f040d2e28776a8a4fconfirms the per-token directory and colon-to-tilde behavior.node scripts/run-vitest.mjs extensions/telegram/src/bot.media.stickers-and-fragments.e2e.test.ts extensions/telegram/src/bot/delivery.resolve-media-retry.test.ts— 2 files, 47 tests passed, including a real fs-safe host-volume read.tbx_01kwqczycnebqzzhqbdecsy2c4: the same 47 focused tests passed;check:changedandcheck:docspassed.node --import tsx scripts/generate-bundled-channel-config-metadata.ts --checkpassed after refreshing generated metadata.Proof gap: the maintainer did not move a shared Telegram credential from the cloud Bot API into a dedicated local Bot API during review. The live server proof is the contributor's production run; the rebuilt source patch is additionally covered by actual-host-filesystem E2E and Testbox proof.
AI-assisted (Claude Code on the original contribution; maintainer rebuild and review with Codex).