Skip to content

Fix autoFocus for anchor elements and ReDoS in devtools stack parsing#35692

Closed
d1maash wants to merge 2 commits intofacebook:mainfrom
d1maash:feat/dimash
Closed

Fix autoFocus for anchor elements and ReDoS in devtools stack parsing#35692
d1maash wants to merge 2 commits intofacebook:mainfrom
d1maash:feat/dimash

Conversation

@d1maash
Copy link

@d1maash d1maash commented Feb 4, 2026

Summary

This PR addresses two open issues:

  1. Support autoFocus on anchor elements (Bug: Anchor tags do not support autoFocus #35656)

autoFocus is a [global HTML
attribute](https://developer.mozilla.org/en-US/docs/W
eb/HTML/Global_attributes/autofocus) supported by all
major browsers, but React only handles it for
button, input, select, and textarea. Added
<a> to the autoFocus handling in
finalizeInitialChildren and commitMount so that
<a href="..." autoFocus /> correctly receives focus
after mount.

  1. Fix ReDoS vulnerabilities in stack trace
    parsing (Bug: Inefficient Regular Expression Complexity in react #35490)

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

  • firefoxFrameRegExp: (?:.*".+")?[^@]*
    contains overlapping quantifiers that cause
    exponential backtracking on inputs with quotes but no
    @. Replaced with [^@"]*(?:"[^"]*"[^@"]*)* using
    non-overlapping character classes.
  • CHROME_STACK_REGEXP: .*(\S+:\d+|\(native\))
    causes O(n²) backtracking because .* and \S+
    overlap. Simplified to /^\s*at /m which is
    sufficient for Chrome vs Firefox format detection.

autoFocus is a global HTML attribute but React only handled it for
button, input, select, and textarea. This adds anchor tags to the
autoFocus handling in finalizeInitialChildren and commitMount, so that
<a autoFocus /> correctly receives focus after mount.
…#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
Copy link

meta-cla bot commented Feb 4, 2026

Hi @d1maash!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@d1maash d1maash closed this Feb 4, 2026
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