Skip to content

fix(oauth): bound Meta Muse device response bodies - #540

Open
luvs01 wants to merge 1 commit into
devfrom
codex/fix-unbounded-response-parsing-in-meta-device-login
Open

luvs01 wants to merge 1 commit into
devfrom
codex/fix-unbounded-response-parsing-in-meta-device-login

Conversation

@luvs01

@luvs01 luvs01 commented Sep 14, 2026

Copy link
Copy Markdown
Owner

Motivation

  • The Meta Muse device-login path became runtime-reachable and parsed three upstream JSON responses with response.json() unbounded, exposing the process to memory exhaustion from a large or malicious response.

Description

  • Add a readMuseJson helper that enforces the shared 64 KiB ceiling using readBoundedResponseBytes and rejects oversized declared or streamed bodies before JSON parsing.
  • Replace raw response.json() calls in requestMuseDeviceAuthorization, pollMuseDeviceToken, and mintMuseApiKey with the bounded reader and preserve the request deadline via the combined abort signal.
  • Add focused tests in tests/providers/meta-muse-device.test.ts that cover oversized streamed authorization/token responses and an oversized declared mint response, and update structure/runtime.md to document the bounded-body invariant for the OAuth transport.

Testing

  • ✅ Focused unit suite: npx --yes bun@1.4.2 test tests/providers/meta-muse-device.test.ts — 39 passed, 0 failed.
  • ✅ Static checks: npx --yes bun@1.4.2 run typecheck, npx --yes bun@1.4.2 run structure:check, and npx --yes bun@1.4.2 run privacy:scan all passed.
  • ⚠️ Full repository test run: npx --yes bun@1.4.2 run test completed but reported unrelated existing/concurrency-sensitive failures in tests/server/api-key-attribution.test.ts, tests/lab/lab-automation-final-coderabbit-regressions.test.ts, and tests/codex-integration/bearer-admission-routed-provider.test.ts; the focused Meta Muse tests remained green.
  • ⚠️ Environment note: running bun test with the preinstalled Bun 1.2.14 failed due to node:zlib symbol differences, so tests were exercised with the repository-aligned Bun 1.4.2 runtime.

Codex Task

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-14T06:36:38.757782Z ca5d15c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Advanced

Run ID: a946034c-baae-4d4f-ade3-30ad05019086


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the bug Something isn't working label Sep 14, 2026
@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ca5d15ccf6

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread structure/runtime.md
| `src/providers/registry.ts` | Canonical provider presets for CLI, dashboard, OAuth, key providers, and metadata. |
| `src/providers/derive.ts` | Enrichment from provider presets into user config. |
| `src/oauth/` | OAuth providers, token storage, refresh, and auth-token resolution. The login callback listener binds a per-provider FIXED loopback port, so consecutive logins reuse the same number; every response it sends ends its connection (`Connection: close`, including non-callback paths such as a stray `/favicon.ico` 404). Stopping the listener does not close an established socket, so without that a pooled client would deliver the next login's callback to the retired flow, which rejects the unknown state as a CSRF mismatch while the live flow waits. Kiro add-account identity prefers same-session `whoami` over a leftover SQLite state profile, and never persists the Builder ID service profile ARN as `accountId`. |
| `src/oauth/` | OAuth providers, token storage, refresh, and auth-token resolution. Meta Muse device authorization, polling, and key-mint JSON responses share the 64 KiB bounded-body ceiling and the request's deadline; oversized declared or streamed bodies are rejected before JSON parsing. The login callback listener binds a per-provider FIXED loopback port, so consecutive logins reuse the same number; every response it sends ends its connection (`Connection: close`, including non-callback paths such as a stray `/favicon.ico` 404). Stopping the listener does not close an established socket, so without that a pooled client would deliver the next login's callback to the retired flow, which rejects the unknown state as a CSRF mismatch while the live flow waits. Kiro add-account identity prefers same-session `whoami` over a leftover SQLite state profile, and never persists the Builder ID service profile ARN as `accountId`. |

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Update every mapped OAuth structure document

This change updates only runtime.md, but structure/INDEX.md maps src/oauth/ to three owning documents: runtime.md, transports/inventory.md, and providers/xai-grok.md. Because the new OAuth response-body contract leaves the latter two owners untouched, the repository's mandatory source-to-doc synchronization is incomplete; update both mapped documents in this commit, or narrow their manifest ownership if they no longer describe this area.

AGENTS.md reference: structure/AGENTS.md:L44-L50

Useful? React with 👍 / 👎.

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

Labels

aardvark bug Something isn't working codex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant