fix(telegram): reject unsafe topic targets · openclaw/openclaw@e890d7e
steipete
·
2026-05-29
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +import { parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime"; |
| 2 | + |
1 | 3 | export type TelegramTarget = { |
2 | 4 | chatId: string; |
3 | 5 | messageThreadId?: number; |
@@ -102,18 +104,32 @@ export function parseTelegramTarget(to: string): TelegramTarget {
|
102 | 104 | |
103 | 105 | const topicMatch = /^(.+?):topic:(\d+)$/.exec(normalized); |
104 | 106 | if (topicMatch) { |
| 107 | +const messageThreadId = parseStrictNonNegativeInteger(topicMatch[2]); |
| 108 | +if (messageThreadId === undefined) { |
| 109 | +return { |
| 110 | +chatId: normalized, |
| 111 | +chatType: resolveTelegramChatType(normalized), |
| 112 | +}; |
| 113 | +} |
105 | 114 | return { |
106 | 115 | chatId: topicMatch[1], |
107 | | -messageThreadId: Number.parseInt(topicMatch[2], 10), |
| 116 | + messageThreadId, |
108 | 117 | chatType: resolveTelegramChatType(topicMatch[1]), |
109 | 118 | }; |
110 | 119 | } |
111 | 120 | |
112 | 121 | const colonMatch = /^(.+):(\d+)$/.exec(normalized); |
113 | 122 | if (colonMatch) { |
| 123 | +const messageThreadId = parseStrictNonNegativeInteger(colonMatch[2]); |
| 124 | +if (messageThreadId === undefined) { |
| 125 | +return { |
| 126 | +chatId: normalized, |
| 127 | +chatType: resolveTelegramChatType(normalized), |
| 128 | +}; |
| 129 | +} |
114 | 130 | return { |
115 | 131 | chatId: colonMatch[1], |
116 | | -messageThreadId: Number.parseInt(colonMatch[2], 10), |
| 132 | + messageThreadId, |
117 | 133 | chatType: resolveTelegramChatType(colonMatch[1]), |
118 | 134 | }; |
119 | 135 | } |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。