@goodandready/dsh-messenger-gateway 0.4.35 → 0.4.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/README.ru.md +0 -0
- package/README.zh.md +0 -0
- package/lib/adapters/telegram.js +0 -0
- package/lib/client.js +2 -2
- package/lib/config.js +1 -1
- package/lib/documents.js +15 -3
- package/lib/file-manager.js +0 -0
- package/lib/gateway-commands.js +0 -0
- package/lib/gateway.js +0 -0
- package/lib/http.js +0 -0
- package/lib/index.js +12 -3
- package/lib/webapp.js +20 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -146,6 +146,9 @@ In addition to Telegram, outbound messages can be dispatched to Discord and Slac
|
|
|
146
146
|
- `allowlistMode`: `closed` (default) or `open` — **closed** refuses every unknown user (fail-closed): a fresh install admits nobody until the admin approves a pairing code (`/start` → approve in the settings card); **open** admits all users when the allowlist is empty — enable it explicitly only for public assistant bots, the settings card and `/status` surface the exposure
|
|
147
147
|
- `security.trustProxy`: `false` (default) — loopback-trusted requests must carry a pinned `localhost` / `127.0.0.1` / `[::1]` Host (DNS rebinding defense). Enable only behind a trusted local reverse proxy that rewrites the Host header
|
|
148
148
|
- `/get` and `/files` require allowlisted users and never serve hidden (dot) files
|
|
149
|
+
- `telegram.proxyUrl` is a secret: the settings API returns only a masked value and an empty field keeps the configured proxy
|
|
150
|
+
- Inbound archives are extraction-capped (per-entry and per-archive budget verified against actual bytes — a lying ZIP header cannot balloon the heap)
|
|
151
|
+
- Mini App artifacts are chat-scoped: a Telegram user sees only artifacts produced in their own chat; allowlisted admins see all
|
|
149
152
|
- `sessionList`: `true` (default) — enables `/sessions` and `/resume` commands in chat
|
|
150
153
|
- `sessionTitleFromChat`: `false` (default) — name each new session after its originating chat (`TG · @user`, `TG · Group › topic N`) instead of generic generated titles
|
|
151
154
|
- `voiceMode`: `mirror` / `always` / `off` — when to speak replies (also `/voice`)
|
package/README.ru.md
CHANGED
|
File without changes
|
package/README.zh.md
CHANGED
|
File without changes
|
package/lib/adapters/telegram.js
CHANGED
|
File without changes
|
package/lib/client.js
CHANGED
|
@@ -111,7 +111,7 @@ window.__ModuleLoader__.load({
|
|
|
111
111
|
webhookSecretConfigured: 'Secret set',
|
|
112
112
|
webhookSecretRequired: 'Secret required',
|
|
113
113
|
proxyUrl: 'Proxy URL (HTTP, HTTPS, SOCKS5)',
|
|
114
|
-
proxyUrlHint: 'Optional proxy for Telegram API requests (e.g. socks5://127.0.0.1:1080 or http://127.0.0.1:8080).',
|
|
114
|
+
proxyUrlHint: 'Optional proxy for Telegram API requests (e.g. socks5://127.0.0.1:1080 or http://127.0.0.1:8080). Leave empty to keep the configured proxy.',
|
|
115
115
|
apiRoot: 'Custom Telegram Bot API Base URL',
|
|
116
116
|
apiRootHint: 'Custom API root for reverse proxies or local Bot API servers. Default: https://api.telegram.org',
|
|
117
117
|
workingDir: 'Working directory (agent.cwd)',
|
|
@@ -265,7 +265,7 @@ window.__ModuleLoader__.load({
|
|
|
265
265
|
webhookSecretConfigured: '密钥已设置',
|
|
266
266
|
webhookSecretRequired: '必须设置密钥',
|
|
267
267
|
proxyUrl: '代理地址 (HTTP, HTTPS, SOCKS5)',
|
|
268
|
-
proxyUrlHint: 'Telegram API 请求的可选代理(例如 socks5://127.0.0.1:1080 或 http://127.0.0.1:8080
|
|
268
|
+
proxyUrlHint: 'Telegram API 请求的可选代理(例如 socks5://127.0.0.1:1080 或 http://127.0.0.1:8080)。留空保持当前代理。',
|
|
269
269
|
apiRoot: '自定义 Telegram Bot API 地址',
|
|
270
270
|
apiRootHint: '用于反向代理或本地 Bot API 服务器的自定义根地址。默认:https://api.telegram.org',
|
|
271
271
|
workingDir: '工作目录 (agent.cwd)',
|
package/lib/config.js
CHANGED
|
@@ -57,7 +57,7 @@ export const PluginConfig = z.object({
|
|
|
57
57
|
webhookUrl: z.string().default(''),
|
|
58
58
|
webhookSecret: z.string().role('secret').default(''),
|
|
59
59
|
webhookPath: z.string().default('/dsh-messenger-gateway/telegram/webhook'),
|
|
60
|
-
proxyUrl: z.string().default('').description('Proxy for Telegram Bot API calls: http(s)://[user:pass@]host:port or socks5://[user:pass@]host:port (socks5h/socks are aliases). Empty = take from the environment (TELEGRAM_PROXY/HTTPS_PROXY/ALL_PROXY); off/none/direct = never use a proxy'),
|
|
60
|
+
proxyUrl: z.string().role('secret').default('').description('Proxy for Telegram Bot API calls: http(s)://[user:pass@]host:port or socks5://[user:pass@]host:port (socks5h/socks are aliases). Empty = take from the environment (TELEGRAM_PROXY/HTTPS_PROXY/ALL_PROXY); off/none/direct = never use a proxy'),
|
|
61
61
|
apiRoot: z.string().default('').description('Custom Telegram Bot API root URL (default: https://api.telegram.org)'),
|
|
62
62
|
voiceMode: z.union([z.const('mirror'), z.const('always'), z.const('off')]).default('mirror')
|
|
63
63
|
.description('mirror: TTS when inbound was voice; always/off override (per-user /voice wins)'),
|
package/lib/documents.js
CHANGED
|
@@ -107,7 +107,9 @@ export function extractDocxText(buffer) {
|
|
|
107
107
|
let xmlStr = ''
|
|
108
108
|
try {
|
|
109
109
|
if (compMethod === 8) {
|
|
110
|
-
|
|
110
|
+
// word/document.xml for a real docx stays far below this cap; a
|
|
111
|
+
// bomb stream is cut off instead of ballooning the heap (#199).
|
|
112
|
+
xmlStr = inflateRawSync(compData, { maxOutputLength: 16 * 1024 * 1024 }).toString('utf8')
|
|
111
113
|
} else {
|
|
112
114
|
xmlStr = compData.toString('utf8')
|
|
113
115
|
}
|
|
@@ -179,6 +181,7 @@ export function extractZipEntries(buffer, opts = {}) {
|
|
|
179
181
|
const entries = []
|
|
180
182
|
let pos = cdOffset
|
|
181
183
|
let totalUncompressed = 0
|
|
184
|
+
let extractedBytes = 0
|
|
182
185
|
|
|
183
186
|
for (let idx = 0; idx < totalEntries && idx < maxEntries; idx++) {
|
|
184
187
|
if (pos + 46 > buffer.length) break
|
|
@@ -221,13 +224,22 @@ export function extractZipEntries(buffer, opts = {}) {
|
|
|
221
224
|
const compData = buffer.subarray(dataStart, dataStart + compSize)
|
|
222
225
|
|
|
223
226
|
let content = null
|
|
224
|
-
|
|
227
|
+
// The declared uncompressed size is attacker-controlled: treat it only as a
|
|
228
|
+
// fast-path skip, cap every inflate with maxOutputLength (#199), and count
|
|
229
|
+
// the ACTUAL bytes against the archive-wide budget.
|
|
230
|
+
const canExtract = uncompSize <= maxFileBytes
|
|
231
|
+
&& extractedBytes < maxUncompressedBytes
|
|
232
|
+
&& (TEXT_INJECT_EXTS.has(ext) || !ext)
|
|
225
233
|
if (canExtract) {
|
|
226
234
|
try {
|
|
227
235
|
if (compMethod === 8) {
|
|
228
|
-
|
|
236
|
+
const budget = Math.max(1, Math.min(maxFileBytes, maxUncompressedBytes - extractedBytes))
|
|
237
|
+
const inflated = inflateRawSync(compData, { maxOutputLength: budget })
|
|
238
|
+
extractedBytes += inflated.length
|
|
239
|
+
content = inflated.toString("utf8")
|
|
229
240
|
} else if (compMethod === 0) {
|
|
230
241
|
content = compData.toString("utf8")
|
|
242
|
+
extractedBytes += content.length
|
|
231
243
|
}
|
|
232
244
|
} catch {
|
|
233
245
|
content = null
|
package/lib/file-manager.js
CHANGED
|
File without changes
|
package/lib/gateway-commands.js
CHANGED
|
File without changes
|
package/lib/gateway.js
CHANGED
|
File without changes
|
package/lib/http.js
CHANGED
|
File without changes
|
package/lib/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import { listHomes } from './homes.js'
|
|
14
14
|
export { plainConfig } from './config.js'
|
|
15
15
|
import { Config, plainConfig, resolveInternalBaseUrl } from './config.js'
|
|
16
|
-
import { describeProxy } from './proxy.js'
|
|
16
|
+
import { describeProxy, maskProxyUrl } from './proxy.js'
|
|
17
17
|
import { readSecrets, restoreSecrets } from './secret-guard.js'
|
|
18
18
|
import { setupSettings } from './settings-bridge.js'
|
|
19
19
|
import { resolveEffectiveCwd, getCwdWarning } from './workspace.js'
|
|
@@ -36,7 +36,7 @@ function resolveConfig(raw) {
|
|
|
36
36
|
return cfg
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
function publicConfig(cfg, gw, ctx) {
|
|
39
|
+
export function publicConfig(cfg, gw, ctx) {
|
|
40
40
|
const internalBaseURL = gw?.baseUrl?.() || resolveInternalBaseUrl(cfg, ctx)
|
|
41
41
|
const proxy = describeProxy(cfg.telegram?.proxyUrl)
|
|
42
42
|
return {
|
|
@@ -69,7 +69,8 @@ function publicConfig(cfg, gw, ctx) {
|
|
|
69
69
|
webhookPath: cfg.telegram.webhookPath,
|
|
70
70
|
webhookSecretConfigured: Boolean(String(cfg.telegram.webhookSecret || '').trim()),
|
|
71
71
|
botTokenConfigured: Boolean(String(cfg.telegram.botToken || '').trim()),
|
|
72
|
-
|
|
72
|
+
proxyUrlConfigured: Boolean(String(cfg.telegram.proxyUrl || '').trim()),
|
|
73
|
+
proxyUrlMasked: maskProxyUrl(cfg.telegram.proxyUrl || ''),
|
|
73
74
|
apiRoot: cfg.telegram.apiRoot || '',
|
|
74
75
|
proxyActive: Boolean(proxy.active),
|
|
75
76
|
proxyLabel: proxy.label || '',
|
|
@@ -686,6 +687,14 @@ export function apply(ctx, config) {
|
|
|
686
687
|
const cur = source()
|
|
687
688
|
const nextTg = { ...cur.telegram, ...(payload.telegram || {}) }
|
|
688
689
|
if (payload.telegram && !String(payload.telegram.botToken || '').trim()) nextTg.botToken = cur.telegram.botToken
|
|
690
|
+
// proxyUrl is a secret: empty value or an echoed mask means "keep the
|
|
691
|
+
// stored proxy" (#200)
|
|
692
|
+
if (payload.telegram && Object.prototype.hasOwnProperty.call(payload.telegram, 'proxyUrl')) {
|
|
693
|
+
const incoming = String(payload.telegram.proxyUrl || '').trim()
|
|
694
|
+
if (!incoming || incoming.includes(':***@') || incoming === maskProxyUrl(cur.telegram.proxyUrl || '')) {
|
|
695
|
+
nextTg.proxyUrl = cur.telegram.proxyUrl
|
|
696
|
+
}
|
|
697
|
+
}
|
|
689
698
|
if (payload.telegram && Object.prototype.hasOwnProperty.call(payload.telegram, 'webhookSecret') && !String(payload.telegram.webhookSecret || '').trim()) {
|
|
690
699
|
nextTg.webhookSecret = cur.telegram.webhookSecret
|
|
691
700
|
}
|
package/lib/webapp.js
CHANGED
|
@@ -621,11 +621,12 @@ export function createWebAppHandler(options = {}) {
|
|
|
621
621
|
if (initData) {
|
|
622
622
|
const val = validateTelegramWebAppData(initData, botToken)
|
|
623
623
|
if (val.ok) {
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
624
|
+
// Gateway-aware allowlist check (#201): honors allowlistMode — in the
|
|
625
|
+
// default closed mode an empty allowlist admits nobody (fail-closed),
|
|
626
|
+
// previously a non-empty check only.
|
|
627
|
+
const uid = Number(val.user?.id)
|
|
628
|
+
if (gw?.isUserAllowed && !gw.isUserAllowed(uid)) {
|
|
629
|
+
return { ok: false, error: 'user_not_allowed' }
|
|
629
630
|
}
|
|
630
631
|
return { ok: true, user: val.user, initData: val }
|
|
631
632
|
}
|
|
@@ -678,7 +679,15 @@ export function createWebAppHandler(options = {}) {
|
|
|
678
679
|
if (!auth.ok) return writeJson(res, 401, { ok: false, error: auth.error })
|
|
679
680
|
|
|
680
681
|
const limit = Number(url.searchParams.get('limit')) || 30
|
|
681
|
-
const
|
|
682
|
+
const uid = Number(auth.user?.id || 0)
|
|
683
|
+
// Allowlist membership (not open-mode admission) defines an admin:
|
|
684
|
+
// in open mode everyone authenticates, so chat scoping stays meaningful.
|
|
685
|
+
const isAdmin = Array.isArray(tgCfg.allowedUserIds) && tgCfg.allowedUserIds.includes(uid)
|
|
686
|
+
const all = gw?.artifactStore ? gw.artifactStore.list(limit) : []
|
|
687
|
+
// Chat isolation (#201): an authenticated Mini App user sees only
|
|
688
|
+
// artifacts produced in their own private chat (chatId === userId);
|
|
689
|
+
// allowlisted admins see the whole store.
|
|
690
|
+
const artifacts = all.filter((a) => isAdmin || (uid && String(a.chatId || '') === String(uid)))
|
|
682
691
|
return writeJson(res, 200, { ok: true, artifacts })
|
|
683
692
|
}
|
|
684
693
|
|
|
@@ -691,6 +700,11 @@ export function createWebAppHandler(options = {}) {
|
|
|
691
700
|
|
|
692
701
|
const artifact = gw?.artifactStore?.get(id)
|
|
693
702
|
if (!artifact) return writeJson(res, 404, { ok: false, error: 'not found' })
|
|
703
|
+
const uid = Number(auth.user?.id || 0)
|
|
704
|
+
const isAdmin = Array.isArray(tgCfg.allowedUserIds) && tgCfg.allowedUserIds.includes(uid)
|
|
705
|
+
if (!isAdmin && String(artifact.chatId || '') !== String(uid)) {
|
|
706
|
+
return writeJson(res, 403, { ok: false, error: 'forbidden' })
|
|
707
|
+
}
|
|
694
708
|
|
|
695
709
|
return writeJson(res, 200, { ok: true, artifact })
|
|
696
710
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@goodandready/dsh-messenger-gateway",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.36",
|
|
4
4
|
"description": "Telegram messenger bridge for DeepSeek Harness: sessions, steer, homes, inline asks, notify bridge, and optional TTS voice notes.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|