Skip to content

fix(nextcloud-talk): bound concurrent pre-auth webhook reads - #138278

Closed
masatohoshino wants to merge 6 commits into
openclaw:mainfrom
masatohoshino:nextcloud-talk-preauth-inflight
Closed

masatohoshino wants to merge 6 commits into
openclaw:mainfrom
masatohoshino:nextcloud-talk-preauth-inflight

Conversation

@masatohoshino

@masatohoshino masatohoshino commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Related: the SMS channel's equivalent
change
— prior art for the shape, not a
prerequisite.

Scope: one production file (extensions/nextcloud-talk/src/monitor.ts), one existing test
file, and one bullet in docs/channels/nextcloud-talk.md recording the new 503 outcome.

What Problem This Solves

The Nextcloud Talk channel runs its own HTTP listener — createNextcloudTalkWebhookServer
calls node:http's createServer (monitor.ts:119,149), started by
monitor-runtime.ts:96,135 on the operator-configured host and port — and reads the request
body before verifying the signature. Each read is bounded to 64 KiB and 5 s
(monitor.ts:18,21,96-105), but nothing capped how many ran at once, so any client that can
reach the port and satisfy the pre-read checks below could occupy those reads by uploading
slowly.

It takes an unauthenticated but protocol-shaped request: POST to the configured path, a
JSON content type, x-nextcloud-talk-signature and x-nextcloud-talk-random merely
present — neither is validated at this stage — and, where the account declares a backend
URL, an x-nextcloud-talk-backend matching it. None of these authenticate the caller: the
first two are unchecked until after the read, and the third is a value to know rather than a
secret to prove.

What is claimed here is the absence of a bound, not observed starvation. The capture below
holds 512 unauthenticated reads: the base admits all 512, and a correctly signed delivery sent
while they are held still returns 200 and reaches the spool. So the listener keeps serving
with 512 reads open, and this PR does not claim otherwise. What it claims is that no
application-level cap exists — 512 is the number the harness opened, not a limit the code
imposed.

Why This Change Was Made

Nothing before the read bounds repetition. isBackendAllowed is () => true unless a
backend URL is declared (monitor-runtime.ts:101-107). The failed-auth rate limiter cannot
help by construction: createAuthRateLimiter (src/gateway/auth-rate-limit.ts:183) answers
check() from entry.attempts, appended to only by recordFailure, which
verifyWebhookSignature reaches only after a read completes with a bad signature
(monitor.ts:73-94, recordFailure at :88). A caller that never finishes a body is never
counted.

This patch changes monitor.ts to bound the concurrency with createWebhookInFlightLimiter
(src/plugin-sdk/webhook-request-guards.ts:125), exported to plugins since e1ec51b1a4a, an
ancestor of this base:

  • one limiter per server, created inside createNextcloudTalkWebhookServer and acquired with
    one fixed key. The limiter counts per key in a map owned by the instance
    (webhook-request-guards.ts:131-155), so one instance plus one key is one budget for the
    listener;
  • acquired after the header and backend checks, immediately before the body read;
  • excess requests answered 503 through sendHttpRequestRejection — that refusal reaches
    its own sender before its connection closes;
  • released in a finally around the read and signature check, before the spool, which is
    downstream of authentication;
  • the 413 and 408 answers moved inside that block. Left in the outer catch they would
    run after the new finally, freeing the slot mid-teardown. The teardown is the helper's
    ordering: sendHttpRequestRejection awaits rejection.closed
    (src/infra/http-request-lifecycle.ts:286), resolved on the socket's close after
    setTimeout(rejection.destroy, REJECTION_CLOSE_TIMEOUT_MS) — one second (:10,:173).

503, not 429 is a local retryability decision. This file answers 500 on admission
failure and says why at monitor.ts:197-198 — "Nextcloud retries only a few times ... append
failure must remain retryable". This is an analogy, not protocol evidence: that comment is
about an append failure, not about a capacity refusal, and it is the repository's own statement
about the sender rather than a measurement. What it establishes is which status class this file
already treats as worth retrying; there is no corresponding statement for 429. Whether a
deployed Nextcloud redelivers a refused webhook is unverified either way. 503 is a new user-visible outcome for this
channel, so accepting it on that basis is a maintainer product call; the operator-facing half is
recorded in docs/channels/nextcloud-talk.md ("a 503 here reports load rather than a
misconfiguration ... Whether Nextcloud redelivers a refused webhook depends on its own sender
behavior").

64 is a new effective cap for this listener. It bounds how many requests are inside the
guarded region at once, and that region is wider than the read alone: it runs from just before
readBody through signature verification to the finally. So the cap is on unauthenticated
work in flight, not only on bytes being read. The value is taken from
PRE_AUTH_MAX_IN_FLIGHT (extensions/sms/src/webhook.ts:31, passed as maxInFlightPerKey
at :115), where the other standalone listener bounds its own pre-authentication reads —
prior art for the number, not a shared policy, and nothing here couples the two. It caps
concurrent admitted readBody operations, each of which may buffer up to the 64 KiB
pre-authentication limit. Whether 64 suits a bot webhook receiving one delivery per chat
event is a judgement rather than a measurement; no traffic data is offered for it, and it is
a one-constant change to revise.

Out of scope. The listener keeps its own node:http server rather than registering through
registerWebhookTargetWithPluginRoute; the failed-auth limiter keeps its semantics; no other
channel is touched.

User Impact

At most 64 requests occupy the guarded region at once — the budget applies after the method,
header and backend checks, and covers everything from just before the body read to the end of
signature verification. A request arriving while it is full is answered 503, which is a new
outcome here: a delivery that would previously have entered the read can now be refused before
it. That refusal is final for that request; what may succeed later is a redelivery, once a slot
has freed. 413 and 408 keep their existing responses. Cases 2 and 4 below show a valid
delivery returning 200 after the budget was filled and drained, on the 413 path and on the
signature-rejection path; case 3 shows the route still serving after a timed-out read, which is
liveness rather than proof that that request returned its slot. No operator-configurable option
is added; the default behavior is what changes.

Three shapes occupy the budget: slow uploads, each holding a slot for as long as its read runs,
up to 5 s — the original defect; oversized bodies, rejected on crossing the 64 KiB cap and then
holding their slot for the rejection's teardown, which the shared lifecycle bounds at one
second; and completed bodies still inside signature verification, which is a synchronous HMAC
and therefore brief, but is inside the region rather than after it.

Evidence

Four cases in the channel's existing wire test file,
extensions/nextcloud-talk/src/monitor.replay.test.ts, under
createNextcloudTalkWebhookServer pre-authentication concurrency. They drive the real
createNextcloudTalkWebhookServer on a loopback port over raw sockets, so the status line and
connection outcome are observed independently of fetch. Fixtures carry what the pre-read
checks need; the requests that occupy the budget carry a placeholder signature (never examined
in cases 1 and 3, whose reads never complete, and in case 2, whose reads end at the 64 KiB cap
before verification; deliberately invalid in case 4), and every
delivery asserted to return 200 carries a real signature from the channel's fixture helper.

  1. answers 503 on the wire once the pre-auth read budget is full — 64 readers held at an
    injected barrier, then one more request asserted on the wire: status line,
    connection: close, JSON body, server-side close, unadvanced counter;
  2. returns an over-limit body's slot, so later deliveries still land — 64 oversized requests
    issued together, each answered 413; past the rejection grace a valid signed delivery gets
    200. That 200 shows at least one slot came back, not that all 64 did — one free slot
    serves one delivery. What covers the other 63 is that all 64 are asserted to receive their 413, that answer is given
    inside the guarded region, and the release is an unconditional finally on that path, so
    each of the 64 released on its own. The hold itself is bounded by a wall-clock grace inside a
    shared owner, and asserting it is still held would mean racing that clock on the runner, so
    this case deliberately asserts only the deterministic half;
  3. answers a stalled upload with 408 on the wire and does not wedge the route — a request
    declaring 4096 bytes and sending one is answered 408 after the 5 s read timeout, and a
    delivery 1500 ms later gets 200. This holds one request against a budget of 64, so that
    200 shows the route still serves; it does not establish that the timed-out request
    returned its slot, since 63 were free regardless. The release ordering for that block is
    what case 2 covers — both branches are the same rejectWebhookRequest call in the same
    position, inside the same finally;
  4. releases the slot a rejected signature took, so later deliveries still land — 64 reads are
    admitted and parked at an injected barrier, the barrier is opened, each completes and is then
    rejected by signature verification, and a valid delivery afterwards returns 200. As in case
    2, that 200 shows at least one slot; the other 63 rest on all 64 taking the same
    unconditional release.
node scripts/run-vitest.mjs run extensions/nextcloud-talk/src/monitor.replay.test.ts
      Tests  16 passed (16)

node scripts/run-vitest.mjs run extensions/nextcloud-talk/
 Test Files  26 passed (26)
      Tests  184 passed (184)

Reverting monitor.ts to the base gives Tests 1 failed | 15 passed (16): case 1 fails, since
it asserts a 503 that exists only with the budget. Cases 2-4 pass either way — they guard the
new mechanism against leaking slots or wedging the route rather than demonstrating the defect.

Behavior addressed: the listener applies no application-level cap on concurrent
pre-authentication body reads.

Real environment tested: Linux, Node v24.18.0. A standalone probe — not part of this diff;
the in-tree reproducer is the regression above — starts the real listener on a loopback port and
drives it over real TCP. It opens 512 connections carrying the four headers the pre-read checks
require and a Content-Length for the real payload, writes one byte on each and stops, then
sends one more request, sends a correctly signed delivery while saturated, writes the remaining
bytes on all 512, and sends the signed delivery again. admittedToSpool counts calls into the
listener's onWebhook handler — the point past authentication where a delivery is accepted — and
each arm runs its own process, so the counters start at zero on both sides.
reachedBodyRead counts requests whose
body produced at least one chunk, so it measures the 512 holders only: the extra request sends
headers and no body, and therefore never advances the counter on either arm. Whether it was
admitted is read from its own answer instead — a 408 after the full 5 s read budget means it
entered the read; a 503 in under a millisecond means it did not.

Exact steps or command run after this patch:

HOLD=512 ./node_modules/.bin/tsx nt-preauth-probe.mts

Both arms run the same script in their own checkout. monitor.ts-blob is git hash-object of
the file the process actually loaded, so each side is identifiable independently of the branch
name. The script is not in this diff and is not fetchable from it, so a reviewer cannot re-run
this command: the reproduction anyone can run is the committed wire test above, which asserts
the same boundary on the same listener. The probe is here because it reaches 512 connections and
the real production reader on both arms, which the test file does not.

Before evidence: base 7167fb6f195, blob c4c245a234c, which equals
git rev-parse 7167fb6f195:extensions/nextcloud-talk/src/monitor.ts.

repo-head=7167fb6f1959e9ecb9381e33c4c0a36b6865459a  monitor.ts-blob=c4c245a234ca0122bda32ff18f653b18fcfb4ef7
held=512  reachedBodyRead=512
overflow: reachedBodyRead=512 status="HTTP/1.1 408 Request Timeout" heldForMs=5001
overflow body: "{\"error\":\"Request body timeout\"}"
while saturated: signedDelivery=200 admittedToSpool=1
after release: signedDelivery=200 admittedToSpool=2

All 512 are admitted. The extra request is admitted too: 408 after 5001 ms is the
pre-authentication read timeout (PREAUTH_WEBHOOK_BODY_TIMEOUT_MS, monitor.ts:21) firing,
which only happens inside the read it entered.

Evidence after fix: head 802c408b5fe, blob 76fc3634a58.

repo-head=802c408b5fe9b6065547a45d842b2c6500961e1e  monitor.ts-blob=76fc3634a58e1f052f4aa512a8eeb03778ee90be
held=512  reachedBodyRead=64
overflow: reachedBodyRead=64 status="HTTP/1.1 503 Service Unavailable" heldForMs=0
overflow body: "{\"error\":\"Pre-authentication capacity exhausted\"}"
while saturated: signedDelivery=503 admittedToSpool=0
after release: signedDelivery=200 admittedToSpool=1

Observed result after fix: reachedBodyRead stops at exactly the bound — 512 → 64 — and the
extra request is answered 503 in under a millisecond instead of entering a read and timing out
after 5001 ms. The while saturated
line is the cost this PR imposes
, measured rather than argued: a correctly signed delivery that
returns 200 on the base is refused with 503 on the branch. The line after it shows the
capacity is not leaked — once the held connections finish, a subsequent identical signed
delivery is admitted. The refused request itself is over; the listener does not retry it.

What was not tested: no deployed Nextcloud server, so its handling of the refusal is not
demonstrated — whether it redelivers a refused webhook is its own sender behavior, and the docs
bullet says so rather than asserting it. No claim is made that deliveries stop arriving at
today's scale; see the note above.

Known risk, deferred: this listener does not serialise responses through
runHttpConnectionRequest (src/infra/http-request-lifecycle.ts:75), so on a pipelined
connection a refusal that closes the socket can cut a response owed to an earlier request. The
existing 413 and 408 answers already close the socket the same way; the new 503 adds one
more occasion. It holds for the other standalone listeners too, so the fix is a shared seam
rather than a change here, and a local attempt at it broke the channel's existing suite. Not
carried in this PR; happy to open an issue for it.

All file and line references are against base 7167fb6f1959e9ecb9381e33c4c0a36b6865459a.

@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@masatohoshino
masatohoshino marked this pull request as ready for review September 4, 2026 13:23
@openclaw-barnacle openclaw-barnacle Bot added channel: nextcloud-talk Channel integration: nextcloud-talk size: M labels Sep 4, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 2:00 PM ET / 18:00 UTC.

ClawSweeper review

What this changes

This PR caps concurrent unauthenticated Nextcloud Talk webhook body reads at 64 and returns HTTP 503 when the listener is full.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 8 items remain

Keep open. The capacity proof is strong, but the prior P1 remains: a pipelined overflow rejection can close a connection before an earlier signed delivery finishes durable admission and sends its required 200 response. The new 503 outcome also has no verified Nextcloud redelivery contract.

Priority: P1
Reviewed head: 802c408b5fe9b6065547a45d842b2c6500961e1e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The real-boundary proof for the limiter is strong, but the unresolved P1 durable-ack loss makes this patch not ready to merge.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The changed production listener is started on loopback and exercised over raw TCP: 64 held pre-auth reads produce an observed 503 with connection closure, then recovery paths admit valid signed deliveries; supplied terminal evidence reports the focused test suite passing after the change.
Patch quality 🧂 unranked krab (1/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed production listener is started on loopback and exercised over raw TCP: 64 held pre-auth reads produce an observed 503 with connection closure, then recovery paths admit valid signed deliveries; supplied terminal evidence reports the focused test suite passing after the change.
Evidence reviewed 7 items Introduced overflow trigger: The PR introduces the full-budget branch that sends a connection-closing 503 before reading the request body; its raw recorded parent is the PR merge base.
Earlier durable response can still be pending: After releasing the new pre-auth slot, the listener awaits durable admission before writing 200; the adjacent durable-ack test explicitly holds that admission and verifies the response remains unsettled.
Canonical ordering contract: The lifecycle owner serializes per-connection admission and waits for the prior response when given it. Its boundary test proves an earlier 200 precedes a later rejection, while the adjacent no-response-owner case observes an empty wire after closure.
Findings 1 actionable finding [P1] Serialize the overload rejection behind earlier durable responses
Security None None.

How this fits together

Nextcloud Talk receives signed events through a standalone HTTP listener, which reads and authenticates the request before sending accepted events to durable inbound storage. The limiter sits before body reading, while durable acknowledgment happens later in the same request.

flowchart LR
  Sender[Nextcloud webhook sender] --> Headers[Header and backend checks]
  Headers --> Budget[Pre-auth capacity budget]
  Budget -->|available| Verify[Read body and verify signature]
  Budget -->|full| Reject[503 and connection close]
  Verify -->|valid| Durable[Durable inbound admission]
  Durable --> Ack[HTTP 200 acknowledgment]
Loading

Decision needed

Question Recommendation
Should this PR add a generic Plugin SDK connection-ordering seam and repair the standalone listener, rather than merge a new connection-closing 503 path that can preempt an earlier durable acknowledgment? Add a generic ordering seam: Expose a narrow plugin-facing connection-ordering helper, wrap the listener, and prove valid-then-overflow ordering before merge.

Why: The existing ordering owner is core-internal, while direct core imports from the plugin violate the extension boundary; choosing and exposing a supported generic seam is maintainer-owned API direction.

Before merge

  • Serialize the overload rejection behind earlier durable responses (P1) - The new overflow branch closes the connection while an earlier signed request can still await onWebhook before its required durable 200. This listener bypasses the response-aware ordering owner; its boundary test shows an earlier uncommitted response can leave the wire empty when a later rejection closes the socket. Expose and use a generic Plugin SDK ordering seam, then cover valid-then-overflow on one raw keep-alive connection. This is the still-unfixed prior finding; monitor.ts is unchanged since the prior reviewed head.
  • Resolve merge risk (P1) - A valid earlier request can lose its required durable 200 when a later pipelined request reaches the new connection-closing 503 branch.
  • Resolve merge risk (P1) - The documentation correctly says whether Nextcloud redelivers a saturated 503 is sender-dependent, but that retry behavior has not been verified; overload could therefore become message loss.
  • Resolve merge risk (P1) - The bug fix has a net production increase of 52 lines because the required generic ordering capability is not currently exposed to plugins.
  • Complete next step (P2) - Add a generic plugin-facing connection-ordering seam, wrap the full listener dispatch, and prove a raw keep-alive valid-then-overflow sequence preserves the earlier durable 200; verify Nextcloud 503 retry behavior or obtain explicit maintainer acceptance.
  • Improve patch quality - Expose a generic plugin-facing connection-ordering seam, wrap the listener, and add raw keep-alive valid-then-overflow proof.
  • Improve patch quality - Verify Nextcloud’s retry handling for HTTP 503 or obtain explicit maintainer acceptance of that delivery tradeoff.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

  • [P1] Serialize the overload rejection behind earlier durable responses — extensions/nextcloud-talk/src/monitor.ts:201-207
Agent review details

Security

None.

PR surface

Source +52, Tests +203, Docs +1. Total +256 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 72 20 +52
Tests 1 203 0 +203
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 276 20 +256

Review metrics

Metric Value Why it matters
Production versus test delta production +52; tests +203; docs +1 The positive production growth implements a needed bound but should be absorbed by the chosen generic ordering seam rather than leave a standalone lifecycle variant.

Merge-risk options

Maintainer options:

  1. Repair ordering before merge (recommended)
    Add the supported ordering seam and a raw pipelined durable-ack/overflow regression so a valid prior delivery cannot be cut off.
  2. Accept the 503 behavior explicitly
    A maintainer may accept the unverified redelivery tradeoff only after recording why a saturated valid delivery may be refused.
  3. Pause for listener architecture
    Pause this PR if the generic SDK contract is not acceptable for this channel boundary.

Technical review

Best possible solution:

Expose a narrow generic Plugin SDK connection-ordering seam, use it around the complete standalone listener dispatch, and add a raw keep-alive valid-then-overflow regression proving the earlier durable 200 is delivered before closure.

Do we have a high-confidence way to reproduce the issue?

Yes—source-reproducible: an existing lifecycle boundary test demonstrates that a rejection behind an unfinished earlier response produces no wire output without response-aware ordering, and this PR adds that rejection trigger to the standalone listener.

Is this the best way to solve the issue?

No. The limiter addresses the unbounded-read problem, but the standalone dispatch bypasses the canonical ordering owner; a narrow generic Plugin SDK seam is the maintainable repair.

Full review comments:

  • [P1] Serialize the overload rejection behind earlier durable responses — extensions/nextcloud-talk/src/monitor.ts:201-207
    The new overflow branch closes the connection while an earlier signed request can still await onWebhook before its required durable 200. This listener bypasses the response-aware ordering owner; its boundary test shows an earlier uncommitted response can leave the wire empty when a later rejection closes the socket. Expose and use a generic Plugin SDK ordering seam, then cover valid-then-overflow on one raw keep-alive connection. This is the still-unfixed prior finding; monitor.ts is unchanged since the prior reviewed head.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against b6a4d0dad430.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦞 diamond lobster and patch quality is 🧂 unranked krab.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P1: The introduced overload branch can suppress an already-admitted signed channel delivery’s durable acknowledgment.
  • merge-risk: 🚨 message-delivery: A connection-closing overflow response can prevent an earlier valid request on the same keep-alive connection from receiving its required 200.
  • merge-risk: 🚨 availability: The new fixed capacity limit intentionally refuses valid deliveries under load, and retry behavior for that refusal is unverified.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦞 diamond lobster and patch quality is 🧂 unranked krab.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (terminal): The changed production listener is started on loopback and exercised over raw TCP: 64 held pre-auth reads produce an observed 503 with connection closure, then recovery paths admit valid signed deliveries; supplied terminal evidence reports the focused test suite passing after the change.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production listener is started on loopback and exercised over raw TCP: 64 held pre-auth reads produce an observed 503 with connection closure, then recovery paths admit valid signed deliveries; supplied terminal evidence reports the focused test suite passing after the change.

Evidence

What I checked:

  • Introduced overflow trigger: The PR introduces the full-budget branch that sends a connection-closing 503 before reading the request body; its raw recorded parent is the PR merge base. (extensions/nextcloud-talk/src/monitor.ts:201, 33fee45e68bd)
  • Earlier durable response can still be pending: After releasing the new pre-auth slot, the listener awaits durable admission before writing 200; the adjacent durable-ack test explicitly holds that admission and verifies the response remains unsettled. (extensions/nextcloud-talk/src/monitor.durable-ack.test.ts:8, 802c408b5fe9)
  • Canonical ordering contract: The lifecycle owner serializes per-connection admission and waits for the prior response when given it. Its boundary test proves an earlier 200 precedes a later rejection, while the adjacent no-response-owner case observes an empty wire after closure. (src/infra/http-request-lifecycle.test.ts:251, 802c408b5fe9)
  • Standalone listener bypasses the ordering owner: Nextcloud Talk creates its own Node HTTP server and dispatches each request through an independent async handler; the public webhook guard facade exports rejection transport but not the connection-ordering runner. (extensions/nextcloud-talk/src/monitor.ts:167, 802c408b5fe9)
  • Current main and release do not contain this change: Current main and v2026.9.1 still read the body before signature verification without an in-flight limiter; no stable tag contains the PR head or its production commit. (extensions/nextcloud-talk/src/monitor.ts:149, ad6fe23aecb9)
  • Real transport proof covers the intended bound: The added test starts the production listener on loopback, holds 64 body reads, and observes the overflow 503, JSON body, Connection: close, and server close over raw TCP; supplied PR evidence reports the focused suite passing and failing when the production limiter is reverted. (extensions/nextcloud-talk/src/monitor.replay.test.ts:498, 802c408b5fe9)

Likely related people:

  • Peter Steinberger: Raw commit d7e280f adds src/infra/http-request-lifecycle.ts:75 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d7e280fcf690; files: src/infra/http-request-lifecycle.ts)
  • Eden: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Pavan Kumar Gondhi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-04T13:35:21.642Z sha 7d5db4ef1a90d815e01bd17c68f619bd1980fc7a :: blocked before merge. :: [P1] Serialize requests before an overload rejection closes the socket
  • reviewed 2026-09-04T13:56:06.928Z sha 7d5db4ef1a90d815e01bd17c68f619bd1980fc7a :: blocked before merge. :: [P1] Serialize pipelined requests before closing an overload connection
  • reviewed 2026-09-04T15:45:43.678Z sha b1a9c2da7542cd5725018b4e467bdddd84615ae3 :: blocked before merge. :: [P1] Serialize pipelined requests before closing an overload connection
  • reviewed 2026-09-04T16:09:51.959Z sha 4e88c59 :: blocked before merge. :: [P1] Serialize before closing an overloaded connection

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 4, 2026

@sylvesterkaczmarek sylvesterkaczmarek left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bounding the unauthenticated body-read phase is the right control; the failed-auth limiter cannot help requests that never finish a body and therefore never reach signature verification. Acquiring immediately before readBody and releasing only after rejection teardown preserves the actual scarce resource, not just handler entry. The measured cost is also stated correctly: a valid signed delivery can receive 503 while the pre-auth budget is saturated. I would keep that behaviour explicit in operator docs because retryability depends on Nextcloud’s sender semantics, which this PR does not prove.

@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Sep 4, 2026
The Nextcloud Talk channel runs its own HTTP listener and reads the request
body before verifying the signature. Each read is bounded to 64 KiB and 5 s,
but there was no application-level cap on how many ran at once, so any client
that can reach the port could occupy those reads by opening connections and
uploading slowly. No credentials are needed: the signature is not checked
until after the read, and the checks that do run first are not authentication.

The failed-auth rate limiter cannot cover this. It decides from attempts
recorded by recordFailure, which is only reached once a read completes and its
signature turns out invalid, so a caller that never finishes a body is never
counted.

Bound the concurrency with the shared createWebhookInFlightLimiter, one budget
of 64 per listener. Excess requests are refused with 503 rather than 429: this
handler already depends on the sender retrying a 5xx, answering 500 on
admission failure so the delivery stays retryable, and it records no such
expectation for 429, so a refusal the sender may not redeliver would turn a
capacity limit into silent message loss.

The 413 and 408 answers move inside the guarded block so a rejected request
keeps its slot until the response has been delivered, which the shared
rejection lifecycle bounds at one second.

Measured with 512 held connections: the base admits all 512 and holds the next
request's read for the full 5 s budget, while a correctly signed delivery sent
during saturation still returns 200. On this change admission stops at 64, the
next request is refused in 3 ms, and the signed delivery is refused with 503 —
the disclosed cost — then admitted again once the held connections finish.
@masatohoshino
masatohoshino force-pushed the nextcloud-talk-preauth-inflight branch from 0c5f912 to 4e88c59 Compare September 4, 2026 16:01
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 4, 2026
@masatohoshino

Copy link
Copy Markdown
Contributor Author

Applied — the ## Notes section of docs/channels/nextcloud-talk.md now reads:

The number of webhook body reads running before signature verification is bounded. While that budget is saturated, a delivery is answered HTTP 503 before its body is read, including a correctly signed one. Capacity frees as the in-flight reads finish, and a redelivery of the same event is then accepted normally; the refused request itself is over. The bound is fixed and not configurable, so a 503 here reports load rather than a misconfiguration. Whether Nextcloud redelivers a refused webhook depends on its own sender behavior.

The last two sentences go past making the behavior visible, on purpose: the bound is not configurable, so an operator who sees this 503 has no setting to change; and the refused request is finished, so what may come back is a redelivery, which is the sender's decision rather than this listener's.

On retryability, the repository's own statement is the comment at extensions/nextcloud-talk/src/monitor.ts:197-198 — "Nextcloud retries only a few times ... append failure must remain retryable" — and an append failure reaches 500 at monitor.ts:224. That is why I chose a 5xx here: it is the class this file already treats as retryable. I do not have evidence that 429 is unsuitable — this file simply records no expectation about it — so this is a repository-consistent choice rather than a demonstrated one. How a deployed Nextcloud actually treats the refusal is unverified, and the PR body says so under "What was not tested".

Two other corrections since your review:

  • Case 2's claim was too strong. Saturating the budget with 413s and then getting one 200 shows at least one slot came back, not that all 64 did. The other 63 rest on all 64 being asserted to receive their 413 (extensions/nextcloud-talk/src/monitor.replay.test.ts, returns an over-limit body's slot, so later deliveries still land), that answer being given inside the guarded region, and the release being an unconditional finally on that path. Fixed in the test name, its comment, and the body.
  • Rebased onto main at 7167fb6f195, with both proof arms re-run at that base and at the current head. Captures and commands are in the Evidence section.

@clawsweeper — on the two Before-merge items:

  1. 503 retryability. Asking that the repository-owned half be considered addressed by the docs bullet above, with the deployed-Nextcloud behaviour left open and disclosed rather than assumed.
  2. Ordering seam. The invariant: on a keep-alive connection, a response owed to an earlier request must be delivered before a later request's connection-closing refusal. runHttpConnectionRequest (src/infra/http-request-lifecycle.ts:75) enforces it, and its only callers are in the gateway (src/gateway/server-http.ts:212,233, src/gateway/server-http-upgrades.ts:450); the standalone plugin listeners — this one, extensions/feishu/src/monitor.transport.ts:386, extensions/telegram/src/webhook.ts, extensions/voice-call/src/webhook.ts — do not use it. In this listener the property predates this PR: 413 and 408 already close the connection the same way. I tried the local fix and it is not one: wrapping this handler in runHttpConnectionRequest makes a raw-socket pipelining reproduction pass and also makes the existing extensions/nextcloud-talk suite time out. That experiment is not recorded in this PR; I can add the reproduction and both outputs if that would help the decision. I am proposing to defer, not deciding it: is deferral acceptable, and if so would you prefer an issue or a note here? I will do it in this PR instead if you would rather it landed together.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by current main.

The original problem — unbounded concurrent pre-authentication webhook body reads — is now addressed on main with the shared webhook in-flight limiter. The current listener also runs requests through the repository's connection-ordering owner rather than this PR's standalone rejection path, which was the remaining P1 concern in the review.

Given that the needed behavior has landed through a different implementation, continuing to repair this older branch would duplicate current main rather than improve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: nextcloud-talk Channel integration: nextcloud-talk docs Improvements or additions to documentation merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants