Skip to content

fix(security): bound scenario retention and loopback admission - #2961

Closed
cybrking wants to merge 1 commit into
morluto:mainfrom
cybrking:fix/security-resource-boundaries
Closed

cybrking wants to merge 1 commit into
morluto:mainfrom
cybrking:fix/security-resource-boundaries

Conversation

@cybrking

Copy link
Copy Markdown

Summary

Bound browser scenario retention and content scheduling, and reject unauthenticated loopback clients without consuming the Ghidra session. This is a draft with partial browser remediation: Playwright body acquisition still needs a separately enforced producer memory boundary. No issue is linked because this follows a requested repository security review.

Problem and expected behavior

Scenario events and selected network work previously accumulated without collection budgets. The loopback bridge also allowed its first unauthenticated connection to consume the sole session. Resource omissions must remain visible in evidence, and rejected handshake clients must leave the bridge available for its legitimate caller.

Change and scope

  • Reserve event allocation before schema cloning: 16 MiB aggregate, 4 MiB per event, 10,000 events, and 2,048 live listener owners. Check raw strings before normalization and reserve secret replacement expansion and per-match allocation. Omit whole events with dropped counts and limitations.
  • Admit at most 1,024 network transactions and 16 concurrent bounded content jobs before producer invocation; deduplicate request content scheduling. Retain source-event integrity when metadata is omitted. Report oversized headers, body copies, and excess jobs as unavailable.
  • Bound the loopback first frame to 64 KiB and an absolute one-second deadline. Close rejected clients and accept another connection. Preserve pipelined and larger authenticated requests. Retry initial loopback transport failures at most twice within the original startup deadline, detaching old socket state first.
  • Document limits and add production-boundary regressions, including an isolated JDK TCP harness.

Contract and boundary impact

  • Semantic owner: scenario event/network producers and loopback bridge admission.
  • Contribution scope: ordinary security fixes within existing boundaries; advance scope decision not applicable.
  • CLI/MCP schemas and catalog: unchanged. Existing dropped/unavailable/limitations fields now describe resource omissions. Oversized or high-volume captures retain less evidence.
  • Compatibility: UNIX admission remains unchanged. Loopback authentication and identity validation remain in force; only initial transport failures are retried.
  • Provenance/cleanup: request object identities and retained source-event links remain authoritative; existing process supervision, parent startup deadline, and cleanup ownership remain in place.
  • Target authority: no new target selection, instrumentation, mutation, or network capability. Existing browser and bridge workflows still perform their existing process/network interactions.
  • Generated metadata, package, installation: no authored package metadata or installation changes; generated artifacts are uncommitted.

Evidence and regression coverage

Executed regression coverage includes ordinary event/content controls, individual and aggregate retention budgets, count exhaustion, listener capacity reuse, producer non-invocation after admission rejection, redaction expansion, dropped metadata, loopback reconnect/retry exhaustion, and normal provider cleanup.

The JDK harness compiles the production preauthentication read and accept methods with parsing/dispatch fixture seams. It executes rejection, EOF, frame ceiling, idle and slow-trickle deadlines, acceptance of a later valid client, pipelined requests, and authenticated requests larger than the handshake ceiling. It does not compile or run the complete Ghidra engine bridge.

Base vulnerability analysis was source-derived. The new budget/retry assertions contradict the former unbounded/terminal behavior; no exploit was run against a deployed application.

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Incomplete and unavailable outcomes remain visible.

Validation performed

  • Focused browser event/network/session/provider suites — 50 distinct tests passed across focused runs.
  • npm run test:focused -- tests/boundary/providers/ghidra/ghidraClient.test.ts tests/boundary/providers/ghidra/ghidraTransport.test.ts — 41 tests passed.
  • python3 tests/fixtures/ghidraHandshakeProbe.py /path/to/java — passed with a temporary Temurin JDK 21 on macOS.
  • npm run check — passed typecheck, compiled lint, formatting, knip, metadata, module boundaries, and architecture guards.
  • npm run docs:check — passed, including five README consistency tests.
  • npm run verify:test-discovery — all 1,112 test files discovered exactly once.
  • git diff --check — passed.

Compatibility, safety, and release

Unresolved browser acquisition boundary: Response.body() still materializes the complete buffer before the 64 KiB retention check. Incoming Playwright payloads and headers are likewise acquired before adapter admission. A timeout settles a capture job but does not cancel its underlying producer operation. These limits reduce retained copies and scheduled work; they do not establish a complete host-memory bound or close the full browser finding. Preserving body semantics requires supervised producer isolation with enforced memory limits, or a separately designed bounded CDP collector with correct transaction identities and explicit provenance.

The loopback change bounds disruption by an individual rejected client. Repeated queued connections can still delay startup. A real Windows Ghidra lane and a real-browser resource-isolation lane were unavailable on this macOS host; those remain required before treating the relevant platform/containment claims as established.

Before merge

  • Concrete problem and Conventional Commit title.
  • Regression checks, owning documentation, and final diff reviewed.
  • Resolve the remaining producer acquisition boundary or explicitly accept this as a limited mitigation.
  • Complete required real Windows Ghidra/provider validation.

@morluto
morluto marked this pull request as ready for review October 13, 2026 18:24
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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-10-13T18:36:16.527671Z 8cbb79e Draft marked ready
ℹ️ 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.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 3/5 Tier: plus

[Critical impact] Adds authentication and resource limits to Ghidra bridge and browser event capture.

Fix the listener-held URL accounting before merging; it lets page-created data bypass the intended retention budget.

Findings

  1. P2 Unused headers hide network records ▶
Fix with agent prompt
### Issue 1
src/browser/network/PlaywrightScenarioNetwork.ts:272-275
`admitMetadata()` budgets header values even though metadata events retain only `header_names`. With `header_values: false`, those values never appear in the output. A declared one-character secret makes a valid 6 KiB header value exceed this check, even if the value contains no secret.

The collector then omits otherwise small request, response, and completion records. Selected small bodies can also become unreachable. Budget only the fields metadata retains, and leave header-value limits to `captureNetworkHeaders()`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds browser event and network budgets, bounded loopback admission, and limited startup retries.

  • Browser event captures now show when collection limits leave evidence out.
  • Network captures limit queued content work and mark omitted data unavailable.
  • Rejected loopback clients leave the Ghidra bridge open for its caller.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Page["Page event"] --> Raw["Check raw text cost"]
  Raw --> Clean["Clean event fields"]
  Clean --> Budget{"Event fits remaining budget?"}
  Budget -->|Yes| Save["Save and charge event"]
  Budget -->|No| Drop["Count dropped event"]
  Clean --> Listeners["Worker or WebSocket listeners keep URL"]
  Listeners --> Close["Release on close"]

  Client["Loopback client"] --> Frame["Read first frame: 64 KiB, 1 second"]
  Frame --> Auth{"Token matches?"}
  Auth -->|No| Reject["Close and accept another client"]
  Auth -->|Yes| Serve["Serve authenticated requests"]
Loading

Reviews (1) · Last reviewed commit: "fix(security): bound scenario retention ..." · Reviewed by Greptile

Comment on lines +272 to +275
for (const name in headers) {
if (!Object.hasOwn(headers, name)) continue;
yield name;
yield headers[name]!;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Unused headers hide network records

admitMetadata() budgets header values even though metadata events retain only header_names. With header_values: false, those values never appear in the output. A declared one-character secret makes a valid 6 KiB header value exceed this check, even if the value contains no secret.

The collector then omits otherwise small request, response, and completion records. Selected small bodies can also become unreachable. Budget only the fields metadata retains, and leave header-value limits to captureNetworkHeaders().

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/browser/network/PlaywrightScenarioNetwork.ts
Line: 272-275

Comment:
**Unused headers hide network records**

`admitMetadata()` budgets header values even though metadata events retain only `header_names`. With `header_values: false`, those values never appear in the output. A declared one-character secret makes a valid 6 KiB header value exceed this check, even if the value contains no secret.

The collector then omits otherwise small request, response, and completion records. Selected small bodies can also become unreachable. Budget only the fields metadata retains, and leave header-value limits to `captureNetworkHeaders()`.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff

These findings could not be posted inline.

  • P1 Security Dropped URLs stay in memory src/browser/PlaywrightScenarioEvents.ts:416 ▶

    worker() and webSocket() keep cleaned URLs in listener callbacks even when push() drops their opening event. Near the aggregate limit, admitText() still accepts each URL because it checks whether the budget is already full, not whether the URL fits. The callbacks then retain that URL until closure without charging its cost.

    An untrusted page can repeat this with long-lived workers and retain far more than the 16 MiB budget allows. Reserve the listener-held data before creating it, or skip the listeners when that reservation fails. This is separate from the acknowledged Playwright acquisition limit.

    How this was verified: Page-created workers reach saved onClose callbacks that retain cleaned URL copies even when push() refuses the event.

@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: 8cbb79eedb

ℹ️ 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".

sum + this.secrets.redactionAllocationCost(value.length),
0,
) > MAX_EVENT_COST ||
this.retainedCost >= MAX_CAPTURE_COST

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 Reserve text cost against the remaining capture budget

When retained storage is still below 16 MiB but the candidate's estimated redaction cost exceeds the remaining space, this condition admits it because it only tests whether the budget is already completely full. Redaction then performs its scans/expansion before push() rejects the event, and because retainedCost is unchanged, every later large event can repeat that work; a hostile page emitting selected text events in a scenario with declared secrets can therefore keep driving adapter CPU/allocation after retention has effectively filled. Compare and reserve the candidate estimate against the remaining budget before redaction.

AGENTS.md reference: AGENTS.md:L75-L75

Useful? React with 👍 / 👎.

const rawText = message.text();
if (!this.admitText(rawText)) return;
const location = message.location();
if (!this.admitText(location.url, message.type())) return;

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 Admit each console event under one combined budget

When a console message and its source URL are each below MAX_EVENT_COST but exceed it together, the two independent admissions both succeed, after which both fields are redacted/sanitized and only push() notices that the event is oversized. Repeated large console events can thus bypass the advertised pre-redaction per-event bound without increasing retained state; pass the text, URL, and type through one combined admission/reservation.

AGENTS.md reference: AGENTS.md:L75-L75

Useful? React with 👍 / 👎.

request(request: ScenarioNetworkRequest): void {
if (!this.accepting) return;
const transaction = this.transaction(request);
if (transaction === undefined || !this.admitMetadata(request)) return;

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 Keep omitted transactions out of redirect links

When a request's metadata exceeds the new 1 MiB admission limit, transaction() has already inserted it into the map before this return. A later redirect from that request therefore receives its ID via transactions.get(predecessor) even though no event with that transaction ID was retained, contradicting docs/browser-scenario-contract.md:248-253, which says redirects link only to observed transactions and otherwise use null; track whether the predecessor event was retained (or defer insertion) before exposing its ID.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@morluto morluto added area: domain Domain logic, errors, and pure functions bug Something isn't working security Target-execution safety, isolation, authority, and contamination handling labels Oct 14, 2026
morluto added a commit that referenced this pull request Oct 14, 2026
Share tagged readiness observations, retain partial provider facts, authenticate bridge identity, bound diagnostics, and preserve cancellation and lost-session reasons. Fail closed for unparsed MIPS ABI attributes and macOS saved Hopper databases without a script-capable bridge route.

Reviewed fixes: #2010, #2108, #2513, #2695, #2731, #2771, #2828, #2867, #2868, #2870, #2880, #2919, #2945, #2961, #2981, #2998, #3000, #3002.

Validation: 285 focused source/boundary tests passed. Real Ghidra, IDA, Linux Hopper, and Windows provider runs were not repeated.

BREAKING CHANGE: MIPS targets with unresolved GNU ABI attributes and saved Hopper databases on macOS are refused rather than advertised as supported.
morluto added a commit that referenced this pull request Oct 14, 2026
Own service-worker CDP registrations and retry failed teardown. Admit redaction and network metadata against remaining capture capacity, retain explicit omission reasons, and preserve source URL, redirect ancestry, caller-selected content, and historical capture values. Forward CLI cancellation through provider cleanup.

Reviewed fixes: #2263, #2637, #2767, #2845, #2859, #2863, #2872, #2874, #2876, #2879, #2955, #2957, #2961, #3033.

Validation: 25 current event/network source tests passed; earlier focused browser lanes passed 201 source tests and 176 boundary tests with two skips, plus 35 Python tests. Real browser/Windows lanes were not rerun. Playwright allocation before admission remains unbounded by these retention limits.
@CassieFox23

CassieFox23 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Edit: Main caught up with most of this PR. I retested what is left here.

Heads up: main already has this change in f690571. The code is in src/browser/network/PlaywrightScenarioNetwork.ts, and bounds admitted transactions before invoking content producers covers it. It is listed on tracker #3582. If this PR still adds something main doesn't have, please say so here and I'll take it off the list. Thanks for the fix!

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: I retested what is left of this PR after main caught up. The code is already on main and passes there. What main lacks is a short note in docs/testing.md on how to run the Ghidra handshake probe.

Main is 95c8f57, the PR head is 8cbb79e. I compared the PR's added lines with main by hand. These are on main under the same names:

  • The Ghidra bridge
  • The client retry
  • The fake Ghidra server
  • The event and network bounds
  • All eight new tests

The probe script is byte-identical on main.

Check PR head 8cbb79e Main 95c8f57
Events, Network and Ghidra client tests, Node 22.23.1 / 24.18.0 / 26.11.1 60 of 60 passed on each 119 of 119 passed on each (main's copies of these three files hold more tests than the PR's base)
Ghidra handshake probe (JDK 21) passed passed
10,001 page errors, then one 1,000,000-character error kept 10,000, dropped 2, no redaction call on the big one same numbers

The probe is the PR's script. It checks these cases:

  • A rejected client
  • EOF
  • The 64 KiB frame ceiling
  • The idle and slow-trickle deadlines
  • A later good client
  • A large pipelined request

On the PR's base commit 8fef2aa (#2938) the probe stops at once, because the Java file has no readLoopbackHandshake. No TCP check ran there.

What main does not have:

  • A section in docs/testing.md. Its title is Ghidra loopback admission regression. No doc or test on main mentions the probe.
  • One design difference. At 16 concurrent content reads the PR reports the extra content as unavailable. Main queues the extra jobs. I read this in the source and did not run it.

Thanks, cybrking, for the fix. Earlier I posted here that f690571 covered the network part. This comment adds the rest.

Not run

  • Real Ghidra and the Windows Ghidra provider lane.
  • A real browser, Playwright, or network traffic.
  • The 16-job difference, on either tree.
  • Windows and macOS.
Commands
git archive main | tar -x -C /tmp/ev-2961/main     # main 95c8f57aa
npm ci --ignore-scripts && npm run prepare && npm run build:cached && npm run test:prepare   # exit 0, both trees
npm run test:focused -- src/browser/PlaywrightScenarioEvents.test.ts src/browser/network/PlaywrightScenarioNetwork.test.ts tests/boundary/providers/ghidra/ghidraClient.test.ts   # Node 24, exit 0
# Node 22 and 26: same file list through the runner, exit 0
/usr/bin/node scripts/run-development-tests.mjs focused <same three files>
python3 tests/fixtures/ghidraHandshakeProbe.py ~/.local/opt/jdk-21.0.12.1+1/bin/java   # exit 0 on head and main; on the base it stops with exit 1 before any TCP check
Test setup

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 21, 2026

Copy link
Copy Markdown
Owner

Closing as superseded by main commits f690571 and d4bd65c, retained at 67a6477. Main contains the event/listener/transaction bounds, loopback handshake admission, retry path, probe script and regressions. The later comparison comment above independently confirms the original checks on main. Main deliberately queues extra content work within bounded transaction admission rather than immediately omitting it. The remaining short probe-running documentation note does not require retaining this broad implementation PR and can be proposed separately if still useful. This audit used current-main source/test inspection and existing discussion evidence; it did not rerun a browser or Ghidra workflow.

@morluto morluto closed this Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: domain Domain logic, errors, and pure functions bug Something isn't working security Target-execution safety, isolation, authority, and contamination handling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants