vue/no-template-target-blank
disallow target="_blank" attribute without rel="noopener noreferrer"
- 💡 Some problems reported by this rule are manually fixable by editor suggestions.
📖 Rule Details
This rule disallows using target="_blank"
attribute without rel="noopener noreferrer"
to avoid a security vulnerability(see here for more details).
<template>
<!-- ✓ Good -->
<a href="http://example.com" target="_blank" rel="noopener noreferrer">link</a>
<!-- ✗ BAD -->
<a href="http://example.com" target="_blank" >link</a>
</template>
🔧 Options
json
{
"vue/no-template-target-blank": ["error", {
"allowReferrer": true,
"enforceDynamicLinks": "always"
}]
}
allowReferrer
... Iftrue
, does not require noreferrer.defaultfalse
enforceDynamicLinks ("always" | "never")
... Ifalways
, enforces the rule if the href is a dynamic link. defaultalways
.
{ allowReferrer: false }
(default)
<template>
<!-- ✓ Good -->
<a href="http://example.com" target="_blank" rel="noopener noreferrer">link</a>
<!-- ✗ BAD -->
<a href="http://example.com" target="_blank" rel="noopener">link</a>
</template>
{ allowReferrer: true }
<template>
<!-- ✓ Good -->
<a href="http://example.com" target="_blank" rel="noopener">link</a>
<!-- ✗ BAD -->
<a href="http://example.com" target="_blank" >link</a>
</template>
{ "enforceDynamicLinks": "always" }
(default)
<template>
<!-- ✓ Good -->
<a :href="link" target="_blank" rel="noopener noreferrer">link</a>
<!-- ✗ BAD -->
<a :href="link" target="_blank">link</a>
</template>
{ "enforceDynamicLinks": "never" }
<template>
<!-- ✓ Good -->
<a :href="link" target="_blank">link</a>
<!-- ✗ BAD -->
<a href="http://example.com" target="_blank" >link</a>
</template>
🚀 Version
This rule was introduced in eslint-plugin-vue v7.0.0