Skip to content

Commit 5ac120f

Browse files
committed
Add noopener/noreferrer
Fixes graphql#162
1 parent 90f729f commit 5ac120f

File tree

6 files changed

+26
-19
lines changed

6 files changed

+26
-19
lines changed

site/_core/DocsSidebar.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ import { toSlug } from './Header';
1414
function sidebarForCategory(thisPageID, category) {
1515
var listItems = [];
1616
for (var page of category.links) {
17-
var target = page.url.match(/^https?:/) && '_blank';
17+
18+
const shouldOpenInNewWindow = page.url.slice(0, 4) === 'http';
19+
const target = shouldOpenInNewWindow ? '_blank' : null;
20+
const rel = shouldOpenInNewWindow ? 'noopener noreferrer' : null;
21+
1822
var marginLeft = page.indent ? 20 : 0;
1923

2024
// Sublinks to any page sub-parts
2125
var sublinkUL = page.sublinks &&
2226
<ul>{page.sublinks.split(',').map(sublink =>
2327
<li key={sublink}>
24-
<a target={target} href={page.url + '#' + toSlug(sublink)}>
28+
<a target={target} rel={rel} href={page.url + '#' + toSlug(sublink)}>
2529
{sublink}
2630
</a>
2731
</li>
@@ -32,6 +36,7 @@ function sidebarForCategory(thisPageID, category) {
3236
<li key={page.permalink}>
3337
<a
3438
target={target}
39+
rel={rel}
3540
style={{marginLeft: marginLeft}}
3641
className={page.id === thisPageID ? 'active' : ''}
3742
href={page.url}>

site/_core/HeaderLinks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var HeaderLinks = React.createClass({
2424
key={link.section}
2525
href={link.href}
2626
target={link.href.slice(0, 4) === 'http' ? '_blank' : null}
27+
rel={link.href.slice(0, 4) === 'http' ? 'noopener noreferrer' : null}
2728
className={link.section === this.props.section ? 'active' : null}>
2829
{link.text}
2930
</a>

site/_core/Marked.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ InlineLexer.prototype.outputLink = function(cap, link) {
713713
return React.DOM.a({
714714
href: this.sanitizeUrl(link.href),
715715
title: link.title,
716-
target: shouldOpenInNewWindow ? '_blank' : ''
716+
target: shouldOpenInNewWindow ? '_blank' : null,
717+
rel: shouldOpenInNewWindow ? 'noopener noreferrer' : null
717718
}, this.output(cap[1]));
718719
} else {
719720
return React.DOM.img({

site/_core/Site.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,19 @@ var Site = React.createClass({
7878
<div>
7979
<h5><a href="/community">Community</a></h5>
8080
<a href="/community/upcoming-events/">Upcoming Events</a>
81-
<a href="http://stackoverflow.com/questions/tagged/graphql" target="_blank">Stack Overflow</a>
82-
<a href="https://www.facebook.com/groups/graphql.community/" target="_blank">Facebook Group</a>
83-
<a href="https://twitter.com/GraphQL" target="_blank">Twitter</a>
81+
<a href="http://stackoverflow.com/questions/tagged/graphql" target="_blank" rel="noopener noreferrer">Stack Overflow</a>
82+
<a href="https://www.facebook.com/groups/graphql.community/" target="_blank" rel="noopener noreferrer">Facebook Group</a>
83+
<a href="https://twitter.com/GraphQL" target="_blank" rel="noopener noreferrer">Twitter</a>
8484
</div>
8585
<div>
8686
<h5>More</h5>
8787
<a href="/blog">GraphQL Team Blog</a>
88-
<a href="http://facebook.github.io/graphql/" target="_blank">Read the Spec</a>
89-
<a href="https://github.com/graphql" target="_blank">GitHub</a>
90-
{page && <a href={'https://github.com/graphql/graphql.github.io/edit/source/site/' + page.relPath} target="_blank">Edit this page &#x270E;</a>}
88+
<a href="http://facebook.github.io/graphql/" target="_blank" rel="noopener noreferrer">Read the Spec</a>
89+
<a href="https://github.com/graphql" target="_blank" rel="noopener noreferrer">GitHub</a>
90+
{page && <a href={'https://github.com/graphql/graphql.github.io/edit/source/site/' + page.relPath} target="_blank" rel="noopener noreferrer">Edit this page &#x270E;</a>}
9191
</div>
9292
</section>
93-
<a href="https://code.facebook.com/projects/" target="_blank" className="fbOpenSource">
93+
<a href="https://code.facebook.com/projects/" target="_blank" rel="noopener noreferrer" className="fbOpenSource">
9494
<img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45" />
9595
</a>
9696
<section className="copyright">

site/index.html.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -535,32 +535,32 @@ public class Character {
535535
</div>
536536
<div className="logos">
537537
{/* Waiting for permission from some of the below */}
538-
<a href="https://www.facebook.com/" target="_blank">
538+
<a href="https://www.facebook.com/" target="_blank" rel="noopener noreferrer">
539539
<img src="/users/logos/facebook.png" title="Facebook" />
540540
</a>
541541
{/** /}
542-
<a href="https://twitter.com/" target="_blank">
542+
<a href="https://twitter.com/" target="_blank" rel="noopener noreferrer">
543543
<img src="/users/logos/twitter.png" title="Twitter" className="round" />
544544
</a>
545545
{/**/}
546-
<a href="https://developer.github.com/early-access/graphql" target="_blank">
546+
<a href="https://developer.github.com/early-access/graphql" target="_blank" rel="noopener noreferrer">
547547
<img src="/users/logos/github.png" title="GitHub" className="round" />
548548
</a>
549-
<a href="https://www.pinterest.com/" target="_blank">
549+
<a href="https://www.pinterest.com/" target="_blank" rel="noopener noreferrer">
550550
<img src="/users/logos/pinterest.png" title="Pinterest" className="round" />
551551
</a>
552552
{/** /}
553-
<a href="https://www.airbnb.com/" target="_blank">
553+
<a href="https://www.airbnb.com/" target="_blank" rel="noopener noreferrer">
554554
<img src="/users/logos/airbnb.png" title="Airbnb" className="round" />
555555
</a>
556556
{/**/}
557-
<a href="https://www.intuit.com/" target="_blank">
557+
<a href="https://www.intuit.com/" target="_blank" rel="noopener noreferrer">
558558
<img src="/users/logos/intuit.png" title="Intuit" />
559559
</a>
560-
<a href="https://www.coursera.org/" target="_blank">
560+
<a href="https://www.coursera.org/" target="_blank" rel="noopener noreferrer">
561561
<img src="/users/logos/coursera.png" title="Coursera" />
562562
</a>
563-
<a href="https://www.shopify.com/" target="_blank">
563+
<a href="https://www.shopify.com/" target="_blank" rel="noopener noreferrer">
564564
<img src="/users/logos/shopify.png" title="Shopify" className="round" />
565565
</a>
566566
</div>

site/users/index.html.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ module.exports = ({ page }) =>
292292
{logos.sort((a, b) =>
293293
a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1
294294
).map(logo =>
295-
<a href={logo.link} target="_blank" key={logo.name}>
295+
<a href={logo.link} target="_blank" rel="noopener noreferrer" key={logo.name}>
296296
<img src={'/users/logos/' + logo.img} title={logo.name} className={logo.isRound ? 'round' : null} />
297297
</a>
298298
)}

0 commit comments

Comments
 (0)