Skip to content

fix(models): reject oversized piped auth input - #109800

Merged
steipete merged 1 commit into
openclaw:mainfrom
Pick-cat:fix/models-auth-stdin-limit
Jul 18, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
Pick-cat:fix/models-auth-stdin-limit

Conversation

@Pick-cat

@Pick-cat Pick-cat commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where openclaw models auth paste-token and paste-api-key accumulated piped stdin without any size limit, allowing arbitrarily large input to buffer in memory before reaching downstream validation.

Why This Change Was Made

The readPipedStdin() helper now enforces a 1 MiB cap (matching the existing MATRIX_CLI_RECOVERY_KEY_STDIN_MAX_BYTES and CONFIG_PATCH_STDIN_MAX_BYTES limits). The rejection happens at the stream boundary — during the read loop, not after buffering — so oversized input never reaches auth processing.

The change follows the same buffer-chunk pattern used in the Matrix recovery-key stdin fix (PR #108120): collect Buffer chunks, track totalBytes per chunk, and throw before the cap is exceeded. Normal TTY and small piped input paths are unchanged.

Collision check: searched open PRs for readPipedStdin, models auth stdin, paste-token unbounded — no same-file or same-problem open PR found.

User Impact

Piped auth commands now fail with an explicit size error for oversized input instead of buffering unbounded data. Normal interactive entry and direct arguments are unaffected.

Evidence

Exact head: 12be34c454b75916fcf481916dec7998105820df

Format / diff check

$ ./node_modules/.bin/oxfmt --check src/commands/models/auth.ts src/commands/models/auth.test.ts
All matched files use the correct format.

$ git diff --check
# exit 0

Real CLI proof (local, Node 24.18.0, pnpm dev)

Normal small piped API key reaches auth validation:

$ printf 'sk-test123456789\n' | OPENCLAW_STATE_DIR=/tmp/openclaw-test-proof     pnpm dev models auth paste-api-key --provider openai
...
Updated config: /tmp/openclaw-test-proof/openclaw.json
Auth profile: openai:manual (openai/api_key)

Oversized piped input (1 MiB + 1 byte) rejected at the stdin boundary:

$ node -e 'process.stdout.write("x".repeat(1048577))' |     OPENCLAW_STATE_DIR=/tmp/openclaw-test-proof     pnpm dev models auth paste-api-key --provider openai
Error: Piped auth input exceeds 1048576 bytes.

Standalone proof (loopback stream, calls real production function)

$ node --import tsx proof-models-auth-stdin-limit.mts

  ok: small piped input does not trigger size rejection
  info: small_error=Failed to update auth profile store; ...
  ok: oversized piped input is rejected
  ok: rejection message is "Piped auth input exceeds 1048576 bytes."
  info: oversized_error=Piped auth input exceeds 1048576 bytes.

=== Summary ===
ALL PROOF ASSERTIONS: 3 passed, 0 failed

Tests

$ node scripts/run-vitest.mjs src/commands/models/auth.test.ts
 Test Files  1 passed (1)
      Tests  40 passed (40)

New test "rejects oversized piped auth input before buffering it" verifies the exact error message and confirms no downstream auth mutation.

Mutation check

Reverted the fix to bare input += String(chunk) loop with no cap:

$ git checkout HEAD~1 -- src/commands/models/auth.ts
$ node scripts/run-vitest.mjs src/commands/models/auth.test.ts
 Test Files  1 failed (1)
      Tests  1 failed | 39 passed (40)

Oversized input passes through to validate() which reports "That does not look like an OpenAI API key." instead of the size rejection. Restored fix → 40/40 pass.

Not tested

  • Full pnpm build with dist-based CLI (Node 22.22.0 does not meet the >=22.22.3 requirement)
  • The paste-token oversized path (shares the same readPipedStdin helper as the tested paste-api-key path)

🤖 Generated with co-mind

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: XS labels Jul 17, 2026
@Pick-cat
Pick-cat force-pushed the fix/models-auth-stdin-limit branch from 1c9bc7d to 12be34c Compare July 17, 2026 08:12
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 18, 2026, 1:00 AM ET / 05:00 UTC.

Summary
The branch replaces unbounded piped-stdin accumulation in model-auth paste commands with byte-counted Buffer collection capped at 1 MiB and adds a regression test for pre-mutation rejection.

PR surface: Source +7, Tests +15. Total +22 across 2 files.

Reproducibility: yes. from source and supplied real CLI proof: the pre-change reader accumulates all piped chunks before validation, while the proposed path rejects at 1 MiB plus one byte before auth mutation. The review did not independently execute the reproduction.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Refresh the final merge result and required checks against current main.

Risk before merge

  • [P1] The PR deliberately rejects previously accepted piped auth input above 1 MiB; while that is a reasonable resource boundary, maintainers should confirm that the limit and error behavior are acceptable for existing automation.
  • [P1] The branch is behind its base, so approval should use the actual three-way merge result and the final required checks rather than the supplied branch diff alone.

Maintainer options:

  1. Confirm the compatibility boundary before merge (recommended)
    Retain the 1 MiB stream-time cap after checking the final merge result and accepting that larger existing piped inputs will now fail explicitly.
  2. Choose a different documented limit
    If a 1 MiB cap is too restrictive for supported automation, select and document a different bounded maximum with matching exact-boundary coverage.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Require the current merge result to preserve successful normal piped auth input and retain the pre-mutation oversized-input regression coverage.

Next step before merge

  • [P2] No mechanical repair is indicated; the remaining action is maintainer acceptance of the intentional compatibility limit and review of the refreshed merge result.

Security
Cleared: The focused diff introduces no new dependency, execution, permission, or secret-exposure path and reduces unbounded stdin memory consumption.

Review details

Best possible solution:

Land the byte-limit hardening if the current merge result preserves normal piped-token behavior and maintainers accept the 1 MiB operator compatibility boundary.

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

Yes, from source and supplied real CLI proof: the pre-change reader accumulates all piped chunks before validation, while the proposed path rejects at 1 MiB plus one byte before auth mutation. The review did not independently execute the reproduction.

Is this the best way to solve the issue?

Yes, provisionally: enforcing a byte cap while consuming the stream addresses the memory-growth root cause more directly than downstream validation, and the related Matrix implementation supports this bounded-reader pattern.

AGENTS.md: found and applied where relevant.

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

Label changes

Label justifications:

  • P2: This is a bounded CLI hardening change that prevents avoidable memory growth in a model-auth workflow without evidence of an active broad outage.
  • merge-risk: 🚨 compatibility: The new hard limit intentionally changes existing piped auth commands from accepting arbitrarily large input to failing above 1 MiB.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides redacted terminal evidence from the production CLI showing both normal piped input and an oversized-input rejection, supplemented by a focused regression test.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides redacted terminal evidence from the production CLI showing both normal piped input and an oversized-input rejection, supplemented by a focused regression test.
Evidence reviewed

PR surface:

Source +7, Tests +15. Total +22 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 11 4 +7
Tests 1 15 0 +15
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 26 4 +22

What I checked:

  • Changed auth-input boundary: The supplied current-head diff changes readPipedStdin() from incremental UTF-8 string accumulation to byte-counted Buffer chunks, rejecting input once it exceeds 1 MiB before downstream authentication handling. (src/commands/models/auth.ts:133, 86988e613cd1)
  • Regression coverage: The added test supplies 1 MiB plus one byte, asserts the boundary error, and verifies neither interactive prompting nor auth/config mutation occurs. (src/commands/models/auth.test.ts:1476, 86988e613cd1)
  • Observed behavior proof: The PR body includes a real pnpm dev CLI transcript showing a normal piped key reaches auth processing and 1 MiB plus one byte fails with the new boundary error; it also reports the focused test file passing. (src/commands/models/auth.ts:133, 86988e613cd1)
  • Related precedent: The merged Matrix PR uses the same stream-boundary resource-limit pattern for a distinct recovery-key reader, supporting the chosen implementation shape without making the two defects the same root cause. (extensions/matrix/src/cli.ts, 54f1800d2a21)
  • Recent owner involvement: The timeline shows steipete assigned this PR and subsequently force-pushed the current head, so the remaining decision is active maintainer review rather than stale contributor follow-up. (src/commands/models/auth.ts:133, 86988e613cd1)

Likely related people:

  • steipete: The supplied timeline records assignment to steipete and owner-side updates to the current PR head, making them the clearest routing candidate for the remaining compatibility review. (role: recent area contributor and assigned reviewer; confidence: medium; commits: 636f4878d981, 86988e613cd1; files: src/commands/models/auth.ts, src/commands/models/auth.test.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (5 earlier review cycles)
  • reviewed 2026-07-17T08:19:18.602Z sha 12be34c454b75916fcf481916dec7998105820df :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-17T08:54:02.567Z sha 12be34c454b75916fcf481916dec7998105820df :: needs maintainer review before merge. :: none
  • reviewed 2026-07-17T09:24:00.734Z sha 974daa5fbfc7335c8411f5f9c4e5773735dbd809 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T01:39:58.337Z sha 626fbf699cb6e8f7d8042cb7d60e3eae4b6075eb :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T03:37:12.239Z sha 636f4878d981c662dda764caa9dc125acb42c63a :: needs maintainer review before merge. :: none

@Pick-cat

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jul 17, 2026
@Pick-cat
Pick-cat force-pushed the fix/models-auth-stdin-limit branch 2 times, most recently from 974daa5 to 626fbf6 Compare July 18, 2026 01:35
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Jul 18, 2026
@steipete steipete self-assigned this Jul 18, 2026
@steipete
steipete force-pushed the fix/models-auth-stdin-limit branch from 626fbf6 to 636f487 Compare July 18, 2026 03:33
readPipedStdin accumulated piped stdin without a size limit,
letting `models auth paste-token` and `paste-api-key` buffer
arbitrarily large input before any validation. Add a 1 MiB cap
matching the existing Matrix recovery-key and config-patch
stdin limits, and reject oversized input at the stream boundary.

Co-Authored-By: nebulacoder-v8.0 <[email protected]>
@steipete
steipete force-pushed the fix/models-auth-stdin-limit branch from 636f487 to 86988e6 Compare July 18, 2026 04:56
@steipete

Copy link
Copy Markdown
Contributor

Maintainer proof for head 86988e613cd16f89d9b6bece71190189ebea5f7b:

No remaining proof gaps. Ready for the guarded prepare/merge flow.

@steipete
steipete merged commit 6018174 into openclaw:main Jul 18, 2026
113 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 18, 2026
readPipedStdin accumulated piped stdin without a size limit,
letting `models auth paste-token` and `paste-api-key` buffer
arbitrarily large input before any validation. Add a 1 MiB cap
matching the existing Matrix recovery-key and config-patch
stdin limits, and reject oversized input at the stream boundary.
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
readPipedStdin accumulated piped stdin without a size limit,
letting `models auth paste-token` and `paste-api-key` buffer
arbitrarily large input before any validation. Add a 1 MiB cap
matching the existing Matrix recovery-key and config-patch
stdin limits, and reject oversized input at the stream boundary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants