Repository navigation
fix(browser): authenticate ChatGPT interpreter asset fetches - #2712
Conversation
Problem: current ChatGPT pages expose the bearer through the authenticated session endpoint, while the asset bridge only inspected a legacy bootstrap node. Interpreter metadata requests therefore fell back to cookies and collapsed authorization, pod expiry, missing files, and signed-URL expiry into generic HTTP errors. Resolve the bearer inside the trusted MAIN-world bridge, send it only to internally constructed same-origin metadata endpoints, and fetch signed storage URLs without credentials. Return credential-free typed outcomes, enforce the existing size budget, compute SHA-256 in the page, and retain stable attachment receipts across repeat capture. The production-script harness exercises the page bridge and capture envelope, including an unauthenticated source mutation that reproduces the old 401 behavior and assertions that neither bearer nor signed URL crosses the page boundary. Ref polylogue-5k5l.1 Co-Authored-By: Claude <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughChatGPT conversation fetching now resolves cached access tokens, while asset acquisition uses structured outcomes, signed-byte validation, SHA-256 integrity checks, size limits, detailed failures, and lineage-first descriptor traversal. Tests cover bridge responses, credential handling, capture metadata, and branch ordering. ChangesChatGPT asset acquisition
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant capturePage
participant chatgpt_js
participant chatgpt_bridge
participant ChatGPT_API
capturePage->>chatgpt_js: request asset acquisition
chatgpt_js->>chatgpt_bridge: post asset request
chatgpt_bridge->>ChatGPT_API: fetch metadata with bearer token
ChatGPT_API-->>chatgpt_bridge: return signed download URL
chatgpt_bridge->>ChatGPT_API: fetch signed bytes
ChatGPT_API-->>chatgpt_bridge: return bytes
chatgpt_bridge-->>chatgpt_js: return validated outcome
chatgpt_js-->>capturePage: record acquisition status
Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
GitHub's Node 20 runner rejects an ArrayBuffer created in a nested jsdom VM when it is passed directly to host Web Crypto. Adapt the fixture bytes into a host Buffer before invoking the real digest implementation so the test keeps its production crypto dependency without relying on cross-realm coercion. Ref polylogue-5k5l.1 Co-Authored-By: Claude <[email protected]>
Resolve `/api/auth/session` before consulting the legacy bootstrap node so a stale bootstrap bearer cannot override the current authenticated page token. Retain the bootstrap as a tested fallback when the session endpoint has no token, and pin the interpreter message/path query contract in the production bridge harness. Ref polylogue-5k5l.1 Co-Authored-By: Claude <[email protected]>
|
@coderabbitai review |
✅ Action performedReview finished.
|
ChatGPT mapping insertion order can place expired assets from old branches before the current node. The kind-wide failure breaker then skips a live current-branch deliverable without attempting it. Traverse the selected lineage newest-first and process remaining branches by message recency. Cover the production bridge and content scripts with an out-of-order fixture where three stale assets precede a live current-node ZIP. Ref polylogue-5k5l.1 Co-Authored-By: Claude <[email protected]>
Current ChatGPT interpreter metadata can return a same-origin estuary content URL rather than a self-authenticating object-store URL. Omitting credentials from that request produces a false signed_url_expired outcome even for a file created seconds earlier. Keep cookies only for HTTPS download URLs on the exact ChatGPT page origin, while cross-origin signed URLs remain credential-free and no bearer is forwarded. Cover both credential policies through the production bridge. Ref polylogue-5k5l.1 Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aedb2760b1
ℹ️ 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".
| if (data.outcome && typeof data.outcome === "object") { | ||
| pending.resolve(data.outcome); | ||
| } else if (data.asset) { | ||
| pending.resolve({ status: "acquired", phase: "legacy_bridge", asset: data.asset }); |
There was a problem hiding this comment.
Preserve legacy bridge assets after extension updates
When an already-open ChatGPT tab still has the pre-change MAIN-world bridge installed, the bridge is not replaced because of the existing install guard, so asset responses arrive through this legacy data.asset path and contain only base64/size/mime/name. The new acquisition code later requires a 64-character asset.sha256 before accepting status: "acquired", so those still-retrievable assets are recorded as invalid_response and dropped until the user reloads the tab. Compute the digest from the legacy base64 here or force a versioned bridge reinstall so extension updates do not silently lose attachments.
Useful? React with 👍 / 👎.
## Summary Harden the browser-capture path for concurrent extension instances and make replaced receiver snapshots materialize through typed membership authority. ## Problem Concurrent extensions could submit the same provider snapshot without durable attribution or semantic duplicate suppression. Backfill jobs added observer-only job, queue, and extension identifiers to provider metadata, making otherwise-identical posts evade that suppression. Separately, a replaced browser-capture JSON snapshot is not a byte-prefix successor, so generic raw-revision authority quarantined it instead of materializing newer acquired attachment bytes. ## Solution - Stamp direct and retry capture envelopes with one persistent MV3 service-worker instance id, coalescing concurrent cold-start reads and mints. - Deduplicate observer-equivalent snapshots while retaining request-byte acknowledgement hashes, excluding backfill observer attribution from the semantic fingerprint only. - Serialize spool replacement with an advisory OS lock and atomic writes. - Route single-session artifacts from the `browser-capture` watch source through existing membership revision authority from their first observation. Strict message/event/attachment growth governs content changes; metadata-equivalent snapshots retain the existing timestamp-aware membership rule; every raw blob remains retained. ## Acceptance matrix | Bead | Status | Evidence | | --- | --- | --- | | polylogue-3v1.1 | Satisfied | Two concurrent cold-start extension capture messages share one persisted instance id. Receiver writes converge to one artifact and the production live-batch route materializes exactly one archived session; distinct backfill jobs also yield one deduplicated receipt. | | polylogue-57rp | Partial: typed-authority regression satisfied; exact/live criteria deferred | The real-route fixture retains raw snapshots, advances the accepted membership head to the acquired replacement, stores its inline attachment as an acquired content-addressed blob, and retains the head for both reverse and divergent stale replacements. It uses synthetic attachment bytes, so the bead's exact 848,460-byte/SHA proof, daemon replay-debt accounting, and live re-capture query remain deferred under the archive-safety boundary. | | polylogue-5k5l.1 | Already merged | PR #2712 (`8c23ba218`) supplied authenticated interpreter/sandbox acquisition and typed outcomes. | | polylogue-5k5l | Partial: existing acquisition implementation retained; parent ACs not newly closed | Existing adapter tests cover sandbox and file-service acquisition; parser/archive tests prove acquired envelope assets reach attachment blobs. The controlled file-service live acquisition and idempotent live re-capture evidence remain with the parent bead. | ## Verification - `nix develop --command devtools test tests/unit/daemon -k 'receiver or capture'` — 38 passed. - `POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest nix develop --command devtools test tests/unit/daemon/test_browser_capture_instance_attribution.py` — 1 passed. - `POLYLOGUE_PYTEST_BASETEMP_ROOT=/realm/tmp/polylogue-pytest nix develop --command devtools test tests/unit/sources/test_live_batch_support.py -k browser_capture_replacement_advances_membership_head_and_acquires_attachment` — 1 passed. - `npm test -- --run tests/background.test.js` — 23 passed. - `npm test -- --run tests/content/chatgpt.test.js tests/content/chatgpt_bridge.test.js` — 34 passed. - `nix develop --command devtools test tests/unit/sources/test_browser_capture.py -k 'embedded_attachments_are_acquired_in_archive or native_payload_delegation_keeps_envelope_acquired_assets'` — 2 passed. - Pre-push `devtools verify --quick` — all 15 gates passed (`20260712T225848Z-quick-1752486-5ad29130`). ## Adversarial review notes - Iteration 1: fixed a real cold-start instance-id race in `436e9c012`; added a divergent stale-snapshot route proof and corrected the membership wording. A further direct review finding that the spool test did not prove archive materialization landed in `6deab55d7`. The exact/live 57rp and parent 5k5l criteria remain explicitly deferred above. Anti-vacuity: the 57rp fixture calls `LiveBatchProcessor.ingest_files` against the production archive writer, then reads source/index database state. Removing the browser-capture membership route restores the old quarantined byte-revision behavior; removing ambiguity handling lets a divergent stale snapshot overwrite the accepted head. The concurrent-writer test invokes `write_capture_envelope` with a synchronization barrier and distinct backfill job/queue/instance metadata, then runs the real live-batch processor; removing semantic deduplication, its attribution normalization, or the archival route breaks its receipt/artifact/session assertions. The background test drives two real runtime messages concurrently; removing the single-flight promise permits distinct cold-start identifiers and fails its one-id assertion. Ref polylogue-3v1.1 Ref polylogue-57rp Ref polylogue-5k5l --------- Co-authored-by: Claude <[email protected]>
chatgpt-dom-v1 attachment byte acquisition (this branch, commit above) closes the only remaining gap this bead scoped -- the general chatgpt-native-v1 sandbox/file-service asset acquisition already shipped in earlier PRs (#2669/#2672/#2712/#2926). Hand-merged the one touched record from a fresh `bd export` rather than copying the whole file: bd resolves its export target independent of invocation cwd, so it also carries unrelated concurrent-session bead activity that doesn't belong on this branch. Co-Authored-By: Claude <[email protected]>
…e page bridge (#3075) ## Summary Closes the last remaining gap in `polylogue-83u.3`: the `chatgpt-dom-v1` DOM-scrape capture fallback now fetches attachment bytes through the same authenticated page-bridge mechanism the native adapter already uses, instead of recording only the chip name with `byte_count=0`. ## Problem General ChatGPT attachment fetching already ships: `chatgpt_bridge.js` (`fetchAssetBytes`) and `chatgpt.js` (`acquireAssets`/`collectAssetDescriptors`) live-fetch sandbox/file-service bytes for the normal `chatgpt-native-v1` capture path (landed PR #2669, hardened #2672/#2712/#2926). The only remaining gap is the older `chatgpt-dom-v1` fallback — used only when the authenticated backend-api conversation read fails — which had **no acquisition path at all**: `collectAttachments` recorded just the chip's name. ## Architecture constraint `chatgpt-dom-v1` has no backend-api `mapping` to resolve a file/sandbox id from (unlike `chatgpt-native-v1`); the DOM chip's own `href`/`src` is the only evidence available, and it is sometimes already a concrete `https://` URL the page itself rendered (e.g. an inline `<img src>`). ## Solution Added a `"url"` request kind to `chatgpt_bridge.js`'s `fetchAssetBytes` that skips the metadata round trip entirely and reuses the **exact same** fetch+budget+hash mechanism already proven for the `sandbox`/`file` kinds (refactored the shared tail into `fetchBytesFromResolvedUrl`), including the existing cross-origin credential-drop rule (never forward page cookies/bearer to a provider-issued or DOM-rendered cross-origin URL). `chatgpt.js`'s `collectTurns` now awaits a new `acquireDomAttachmentBytes` step — budget-bounded identically to the native path (same per-file/total-byte/time/consecutive-failure caps) — that requests those bytes and sets `inline_base64` on the DOM attachment. That is the exact field `polylogue/sources/parsers/browser_capture.py` already decodes into `ParsedAttachment.inline_bytes` for every adapter, so **no receiver/parser change was needed** — `inline_base64` is not a new payload field, just one `chatgpt-dom-v1` was never wired to populate. Chips with no resolvable URL stay honestly `byte_count=0`. ## Consistency with polylogue-ptx `polylogue-ptx` (PR #2928, merged) replaced the extension's browser-action/campaign machinery with a provider-neutral `BrowserAction` conduit. This change only extends the existing content-script/bridge byte-fetch mechanism at its one documented gap; it does not touch, duplicate, or compete with the `BrowserAction` conduit's submit/receipt machinery. ## Verification - `cd browser-extension && npx vitest run` → **329 passed** (1 pre-existing unrelated failure in `build.test.js`'s packaged-service-worker backfill fixture — reproduces identically without this change) - `npx eslint src/ tests/` → clean - `node scripts/validate-manifest.mjs` → ok - New coverage: 5 focused `fetchAssetBytes` `"url"`-kind tests (direct fetch, cross-origin credential drop, same-origin credential keep, non-https rejection, byte-cap enforcement) plus 2 full-capture DOM-fallback smoke tests (`chatgpt_bridge.test.js`) executing the real production sources through a simulated authenticated page, proving a `chatgpt-dom-v1` capture now yields `inline_base64` whose SHA-256 exactly matches the delivered bytes, and that a chip with no fetchable URL stays honestly `byte_count=0`. Ref polylogue-83u.3 Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
Summary
Authenticate ChatGPT interpreter-asset acquisition through the current page session contract, preserve distinct terminal outcomes, prioritize the selected branch's assets, and attach deterministic SHA-256 receipts without allowing bearer credentials or cross-origin signed URLs to cross the page bridge.
Problem
Live recovery showed that interpreter files classified as generic 403 failures were still retrievable through ChatGPT's authenticated contract. The bridge read only a legacy bootstrap token, iterated unordered branch mappings until stale assets tripped a kind-wide breaker, and fetched every returned download URL with
credentials: omit. Current ChatGPT pages instead expose the bearer through/api/auth/session; current-node assets can appear late in mapping insertion order; and current interpreter metadata may return a same-origin/backend-api/estuary/contentURL that requires cookies.Solution
/api/auth/sessionfirst, retaining the legacy bootstrap only as a tested fallback.Acceptance Matrix
6a5350db-c1d8-83ed-9976-035227280d5eacquired 2/2 assets, each 848,460 bytes at SHA40fa31aeccd41a8c61e3bbe5d721d1f5395cc4f14c7411f94663b777a23eef77; no failures, skips, bearer, or cross-origin credentials. Source/index materialization is separately blocked by typed raw-authority debt tracked inpolylogue-57rp, so this PR does not claim the final content-addressed index row.ace_pod_expired, interpreter 404, byte 403, same-origin estuary acquisition, and external signed acquisition.credentials: omiton same-origin estuary reproduces live403 File stream access denied; unordered stale-first discovery skips the current-node ZIP.40fa31ae...f77. No claim is made that the original pod survived.The browser-auth child remains open until
polylogue-57rpconverges the preserved acquired envelope into the source/index/blob tiers; the parentpolylogue-5k5lalso retains file-service and end-to-end acquisition scope.Verification
npm test->7 files passed; 121 tests passednpm run lint->eslint src/ tests/exited 0npm run validate-> manifest v0.1.0 OKdevtools test tests/unit/sources/test_browser_capture.py tests/unit/storage/test_attachment_acquisition.py -k 'native_payload_delegation_keeps_envelope_acquired_assets or inline_attachment_bytes_are_stored_with_true_hash'->2 passed, 34 deselecteddevtools verify --quickataedb2760b-> 13/13 steps exited 0, run20260712T083505Z-quick-1122043-a123e4abpolylogue-ext-mrhjgnkn-hzbd33l3credentials: omitreturned 403File stream access denied; cookie-only and bearer-only requests both returned 200Review Notes
Self-review corrected explicit provider-diagnostic precedence, current-session-over-stale-bootstrap precedence, selected-lineage ordering, and same-origin estuary authentication. Cross-origin signed URLs still use
credentials: omit; serialized capture evidence contains neither bearer nor signed URL. CodeRabbit initially rate-limited and posted no substantive finding. GitHub checks were green before the final live-proof commits; subsequent workflow jobs are account-billing infrastructure failures with zero executed steps, while local gates above exercised the changed surface.Ref polylogue-5k5l.1
Summary by CodeRabbit