Skip to content

fix(browser): authenticate ChatGPT interpreter asset fetches - #2712

Merged
Sinity merged 5 commits into
masterfrom
feature/fix/chatgpt-asset-auth
Jul 12, 2026
Merged

Sinity merged 5 commits into
masterfrom
feature/fix/chatgpt-asset-auth

Conversation

@Sinity

@Sinity Sinity commented Jul 11, 2026 •

Copy link
Copy Markdown
Owner

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/content URL that requires cookies.

Solution

  • Resolve /api/auth/session first, retaining the legacy bootstrap only as a tested fallback.
  • Send the bearer only to internally constructed same-origin metadata endpoints.
  • For returned HTTPS byte URLs, retain cookies only on the exact ChatGPT page origin; cross-origin signed URLs remain credential-free and never receive the bearer.
  • Walk the selected current-node lineage newest-first, then best-effort backfill remaining branches by message recency, so stale off-branch assets cannot suppress a live current deliverable.
  • Classify unauthorized, pod-expired, missing, signed-URL-expired, too-large, contract/transport failure, and acquired outcomes independently.
  • Enforce the 25 MiB per-file cap, compute SHA-256 with Web Crypto, and retain stable attachment identity plus digest/size receipts.

Acceptance Matrix

AC Status Evidence
1. Live interpreter capture acquires bytes and true SHA without credentials Browser/receiver slice satisfied. Live conversation 6a5350db-c1d8-83ed-9976-035227280d5e acquired 2/2 assets, each 848,460 bytes at SHA 40fa31aeccd41a8c61e3bbe5d721d1f5395cc4f14c7411f94663b777a23eef77; no failures, skips, bearer, or cross-origin credentials. Source/index materialization is separately blocked by typed raw-authority debt tracked in polylogue-57rp, so this PR does not claim the final content-addressed index row.
2. Unauthorized, pod-expired, missing, signed-expired, acquired remain distinct Satisfied. Production bridge response matrix covers auth-session 401, provider ace_pod_expired, interpreter 404, byte 403, same-origin estuary acquisition, and external signed acquisition.
3. Regression fails under previous behavior Satisfied. Removing metadata Authorization changes acquired to unauthorized/401; forcing credentials: omit on same-origin estuary reproduces live 403 File stream access denied; unordered stale-first discovery skips the current-node ZIP.
4. Re-capture a recovered GPT-Pro package with matching SHA Satisfied with explicit recovery boundary. The original pod now returns a fresh metadata URL whose byte request is genuinely expired. The independently recovered 848,460-byte Demo Packet ZIP was re-emitted byte-for-byte through a fresh ChatGPT interpreter and captured through this extension; both the sandbox deliverable and file attachment equal the independent SHA 40fa31ae...f77. No claim is made that the original pod survived.
5. Focused extension/parser tests and browser smoke pass Satisfied. See verification.

The browser-auth child remains open until polylogue-57rp converges the preserved acquired envelope into the source/index/blob tiers; the parent polylogue-5k5l also retains file-service and end-to-end acquisition scope.

Verification

  • npm test -> 7 files passed; 121 tests passed
  • npm run lint -> eslint src/ tests/ exited 0
  • npm run validate -> manifest v0.1.0 OK
  • devtools 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 deselected
  • pre-push devtools verify --quick at aedb2760b -> 13/13 steps exited 0, run 20260712T083505Z-quick-1122043-a123e4ab
  • Live extension capture -> native_full, 6 turns, 2 acquired / 0 failed, exact 848,460-byte SHA match, receiver request polylogue-ext-mrhjgnkn-hzbd33l3
  • Live negative proof -> same-origin estuary credentials: omit returned 403 File stream access denied; cookie-only and bearer-only requests both returned 200

Review 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

  • Bug Fixes
    • Improved ChatGPT conversation and attachment capture reliability.
    • Prioritizes the currently selected conversation branch when locating attachments.
    • Validates downloaded attachments for integrity and size before saving them.
    • Provides clearer acquisition results for successful, skipped, and failed attachments.
    • Improved handling of authentication issues, expired links, missing files, and download failures.
    • Enhanced protection for credentials during conversation and attachment retrieval.

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]>
@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: fa100709-1a59-4042-abc9-495af04e5c6b

📥 Commits

Reviewing files that changed from the base of the PR and between 885b46d and aedb276.

📒 Files selected for processing (3)
  • browser-extension/src/content/chatgpt.js
  • browser-extension/src/content/chatgpt_bridge.js
  • browser-extension/tests/content/chatgpt_bridge.test.js

📝 Walkthrough

Walkthrough

ChatGPT 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.

Changes

ChatGPT asset acquisition

Layer / File(s) Summary
Token resolution and conversation interception
browser-extension/src/content/chatgpt_bridge.js, browser-extension/tests/content/chatgpt_bridge.test.js
Conversation requests resolve access tokens from session and bootstrap sources, apply bearer authorization, and use stricter route matching.
Validated asset outcome pipeline
browser-extension/src/content/chatgpt_bridge.js, browser-extension/src/content/chatgpt.js, browser-extension/tests/content/chatgpt_bridge.test.js
Asset requests validate metadata, URLs, credentials, size limits, SHA-256 values, and structured success or failure outcomes.
Lineage ordering and capture reporting
browser-extension/src/content/chatgpt.js, browser-extension/tests/content/chatgpt_bridge.test.js
Capture prioritizes the selected conversation lineage and records acquired assets, status counts, provider metadata, and detailed failures.

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
Loading

Possibly related PRs

  • Sinity/polylogue#2376: Adds ChatGPT DOM attachment extraction that supplies turn.attachments for the acquisition path updated here.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/fix/chatgpt-asset-auth

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.

Sinity and others added 2 commits July 11, 2026 19:09
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]>

Sinity commented Jul 11, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 11, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sinity and others added 2 commits July 12, 2026 10:26
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]>
@Sinity
Sinity marked this pull request as ready for review July 12, 2026 08:39
@Sinity
Sinity merged commit 8c23ba2 into master Jul 12, 2026
4 of 24 checks passed
@Sinity
Sinity deleted the feature/fix/chatgpt-asset-auth branch July 12, 2026 08:39

@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: 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 });

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Sinity added a commit that referenced this pull request Jul 12, 2026
## 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]>
Sinity added a commit that referenced this pull request Jul 18, 2026
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]>
Sinity added a commit that referenced this pull request Jul 18, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant