You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/jsx-no-target-blank.md
+35-7
Original file line number
Diff line number
Diff line change
@@ -5,19 +5,28 @@ This rules requires that you accompany `target='_blank'` attributes with `rel='n
5
5
6
6
## Rule Details
7
7
8
-
This rule aims to prevent user generated links from creating security vulnerabilities by requiring `rel='noreferrer'` for external links, and optionally any dynamically generated links.
8
+
This rule aims to prevent user generated link hrefs and form actions from creating security vulnerabilities by requiring `rel='noreferrer'` for external link hrefs and form actions, and optionally any dynamically generated link hrefs and form actions.
* allow-referrer: optional boolean. If `true` does not require `noreferrer`. Defaults to `false`.
18
-
* enabled: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
19
-
* enforceDynamicLinks: optional string, 'always' or 'never'
20
-
* warnOnSpreadAttributes: optional boolean. Defaults to `false`.
23
+
*`allowReferrer`: optional boolean. If `true` does not require `noreferrer`. Defaults to `false`.
24
+
*`enabled`: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
25
+
*`enforceDynamicLinks`: optional string, 'always' or 'never'
26
+
*`warnOnSpreadAttributes`: optional boolean. Defaults to `false`.
27
+
*`enforceDynamicLinks` - enforce: optional string, 'always' or 'never'
28
+
*`links` - Prevent usage of unsafe `target='_blank'` inside links, defaults to `true`
29
+
*`forms` - Prevent usage of unsafe `target='_blank'` inside forms, defaults to `false`
21
30
22
31
### `enforceDynamicLinks`
23
32
@@ -74,6 +83,20 @@ Defaults to false. If false, this rule will ignore all spread attributes. If tru
74
83
<a {...unsafeProps} href="/some-page"></a>
75
84
```
76
85
86
+
### `links` / `forms`
87
+
88
+
When option `forms` is set to `true`, the following is considered an error:
89
+
90
+
```jsx
91
+
var Hello =<form target="_blank" action="http://example.com/"></form>;
92
+
```
93
+
94
+
When option `links` is set to `true`, the following is considered an error:
95
+
96
+
```jsx
97
+
var Hello =<a target='_blank' href="http://example.com/"></form>
98
+
```
99
+
77
100
### Custom link components
78
101
79
102
This rule supports the ability to use custom components for links, such as `<Link />` which is popular in libraries like `react-router`, `next.js` and `gatsby`. To enable this, define your custom link components in the global [shared settings](https://github.com/yannickcr/eslint-plugin-react/blob/master/README.md#configuration) under the `linkComponents` configuration area. Once configured, this rule will check those components as if they were `<a />` elements.
@@ -94,9 +117,14 @@ var Hello = <Link target="_blank" to="/absolute/path/in/the/host"></Link>
94
117
var Hello =<Link />
95
118
```
96
119
120
+
### Custom form components
121
+
122
+
This rule supports the ability to use custom components for forms. To enable this, define your custom form components in the global [shared settings](https://github.com/yannickcr/eslint-plugin-react/blob/master/README.md#configuration) under the `formComponents` configuration area. Once configured, this rule will check those components as if they were `<form />` elements.
123
+
97
124
## When To Override It
125
+
98
126
For links to a trusted host (e.g. internal links to your own site, or links to a another host you control, where you can be certain this security vulnerability does not exist), you may want to keep the HTTP Referer header for analytics purposes.
99
127
100
128
## When Not To Use It
101
129
102
-
If you do not have any external links, you can disable this rule.
130
+
If you do not have any external links or forms, you can disable this rule.
0 commit comments