Skip to content

add rel="noopener noreferrer" to external links#2431

Open
azizbecha wants to merge 1 commit intoreact-native-community:mainfrom
azizbecha:fix/external-link-rel-noopener
Open

add rel="noopener noreferrer" to external links#2431
azizbecha wants to merge 1 commit intoreact-native-community:mainfrom
azizbecha:fix/external-link-rel-noopener

Conversation

@azizbecha
Copy link
Copy Markdown
Contributor

@azizbecha azizbecha commented May 2, 2026

Summary

The shared <A> component in common/styleguide.tsx defaults target to _blank but does not emit a matching rel attribute. Links opened in a new tab without rel="noopener" allow the new page to access window.opener, which is a known tabnabbing vector, and without noreferrer the referrer is leaked to the destination.

This sets rel="noopener noreferrer" (on both the web rel prop and the React Native hrefAttrs) whenever the resolved target is _blank. Internal target="_self" links are unaffected.

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".
Comment thread common/styleguide.tsx
numberOfLines={containerStyle ? 1 : undefined}
target={target ?? '_blank'}
hrefAttrs={{ target: target ?? '_blank' }}
rel={(target ?? '_blank') === '_blank' ? 'noopener noreferrer' : undefined}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we extract target ?? '_blank' to a variable to avoid checks repetition, and for a bit more code clarity?

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.

2 participants