Skip to content

macOS engine: background Safari finds type_text's focused field by WebKit's text marker, never inspecting it (#395) - #417

Merged
SSFSKIM merged 12 commits into
mainfrom
fix/395-safari-marker-route
Nov 18, 2026
Merged

SSFSKIM merged 12 commits into
mainfrom
fix/395-safari-marker-route

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Nov 18, 2026

Copy link
Copy Markdown
Owner

What changes

Today: in background Safari, nothing answers AXFocusedUIElement: not the application, not the window, not the web area. type_text's read-back then falls back to #354's bounded walk, which gives up past 200 nodes. On a real-size page, type_text therefore answers noFocusedElement, even though the text landed.

Now: Safari takes WebKit's text-marker route to the field. The web area's AXSelectedTextMarkerRange gives a start marker; AXUIElementForTextMarker(start) gives an AXStaticText; its AXParent is the field. On a 1,600-node page, the route found the field 180/180, and the walk 0/180.

Privacy (ruling 1ea561bc:824, under 811). The marker carries the caret's character offset in plain bytes. WebKit returns it for password fields too, and there the caret is usually at the end, so the offset is usually the length. Condition by condition:

  1. The marker is opaque. The start marker goes from the reply into AXUIElementForTextMarker as an argument, then is released. It is never parsed, never passed to a string, length or index attribute, and never cached, logged, compared or emitted. CopyEndMarker and the marker byte/length functions are never even resolved (dlsym).
  2. Classified before read. The web area must classify as AXWebArea before its marker is read. Each element on the climb, at most 4 AXParent hops, is checked to be Safari's and classified with macOS engine: observation never reads a secure field's value, length or selection (protection is the AX provider's today) #405's valueClassification before anything else is read from it.
    • A secure role or subrole, or an unreadable subrole, gives .refused(.secure). An unreadable role gives .refused(.roleUnreadable). Nothing more is read in either case.
    • type_text still never reads a password field, as on main.
  3. The claim. The field must read AXFocused true. Its AXParent chain must reach the same web area within 24 hops, with every ancestor Safari's. Otherwise there is no claim, and the walk runs.
  4. Resolved before input. No marker call is made after any text is delivered. After typing, and at checkpoints, a marker-found field is confirmed by its own handle reading AXFocused true. Nothing is looked up again, and none of these reads depends on whether the request is concealed.
  5. Safari only. The route runs only for com.apple.Safari (exact bundle id), only when the application's AXFocusedUIElement answers absent, and only when the three symbols resolve. A failed focus read goes straight to the walk, as on main. Every other app is unchanged.

Files:

  • native/engine/Sources/Engine/TypeReadbackMarker.swift (new);
  • TypeReadback.swift, whose ReadbackAX makes every AX call injectable, so ReadbackReads.live runs whole over a stub Safari;
  • Input.swift, the Safari gate.

Docs:

Plugin 0.28.15 (ruling 822).

Evidence

Hosted macOS, Safari 27.2. docs/evidence/2026-11-18-safari-marker-route/README.md has the detail.

  • Discovery (kit probe/395-marker, run 44297805982): 462/462 trials, 0 wrong targets, 0 privacy violations.
    • The marker is 28 bytes, with the caret as a plain little-endian 32-bit word.
    • All 132 password rows resolved to the field.
    • AXStringForTextMarkerRange on a password selection returns masks at the exact length, which is why the product never calls it.
  • Qualification (kit probe/395-qual, run 44308992433), fix 0e9f4aff against main f2c30fc5, both unmodified, interleaved, 20 trials per cell:
main fix
small page, plain + short and long secret 60/60 confirmed, DOM exact 60/60 confirmed, DOM exact
large page (1,600 nodes), same 60/60 noFocusedElement 60/60 confirmed, DOM exact
password field from page load small secure, large noFocusedElement secure on both, no value or range in the reply
marker calls none exactly one pre-input pair in 160/160; none after input
fallbacks to the walk n/a 0
wrong successes / privacy violations 0 / 0 0 / 0
  • Secret audit (instrumented copies): the pre-input reads through classification are identical for literal, short-secret and long-secret text on the fix. Concealed short-vs-long whole schedules are equal after poll normalization.
  • One red row: fix/large/password r03. Input arrived, but the DOM didn't match. The engine answered secure, unconfirmed, as it should.
    • A targeted rerun (44322575578) ran 40 interleaved pairs on that cell: 40/40 exact on both heads. So it is treated as a background-Safari delivery flake.
  • Latency, large page, p50/p95: finding the field takes 8.2/13.7 ms on the fix, against 39.8/41.1 ms for main's walk to give up. This speeds up discovery; it doesn't make typing faster end to end.

Limits

Verification

  • Swift: swift test (native/engine) gives 1,347 tests, 0 failures, 1 skipped (CUA_304_TREES, pre-existing). TypeReadbackMarkerTests (14) are new.
    • The leak test ruling 824 asked for: stub markers carry known offsets. Neither offset reaches the reply JSON, the record, the error sentences or the stderr tail, in decimal, hex, the little-endian bytes or base64 forms.
    • Three injected leaks were caught.
    • Also covered: the gating, closed classifications, odd marker replies, scope and hop bounds, and the absence of any post-input marker call.
  • Node: core-documentation 7/7, docs-oracle 11/11 and docs-source-behavior 2/2.
  • Mutation: every guard was removed and caught, including the 7 that the review rounds added. One early survivor got a test.
  • Review: doperpowers:reviewer-high, over two rounds.
    • Round 1: classify the web area; ancestor ownership; absent vs failed focus; tests that crashed without the constructors.
    • Round 2: foreign elements in the web-area search; a wall-clock assertion.
    • All were fixed, except ancestor classification, which was dismissed for the reason above.
    • Both qualification kits were reviewed by doperpowers:reviewer-medium before dispatch.
  • ci-gate: plugin, test, engine-swift and parity-browser were GREEN on 0e9f4af (44306752262). This head adds only the evidence file; its gate on plugin, test and engine-swift was GREEN (44326134389).

Closes #395

Sminos-Session: cursor235#b93055dd (cua on macbook)

…bKit's text marker, never inspecting it (refs #395)

Background Safari names no focused element, and #354's walk gives up past
200 nodes, so on a real-size page type_text answered noFocusedElement. In
Safari only (the bundle identifier of the process read), once the
application's AXFocusedUIElement answers none, the read-back now takes
WebKit's route before the walk: the primary window's first AXWebArea (the
walk's bounds), its AXSelectedTextMarkerRange, that range's start marker
straight into AXUIElementForTextMarker on the web area, then at most four
AXParent hops to the field. The walk still runs when the route claims
nothing.

Under ruling 1ea561bc:824: the marker lives only in readbackMarkedElement
and is released there; nothing reads its bytes or length, the end marker is
never resolved, and no other parameterized attribute is asked. Every element
on the way is classified (role and subrole in one batch, #405's
valueClassification) before anything else is read of it; a closed one ends
the lookup with main's reason (secure, or roleUnreadable) and nothing more
read. A field is claimed only when it is the app's, reads AXFocused true and
its parents reach that web area. After typing, and at a checkpoint, a field
the route found is asked itself (AXFocused true on the same handle): no
marker call follows delivered text, and the reads do not depend on a secret.

ReadbackAX carries every Accessibility call of the live reads, so the tests
run the live composition over a stub Safari whose web area answers a real
AXTextMarkerRange with a known offset in its bytes.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…range (refs #395)

The stub web area now answers its range beside an error too, so the
range read's error check is exercised rather than covered by the stub.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…xt's field (refs #395)

Sminos-Session: cursor235#b93055dd (cua on macbook)
… to find the field (refs #395)

agent-cursor.md's typing paragraph loses its sentence on background
Safari's large page answering no focused field: the text-marker route now
finds that field. The docs oracle and the core-documentation test carry the
paragraph byte for byte; PROVENANCE.md and the surface inventory's "Table 3
amendment (2026-11-18, #395, ruling 1ea561bc:824)" record it.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…d the marker tests fail rather than crash (refs #395)

The mutation check found the failed-children guard of the web area's search
survived: its only case had no other web area to find. A web area after the
element whose children failed now must not be taken. The closed-field and
post-input tests unwrap their log positions with a failure instead of a trap.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…rker route (refs #395)

The entry records ruling 1ea561bc:824's conditions as built, the probe's
facts (runs 44296356927 and 44297805982: a 28-byte marker holding the caret
as an LE32 word, a password field's included), the choices the ruling left
(the route before the walk, the web area under the walk's bounds, four hops
to the field, the field focused and under that web area, the field's own
AXFocused after typing, Safari by bundle identifier), what is noted and not
measured, and the proof with its mutation check. #354's limit 11 points to
it. The log is appended oldest first, as this spec's always has been.

Sminos-Session: cursor235#b93055dd (cua on macbook)
… runs only on an absent focus answer (refs #395)

The high review's findings, as the design ruled:
- The web area is checked to be the app's and classified, open as an
  AXWebArea, before its marker is read; otherwise no claim, and the walk
  runs. It is not the field, so a closed classification is no refusal.
- Each ancestor the claim's scope climb passes is checked to be the app's
  before it is compared or climbed.
- readbackFocusedField takes the application's AXFocusedUIElement as a
  ReadbackWalkRead: an absent answer (noValue, attributeUnsupported) goes
  to the primary window, the marker, then the walk; a failed read
  (another error, or a reply that is not an element) to the walk alone,
  as on main (ruling 1ea561bc:824).
- The marker tests skip, rather than trap, where HIServices' private
  constructors or the engine's marker symbols do not resolve; the
  odd-reply test unwraps the symbols with XCTUnwrap.

New tests: the web area another process's, unreadable or classified
otherwise (five cases, no marker call); a failed or wrong-typed
application focus read (no marker call, the walk confirms a small page;
attributeUnsupported takes the route); an ancestor another process's.
The lookup-order test now shows the web area's classification before
its marker read. Each new guard, removed or weakened (six mutations),
fails a test.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ecks and the absent-only route (refs #395)

Item 2 (c): the web area is checked to be the app's and classified
(AXWebArea, open) before its marker is read; each ancestor of the scope
climb is checked to be the app's. Item 2 (e) and item 3: the route runs
only on an absent answer (noValue or attributeUnsupported); a failed
application focus read goes to the walk alone. Item 5: 14 test
functions, the new cases, the skip without the constructors, and the
six new mutations caught.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…pp's own elements (refs #395)

The re-review's findings:
- [P2] `readbackWebArea` takes an ownership predicate, and
  `readbackMarkedField` passes `marker.owned`. An element another process
  serves, the window included, is skipped: its role is not read, it is
  never the web area and its children are never followed, so a foreign
  provider cannot pick the page whose marker is read. The probe's `tree()`
  visited only owned elements. #354's walk is unchanged. The separate
  ownership check on the web area after the search is dropped, since
  the search now checks it.
- [P3] The tests that showed the fallback walk ran by its reaching
  node 1000, which the live walk's wall-clock 40 ms bound could stop
  on a slow runner, now count the window's AXChildren reads instead.
  The web area's search and the walk each read them first: two after
  the route claims nothing, one when a failed focus read skips the
  route.

New cases: in the generic search, a foreign group between the window
and a web area (not found, the group unread), a foreign sibling that
reads as a web area (skipped, the search goes on) and a foreign window
(nothing read); in the stub, a web area under another process's group
(no marker call, noFocusedElement). Removing the search's ownership
guard fails both.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…app's own elements (refs #395)

Item 3: the web area is the first AXWebArea among the app's own
elements, another process's (the window included) skipped unread, as
the probe's `tree()` visited only the app's. Item 5: the web area under
another process's group, six cases, and the search's ownership among
the mutations caught.

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ches (refs #395)

Sminos-Session: cursor235#b93055dd (cua on macbook)
…ari's text-marker route (refs #395)

Sminos-Session: cursor235#b93055dd (cua on macbook)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T14:45:41.929554Z 4170683 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.

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.

macOS engine: background Safari on a large page can't find the focused field for type_text's read-back (text-marker route)

1 participant