Skip to content

Fix autoFocus for all elements and ReDoS in devtools stack parsing #35693

Open
d1maash wants to merge 5 commits intofacebook:mainfrom
d1maash:main
Open

Fix autoFocus for all elements and ReDoS in devtools stack parsing #35693
d1maash wants to merge 5 commits intofacebook:mainfrom
d1maash:main

Conversation

@d1maash
Copy link

@d1maash d1maash commented Feb 4, 2026

Summary

This PR addresses two open issues:

1. Support autoFocus as a global HTML attribute

(#35656)

autoFocus is a [global HTML
attribute](https://developer.mozilla.org/en-US/docs/W
eb/HTML/Global_attributes/autofocus) per the spec,
but React only handled it for button, input,
select, and textarea. This change treats
autoFocus as a global attribute so it works on
any focusable element — anchor tags, <div tabIndex={0}>, <dialog>, <details>, etc.

Changes:

  • finalizeInitialChildren: default case now returns
    !!props.autoFocus
  • commitMount: default case now calls .focus()
    when autoFocus is set
  • Added tests for <a autoFocus> and <div tabIndex={0} autoFocus>

2. Fix ReDoS vulnerabilities in stack trace

parsing (#35490)

Two regex patterns in parseStackTrace.js are
vulnerable to catastrophic backtracking:

  • firefoxFrameRegExp: (?:.*".+")?[^@]*
    contains overlapping quantifiers. Replaced with
    [^@"]*(?:"[^"]*"[^@"]*)* using non-overlapping
    character classes.
  • CHROME_STACK_REGEXP: .*(\S+:\d+|\(native\))
    causes O(n²) backtracking. Simplified to /^\s*at /m.

d1maash and others added 3 commits February 5, 2026 02:43
…acebook#35656)

autoFocus is a global HTML attribute per the spec, but React only
handled it for button, input, select, and textarea. This change treats
autoFocus as a global attribute so it works on any focusable element
including anchor tags, div with tabIndex, dialog, details, etc.

Changes:
- finalizeInitialChildren: default case now returns !!props.autoFocus
- commitMount: default case now calls .focus() when autoFocus is set
- Added tests for <a autoFocus> and <div tabIndex={0} autoFocus>
…#35490)

Fix two regex patterns in parseStackTrace.js vulnerable to catastrophic
backtracking:

1. firefoxFrameRegExp: replace overlapping .*".+" with non-overlapping
   character classes [^@"]*(?:"[^"]*"[^@"]*)*

2. CHROME_STACK_REGEXP: simplify detection regex from
   /^\s*at .*(\S+:\d+|\(native\))/m to /^\s*at /m to eliminate the
   O(n^2) backtracking between .* and \S+
@meta-cla meta-cla bot added the CLA Signed label Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant