Repository navigation
Conversation
Greptile SummaryThis PR adds a disk-backed webhook queue to survive Telegram gateway restarts — enqueuing payloads atomically before processing and dequeuing them after successful completion, with replay-on-startup. The overall design is sound and the test coverage is thorough. Key issues found:
Confidence Score: 2/5
Last reviewed commit: ee28245 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee282452cc
ℹ️ 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".
ee28245 to
59d25b3
Compare
🔒 Aisle Security AnalysisWe found 3 potential security issue(s) in this PR:
1. 🟠 Telegram webhook response can be delayed up to 10s by awaiting deferred timers (DoS risk)
DescriptionThe new deferred-work tracking causes the Telegram update middleware to await timers/debounced work before considering an update “processed”. In webhook mode, the HTTP handler awaits GrammY’s Impact:
Why it happens (data flow):
Maximum wait (observed in code):
Vulnerable code: // src/telegram/bot.ts
await next();
const deferred = deferredWork.get(updateId);
if (deferred) {
deferredWork.delete(updateId);
await Promise.all(deferred); // waits for timeouts/debounces
}
opts.onUpdateProcessed?.(updateId);RecommendationDecouple webhook acknowledgement from deferred buffering timers. Options (pick one or combine):
// after await next()
const deferred = deferredWork.get(updateId);
deferredWork.delete(updateId);
void Promise.allSettled(deferred ?? []).then(() => {
opts.onUpdateProcessed?.(updateId);
});This allows
const MAX_DEFERRED_WAIT_MS = 250; // e.g., keep well under Telegram webhook expectations
await Promise.race([
Promise.all(deferred),
new Promise<void>((r) => setTimeout(r, MAX_DEFERRED_WAIT_MS)),
]);
opts.onUpdateProcessed?.(updateId);
Also consider:
2. 🟡 Unbounded startup replay of persisted Telegram webhooks can cause denial of service
DescriptionThe Telegram webhook startup path replays all queued webhook payloads synchronously before the HTTP server starts listening, creating an unbounded-work startup phase that can be abused or triggered by backlog accumulation. Impact (DoS):
Vulnerable code (startup replay blocks listener): const pending = await replayPendingWebhooks(queueChannelId, opts.stateDir);
for (const entry of pending) {
await bot.handleUpdate(entry.payload as Parameters<typeof bot.handleUpdate>[0]);
}Note: RecommendationAdd explicit operational bounds and avoid blocking startup on unbounded replay. Suggested mitigations (combine as appropriate):
const MAX_REPLAY = 500; // or config-driven
const REPLAY_DEADLINE_MS = 5000; // time budget
const deadline = Date.now() + REPLAY_DEADLINE_MS;
const pending = await replayPendingWebhooks(queueChannelId, opts.stateDir, { limit: MAX_REPLAY });
for (const entry of pending) {
if (Date.now() > deadline) break;
await bot.handleUpdate(entry.payload as Parameters<typeof bot.handleUpdate>[0]);
}
These changes prevent attacker-triggered or failure-induced backlog from making the service unable to restart. 3. 🔵 Symlink/TOCTOU arbitrary file write via on-disk webhook queue (untrusted stateDir/queueDir)
DescriptionThe on-disk webhook queue performs filesystem operations (mkdir/writeFile/rename/readFile/unlink) on paths derived from If an attacker on the same host can influence
Concrete local exploit scenario (privilege impact depends on how the service is deployed):
Vulnerable code: await fs.promises.mkdir(queueDir, { recursive: true, mode: 0o700 });
...
await fs.promises.writeFile(tmp, JSON.stringify(entry), { encoding: "utf-8", mode: 0o600 });
await fs.promises.rename(tmp, filePath);RecommendationHarden directory and file handling against symlink/hardlink/TOCTOU attacks:
Example hardening sketch: import fs from "node:fs";
async function assertSafeDir(dir: string) {
const st = await fs.promises.lstat(dir).catch((e) => {
if (e && typeof e === "object" && "code" in e && (e as any).code === "ENOENT") return null;
throw e;
});
if (st) {
if (!st.isDirectory() || st.isSymbolicLink()) throw new Error(`Unsafe queue dir: ${dir}`);
if (typeof st.mode === "number" && (st.mode & 0o022) !== 0) throw new Error(`Queue dir is writable by group/other: ${dir}`);
}
}
async function ensureQueueDir(queueDir: string): Promise<void> {
await fs.promises.mkdir(queueDir, { recursive: true, mode: 0o700 });
await assertSafeDir(queueDir);
await fs.promises.chmod(queueDir, 0o700).catch(() => {});
}Also consider documenting that Analyzed PR: #40056 at commit Last updated on: 2026-03-10T14:16:26Z |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 59d25b30ff
ℹ️ 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".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7a10ea2956
ℹ️ 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".
|
Security-model assessment per SECURITY.md: OpenClaw runs as a trusted-operator gateway, not an adversarial multi-tenant service. The operator controls the filesystem, config, and state directory.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f4efe448d4
ℹ️ 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".
|
|
||
| // Sort oldest first; break timestamp ties deterministically by deduplicationId. | ||
| entries.sort( | ||
| (a, b) => a.enqueuedAt - b.enqueuedAt || a.deduplicationId.localeCompare(b.deduplicationId), |
There was a problem hiding this comment.
Preserve numeric update order for replay tie-breaks
In replayPendingWebhooks, tie-breaking with localeCompare reorders numeric Telegram update_ids lexicographically (for example, "100" sorts before "99"), so updates enqueued in the same millisecond can replay out of chronological order. Because deduplicationId is populated from String(update_id), this can happen during burst traffic and cause message handling state to be reconstructed in the wrong sequence after restart.
Useful? React with 👍 / 👎.
f4efe44 to
ffb1339
Compare
|
Closing to resubmit with a clean commit history and updated PR description. New PR incoming from the same branch. |
Problem
Telegram webhook mode acknowledges messages with 200 OK immediately. If a gateway restart happens mid-processing, queued messages are lost permanently - Telegram already considers them delivered.
Solution
Persist inbound webhook payloads to disk before processing. On restart, replay any unprocessed payloads.
How it works
enqueueWebhook()writes the raw payload to~/.openclaw/webhook-queue/<deduplicationId>.jsonvia atomic rename (write to.tmp, thenrename)dequeueWebhook()deletes the file after successful processingreplayPendingWebhooks()scans the queue directory and re-dispatches any remaining payloads inenqueuedAtorder (withdeduplicationIdtie-breaking for same-timestamp bursts)Security
.tmpfiles (from crashes between write and rename) are cleaned up during replayConfig
No config needed - webhook queue activates automatically for Telegram webhook mode. Queue directory is created lazily on first webhook.
Supersedes #34702 (force-push after rebase broke reopen).
Validation
pnpm build-- cleanpnpm check-- cleanpnpm test src/infra/webhook-queue.test.ts-- passedAI Disclosure
AI-assisted (Claude). Fully tested and reviewed.
Closes #42157