Skip to content

Bug - Telegram group: write_file checks writer permission against group:telegram:<id> instead of sender user #915

@rongxanh

Description

@rongxanh

Summary

In Telegram group chats, write_file is being authorized with:

  • userId = group:telegram:<group_id>

instead of the actual sender's Telegram user ID.

This breaks file-writer authorization in groups and causes write_file to fail before file creation.


Affected versions

Reproduced on:

  • v3.6.0
  • v3.7.1

Expected

For Telegram group messages:

  • group should remain the session/scope
  • sender should remain the acting user

So file-writer checks should use:

  • scope = group:telegram:<group_id>
  • user = <sender_user_id>

Actual

write_file fails with:
permission denied: only file writers can modify files in this group. Use /addwriter to get write access

Runtime/tool context shows the wrong principal:

{
  "userId": "group:telegram:<groupid>",
  "channel": "telegram",
  "sessionKey": "agent:<agent>:telegram:group:<groupid>"
}

This suggests group runs are assigning user_id to the group principal instead of the sender user.


Minimal evidence

[INFO] inbound: scheduling message (main lane) ... peerkind=group ... userid=group:telegram:<groupid>
[INFO] tool call ... tool=writefile
[WARN] tool error ... permission denied: only file writers can modify files in this group ...
Tool result:json
{
  "type": "tool.result",
  "payload": {
    "name": "writefile",
    "iserror": true,
    "result": "permission denied: only file writers can modify files in this group. Use /addwriter to get write access"
  },
  "userId": "group:telegram:<group_id>",
  "channel": "telegram"
}

Likely root cause

Telegram group inbound/runtime context appears to collapse:

  • group scope/session
  • acting user

into the same principal.

commands_writers.go seems to treat:

  • group = scope
  • sender = actor

But the tool runtime appears to treat:

  • group = scope
  • group = actor

Suggested fix

For Telegram group runs, keep these separate:

  • session/scope → group:telegram:<group_id>
  • acting user → actual Telegram sender user ID

Then run write_file auth against the sender user within the group scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1-highData loss, core logic broken — fix in sprintarea:channelsTelegram, Discord, channel managerarea:securitySecurity, injection, permissionsbugSomething isn't workingtelegram

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions