Skip to content

Fix secure TextInput leaking through the cached spannable on Android - #59472

Open
lazerg wants to merge 5 commits into
react:mainfrom
lazerg:fix/issue-59469-secure-textinput-leak
Open

lazerg wants to merge 5 commits into
react:mainfrom
lazerg:fix/issue-59469-secure-textinput-leak

Conversation

@lazerg

@lazerg lazerg commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Fixes #59469

On Android (Fabric), a secureTextEntry TextInput that got input is never released after it unmounts. updateCachedSpannable() copies the text with all its spans into the static spannable cache in TextLayoutManager, and that includes PasswordTransformationMethod.Visible, which holds the view's Editable and through it the view and its Activity. The cache entry was only removed in ReactEditText.finalize(), which can't run while the cache keeps the view alive.

The cache is keyed by the view's tag, so ReactTextInputManager now removes the entry in onDropViewInstance. Once the view is dropped nothing reads that entry again, and the view can be collected.

Changelog:

[ANDROID] [FIXED] - Fix secureTextEntry TextInput staying in memory after unmount

Test Plan:

Added ReactEditTextCachedSpannableTest, which types into a TextInput, checks that the cache has an entry for its tag, calls onDropViewInstance and checks the entry is gone. It fails on main and passes with this change.

./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests "com.facebook.react.views.textinput.*"

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 26, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Oct 26, 2026
@github-actions

github-actions Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Visual regression

No visual differences at 557462f540d8.

ios: no capture

@lazerg

lazerg commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Hey @cortinico, please take a look when you have time~

Comment on lines +1248 to +1249
stripSpansOfKind(sb, Any::class.java) { span ->
span !is CharacterStyle && span !is ParagraphStyle && span !is ReactSpan

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.

Could we preserve LineBreakConfigSpan here as well?

Android uses it for per-range line-breaking and hyphenation instructions.

Please also add an SDK-compatible preservation check and a regression test confirming that this layout span survives while PasswordTransformationMethod.Visible is still removed.

@lazerg

lazerg commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Done in 43642b2: LineBreakConfigSpan is kept now (guarded for API 35+), and the new test checks it survives while the password span is still dropped.

@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Dec 2, 2026
@meta-codesync

meta-codesync Bot commented Dec 2, 2026

Copy link
Copy Markdown

@cortinico has imported this pull request. If you are a Meta employee, you can view this in D135649529.

@Abbondanzo Abbondanzo left a comment •

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.

This seems like a stopgap, and solving the real issue would involve removing the view's entry from the spannable cache when the view instance is dropped. The cache is based on incrementing view IDs, so if the view manager is called with onDropViewInstance, then one can reasonably expect that to evict the cache entry

@lazerg

lazerg commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Done in 557462f: the cache entry is now removed in onDropViewInstance, so I dropped the span filtering and updated the test to cover the drop instead.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Android] Unmounted TextInput with secureTextEntry is never released: TextLayoutManager's spannable cache keeps it (and its Activity) alive

3 participants