Open Bug 2091585 Opened 11 days ago Updated 11 days ago

Accessibility engine livelocks (100% CPU) when a page sets tabIndex=-1 on every element

Categories

(Core :: Disability Access APIs, defect)

Firefox 159
Desktop
macOS
defect

Tracking

()

People

(Reporter: hgwtpmedia, Unassigned)

References

(Depends on 1 open bug, Blocks 1 open bug)

Details

Attachments

(2 files)

On Firefox 159.0.1 for macOS, assigning element.tabIndex = -1 to every node returned by document.querySelectorAll("*") on a large DOM livelocks the tab’s content process. The main thread stays in recursive accessibility code and the page becomes unresponsive.

We hit this in the wild when Stripe.js Payment Request / Apple Pay runs a document-wide focus lock on checkout at https://hydrodipzone.com/. The Stripe.js lock is document.querySelectorAll("*") plus el.tabIndex = -1 on every node (lockFocus: true, lockFocusOn: null). The Firefox bug is reproducible without Stripe using the reduced test case attached.

Environment

  • Firefox 159.0.1, Build ID 20261102144711, version 15926.11.2
  • macOS 26.3.1
  • Hung process: tab plugin-container, x86_64, 100% CPU
  • Official XUL symbols (UUID F62AB15F-B49D-367B-95D5-2ED719D4C3CE) were used to name frames

Steps to reproduce

  1. Open the attached reduced test case (firefox-tabindex-a11y-hang.html) in Firefox 159 on macOS, with accessibility active (it often already is on macOS).
  2. Click “Set tabIndex=-1 on every element”.

Expected
The assignment finishes in a short time and the status line updates. The tab stays responsive.

Actual
The tab becomes unresponsive. The content process pegs one CPU core at 100%. The status line never updates. The browser parent process stays idle.

The same hang occurred on https://hydrodipzone.com/ when clicking Apple Pay on checkout (add a product, go to checkout, click Apple Pay; no payment completed). That production page is now mitigated on our side by skipping tabIndex = -1 writes on already non-tabbable nodes, so the live site may no longer hang. The reduced test still demonstrates the engine issue.

Symbolicated hang stack (content process main thread; 100% of samples)
The click/lock path is a JS timeout / callback setting tabIndex, which notifies layout and then accessibility:

  • js::jit::CallNativeSetter
  • mozilla::dom::HTMLElement_Binding::set_tabIndex
  • mozilla::dom::Element::SetTabIndex
  • mozilla::dom::Element::SetAttr
  • mozilla::PresShell::AttributeChanged
  • mozilla::a11y::DocAccessibleWrap::AttributeChanged
  • mozilla::a11y::DocAccessible::AttributeChanged
  • mozilla::a11y::LocalAccessible::DOMAttributeChanged
  • mozilla::a11y::LocalAccessible::State
  • mozilla::a11y::Accessible::ApplyImplicitState

Hot / recursive frames in the same walk included:

  • mozilla::a11y::LocalAccessible::ApplyARIAState
  • mozilla::a11y::Accessible::ApplyImplicitState
  • mozilla::a11y::LocalAccessible::ExplicitState / State
  • mozilla::nsIFrame::UsedUserSelectRecurse
  • mozilla::nsIFrame::IsSelectable
  • mozilla::a11y::aria::UniversalStatesFor / MapToState
  • mozilla::a11y::LocalAccessible::Name / NameIsEmpty / NativeState

This is a recursive a11y tree walk triggered by each tabindex attribute change. Doing it for every node in a large tree never completes.

Notes

  • This is not a security bug and is not filed for a bounty.
  • A separate report is going to Stripe, because their focus lock should not mutate non-tabbable nodes. Even with that fixed, Firefox should not livelock if a page does this.

While we obviously want to improve performance here if we can, it's important to note that setting tabindex="-1" actually makes things focusable, even if not tabbable. That is important because a focusable element must be exposed to the accessibility tree, even if it isn't tabbable. So we might optimise a whole bunch of nodes out of the accessibility tree, but if you go and set tabindex="-1" on those nodes, they're all suddenly going to get nodes in the accessibility tree. There's only so much we can do to mitigate many nodes being added to the tree at once.

Blocks: a11yperf
Severity: -- → S3

I suspect bug 2057395 is at least a significant contributor here.

Depends on: 2057395

Thanks for the explanation — that matches what we observed.

One clarification that may help: the reduced test stands in for Stripe.js Payment Request / Apple Pay. On show(), with lockFocus: true and lockFocusOn: null, it runs document.querySelectorAll("*") and sets el.tabIndex = -1 on every node. On a large WooCommerce checkout that livelocked the tab’s content process at 100% CPU. We mitigated it on our side by skipping tabIndex = -1 writes on elements that were not already keyboard-focusable.

We’re not asking Firefox to ignore tabindex="-1". The report is that inserting that many nodes into the accessibility tree at once never completes.

I'm guessing the stack is very, very deep, with lots of ApplyImplicitState? I'd ask you to provide a Firefox profile, but if it never returns at all, that's not going to be possible.

Yes — the symbolicated hang stack in the original report is already in ApplyImplicitState / ApplyARIAState, and it never returned, so we couldn’t capture a Firefox Profiler recording. Happy to try a smaller test that is slow but eventually finishes, if a profile would still help.

I actually can't reproduce this. I get "Done in 16 ms over 8094 nodes." with your test case.

Do you have any add-ons installed? Can the problem still be reproduced in Firefox troubleshooting mode?

Thanks for checking. 8094 nodes is the expected count for that file.

The hang we captured was in Firefox 159.0.1 on macOS 26.3.1, on a large WooCommerce checkout where Stripe.js ran the same querySelectorAll("*") + el.tabIndex = -1 loop. The symbolicated stack in the original report (deep in ApplyImplicitState / ApplyARIAState, content process at 100% CPU, never returning) is from that checkout.

Could you retry the reduced test with accessibility definitely instantiated? On macOS it is often already active, but if it isn’t, opening the Accessibility panel in Developer Tools (or VoiceOver) should start it. about:support has an Accessibility section that shows whether it is activated.

If it still finishes quickly with accessibility active, the 8094-node file may be below the threshold of the original checkout. We can attach a larger test if that would help.

We don’t have any user-installed add-ons in the Firefox profile where we captured the hang — only Mozilla’s built-in components (New Tab, Form Autofill, Picture-in-Picture, Web Compatibility Interventions, and the default theme).

We have not yet re-tested in troubleshooting mode. The original hang was on a large WooCommerce checkout, which is now mitigated on our side, and the smaller attached test did not hang for you. We’ll try troubleshooting mode once we have a test case that still hangs here, and report back.

(In reply to hgwtpmedia from comment #8)

Could you retry the reduced test with accessibility definitely instantiated?

It's definitely instantiated. I'm using a screen reader, as I'm totally blind. :)

If it still finishes quickly with accessibility active, the 8094-node file may be below the threshold of the original checkout.

Can you reproduce the indefinite hang yourself with the test case? The test case is not a deep tree, which I suspect matters a lot... but I got the impression you were able to reproduce it with your own test case.

I am testing on Windows here, not MacOS, but because this hang is happening in the content process, it shouldn't be platform specific. I can have a colleague test on mac, but I cannot fathom why that would make a difference at this stage.

(In reply to James Teh [:Jamie] from comment #6)

I actually can't reproduce this. I get "Done in 16 ms over 8094 nodes." with your test case.

Testing with the attached testcase on macOS with VO active (macOS 27.2) I get "Done in 24 ms over 8094 nodes."

Thanks, James. You were right that depth matters a lot.

I can now reproduce an indefinite hang here, but not with the original attached test, and not with a larger but relatively shallow tree.

On Firefox 159.0.1 / macOS, with accessibility enabled:

  • A bushy tree of 15,258 nodes at depth 40 completed in 82 ms.
  • A 2000-deep spine of wrapping <div>s (only 2,018 nodes total, with role="group" every 50 levels) hangs indefinitely on the same document.querySelectorAll("*") + el.tabIndex = -1 loop. The status line never updates, and the content process stays at 100% CPU. I waited long enough to be sure this was not just slow: the assignment did not return within 20 seconds, and the content process was still at 100% CPU more than 50 seconds later.

I’m attaching a new test page, firefox-tabindex-a11y-hang-deep.html. It has both cases:

  • “Set tabIndex=-1 on a deep bushy tree” (depth 40, many nodes) — this did not hang for me
  • “Set tabIndex=-1 on a 2000-deep spine” — this is the one that hangs

You can also open it with ?autorun=spine.

This was reproduced in a clean Firefox profile with no extra add-ons. I’m on macOS; as you noted, the hang is in the content process, so I hope it also shows up on Windows. The live shop I originally hit this on is already mitigated on our side, so this file is a better reproduction than the live checkout.

Thanks for checking the original test on macOS with VoiceOver — that matches what James and I see with that file.

The hang is in a new test, attached in comment 12 (attachment 9679114 [details], firefox-tabindex-a11y-hang-deep.html). The case that hangs here is “Set tabIndex=-1 on a 2000-deep spine” (or open it with ?autorun=spine). The bushy depth-40 tree on the same page did not hang.

Could you retry with that file, with accessibility or VoiceOver active?

I can reproduce with the deep tree. Thanks. That deepens my suspicion that bug 2057395 is largely to blame here, though i need to get a full stack dump to be sure.

Status: UNCONFIRMED → NEW
Ever confirmed: true
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: