add rel="noopener noreferrer" to external links#2431
Open
azizbecha wants to merge 1 commit intoreact-native-community:mainfrom
Open
add rel="noopener noreferrer" to external links#2431azizbecha wants to merge 1 commit intoreact-native-community:mainfrom
azizbecha wants to merge 1 commit intoreact-native-community:mainfrom
Conversation
The shared <A> component defaults target to "_blank" but did not set rel, exposing the new tab to window.opener-based tabnabbing and leaking the referrer. Now sets rel="noopener noreferrer" whenever the resolved target is "_blank".
Simek
reviewed
May 3, 2026
| numberOfLines={containerStyle ? 1 : undefined} | ||
| target={target ?? '_blank'} | ||
| hrefAttrs={{ target: target ?? '_blank' }} | ||
| rel={(target ?? '_blank') === '_blank' ? 'noopener noreferrer' : undefined} |
Member
There was a problem hiding this comment.
Can we extract target ?? '_blank' to a variable to avoid checks repetition, and for a bit more code clarity?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The shared
<A>component incommon/styleguide.tsxdefaultstargetto_blankbut does not emit a matchingrelattribute. Links opened in a new tab withoutrel="noopener"allow the new page to accesswindow.opener, which is a known tabnabbing vector, and withoutnoreferrerthe referrer is leaked to the destination.This sets
rel="noopener noreferrer"(on both the webrelprop and the React NativehrefAttrs) whenever the resolved target is_blank. Internaltarget="_self"links are unaffected.