Skip to content

Commit f35c544

Browse files
committed
Add security note for rel="noreferrer” attribute
Fixes #32
1 parent b7ac86d commit f35c544

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

index.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@ import {type HTMLAttributes} from 'create-html-element';
33
export type Options = {
44
/**
55
HTML attributes to add to the link.
6+
7+
Security note: For external links, consider adding `rel: 'noreferrer'` to prevent the linked page from accessing `window.opener` and to avoid sending referrer information.
8+
9+
@example
10+
```
11+
linkifyUrlsToHtml('Visit https://example.com', {
12+
attributes: {
13+
rel: 'noreferrer',
14+
target: '_blank'
15+
}
16+
});
17+
//=> 'Visit <a href="https://example.com" rel="noreferrer" target="_blank">https://example.com</a>'
18+
```
619
*/
720
readonly attributes?: HTMLAttributes;
821

readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ Type: `object`
5858

5959
HTML attributes to add to the link.
6060

61+
**Security note:** For external links, consider adding `rel: 'noreferrer'` to prevent the linked page from accessing `window.opener` and to avoid sending referrer information. This helps protect against reverse tabnabbing attacks and preserves user privacy:
62+
63+
```js
64+
linkifyUrlsToHtml('Visit https://example.com', {
65+
attributes: {
66+
rel: 'noreferrer',
67+
target: '_blank'
68+
}
69+
});
70+
//=> 'Visit <a href="https://example.com" rel="noreferrer" target="_blank">https://example.com</a>'
71+
```
72+
6173
##### value
6274

6375
Type: `string | Function`\

0 commit comments

Comments
 (0)