target='_blank'
attribute without rel='noopener noreferrer'
JS-042247 <Input placeholder="Search images" size="small" onSlInput={event => handleChange((event.target as HTMLInputElement).value)}>
48 <Icon name="search" slot="suffix"></Icon>
49 </Input>
50 <small className={styles.info}>Images provided from <a target="_blank" href="https://pixabay.com">pixabay</a></small>51 </div>
52 <Images searchValue={searchValue} selectImage={selectImage} />
53 </div>
58 </Input>
59 {expanded && (
60 <>
61 <small className={styles.info}>Images provided from <a target="_blank" href="https://pixabay.com">pixabay</a></small>62 <Images searchValue={searchValue} selectImage={selectImage} />
63 </>
64 )}
96 DATASETS.map(option => (
97 <MenuItem key={option} value={option} type="checkbox" checked={datasets.includes(option)}>
98 {option}
99 <a 100 className={styles.optionLink} 101 target="_blank" 102 href={getLinkForDataset(option)}103 >104 <BiLinkExternal />
105 </a>
106 </MenuItem>
When creating a JSX element with 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.
Using target='_blank'
links grants the page we are linking to a partial access to the source page via the window.opener
object.
The newly opened tab can then change the window.opener.location
to some phishing page. Or execute some JavaScript on the opener page on their behalf.
Since the users trust the page that is already opened, they won't get suspicious and this might result in a security risk.
// Bad: Example 1
var Hello = <a target='_blank' href="http://example.com/"></a>
// Bad: Example 2
var Hello = <a target='_blank' href={dynamicLink}></a>
// Example 1
var Hello = <p target="_blank"></p>
// Example 2
var Hello = <a target="_blank" rel="noreferrer" href="http://example.com"></a>
// Example 3
var Hello = <a target="_blank" rel="noopener noreferrer" href="http://example.com"></a>
// Example 4
var Hello = <a target="_blank" href="relative/path/in/the/host"></a>
// Example 5
var Hello = <a target="_blank" href="/absolute/path/in/the/host"></a>
// Example 6
var Hello = <a></a>