jsx-no-target-blank
Configuration
Disallow target="_blank" attribute without rel="noreferrer".
Rule Details
When creating a JSX element that has an a tag, it is often desired to have
the link open in a new tab using the target="_blank" attribute. Using this
attribute unaccompanied by rel="noreferrer", however, is a severe security
vulnerability (see
here for more details).
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Rule Options
allowReferrer
When true the rule permits rel="noopener" alone (the Referer header is
still sent). Defaults to false.
enforceDynamicLinks
"always"(default) — the rule also checks dynamic link targets (href={value})."never"— dynamic link targets are exempt.
warnOnSpreadAttributes
When true, spread attributes ({...props}) are treated as a potential
override of target / href / rel, so the rule may still report even when
the explicit attributes look safe. Defaults to false.
links / forms
Toggle the checks for anchor-like link components (links, default true)
and <form>-like components (forms, default false).
Custom components
The rule honors the top-level settings.linkComponents and
settings.formComponents entries, matching
eslint-plugin-react's linkComponents configuration.
Example:
Differences from ESLint
None — this rule aims for 1:1 behavior with
react/jsx-no-target-blank.
A few upstream implementation details deserve a note:
- The form branch (
forms: true) does not autofix, matching upstream. - When the
relattribute uses an expression the rule cannot analyze (e.g.rel={getRel()}), the diagnostic is still reported but no fix is emitted. - The secure-rel check for
<form>always treatsallowReferrerasfalse— forms with onlyrel="noopener"still report even when the rule-levelallowReferreroption is on, matching upstream'shasSecureRel(node)call shape.