]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
More secure target blank links
authorChocobozzz <me@florianbigard.com>
Mon, 19 Mar 2018 17:30:28 +0000 (18:30 +0100)
committerChocobozzz <me@florianbigard.com>
Mon, 19 Mar 2018 17:30:28 +0000 (18:30 +0100)
client/src/app/+admin/video-abuses/video-abuse-list/video-abuse-list.component.html
client/src/app/shared/misc/help.component.ts
client/src/app/videos/+video-watch/comment/video-comment.component.html
client/src/app/videos/+video-watch/comment/video-comment.component.ts
client/src/app/videos/+video-watch/video-watch.component.html
client/src/app/videos/shared/markdown.service.ts

index fcbdc614753ae760ba1562067073b57166770178..13a5b1117d510ee9a2349e304da509f42964b56e 100644 (file)
     <tr>
       <td>{{ videoAbuse.reason }}</td>
       <td>
-        <a [href]="videoAbuse.reporterAccount.url" title="Go to the account" target="_blank">
+        <a [href]="videoAbuse.reporterAccount.url" title="Go to the account" target="_blank" rel="noopener noreferrer">
           {{ createByString(videoAbuse.reporterAccount) }}
         </a>
       </td>
       <td>{{ videoAbuse.createdAt }}</td>
       <td>
-        <a [href]="videoAbuse.video.url" title="Go to the video" target="_blank">
+        <a [href]="videoAbuse.video.url" title="Go to the video" target="_blank" rel="noopener noreferrer">
           {{ videoAbuse.video.name }}
         </a>
       </td>
index a4a223cd6108d87b047ddfe9c039b8806f8f9989..19ac38b589adcaf3fdc4e43062e1261950fd4751 100644 (file)
@@ -46,7 +46,8 @@ export class HelpComponent implements OnInit {
   }
 
   private formatMarkdownSupport (rules: string[]) {
-    return '<a href="https://en.wikipedia.org/wiki/Markdown#Example" target="_blank">Markdown</a> compatible that supports:' +
+    return '<a href="https://en.wikipedia.org/wiki/Markdown#Example" target="_blank" rel="noopener noreferrer">Markdown</a> ' +
+      'compatible that supports:' +
       this.createMarkdownList(rules)
   }
 
index 831ea0521a94332c2a9903c5e95c736a4b05a8a2..8a649e88fe63ce80982e6d9fbf49dbf130bd12a5 100644 (file)
@@ -5,7 +5,7 @@
     <div *ngIf="highlightedComment === true" class="highlighted-comment">Highlighted comment</div>
 
     <div class="comment-account-date">
-      <a target="_blank" [href]="comment.account.url" class="comment-account">{{ comment.by }}</a>
+      <a [href]="comment.account.url"  target="_blank" rel="noopener noreferrer" class="comment-account">{{ comment.by }}</a>
       <a [routerLink]="['/videos/watch', video.uuid, { 'threadId': comment.threadId }]" class="comment-date">{{ comment.createdAt | myFromNow }}</a>
     </div>
     <div class="comment-html" [innerHTML]="sanitizedCommentHTML"></div>
index cfcefed830fe184c41b2b7931b6c7189e3236765..26fc9d0b8c3ec9a730baf08bb75976e25f2b6d5a 100644 (file)
@@ -107,7 +107,8 @@ export class VideoCommentComponent implements OnInit, OnChanges {
           return {
             tagName,
             attribs: Object.assign(attribs, {
-              target: '_blank'
+              target: '_blank',
+              rel: 'noopener noreferrer'
             })
           }
         }
index 6a7da06140e3669167dd64efbeaba2642c914974..6c7fc08e112bed0f8073532244e049c428b73917 100644 (file)
     <strong>Friendly Reminder:</strong>
     <div class="privacy-concerns-text">
       The sharing system used by this video implies that some technical information about your system (such as a public IP address) can be accessed publicly.
-      <a title="Get more information" target="_blank" href="/about#p2p-privacy">More information</a>
+      <a title="Get more information" target="_blank" rel="noopener noreferrer" href="/about#p2p-privacy">More information</a>
     </div>
 
     <div class="privacy-concerns-okay" (click)="acceptedPrivacyConcern()">
index 9d73efa4640695eed3b9c7d2650f13a87472044e..dd8ff20d83181b635eaf4c2725e9c272b11de6d3 100644 (file)
@@ -52,18 +52,19 @@ export class MarkdownService {
       return self.renderToken(tokens, idx, options)
     }
 
-    markdownIt.renderer.rules.link_open = function (tokens, idx, options, env, self) {
-      // If you are sure other plugins can't add `target` - drop check below
-      const aIndex = tokens[idx].attrIndex('target')
+    markdownIt.renderer.rules.link_open = function (tokens, index, options, env, self) {
+      const token = tokens[index]
 
-      if (aIndex < 0) {
-        tokens[idx].attrPush(['target', '_blank']) // add new attribute
-      } else {
-        tokens[idx].attrs[aIndex][1] = '_blank'    // replace value of existing attr
-      }
+      const targetIndex = token.attrIndex('target')
+      if (targetIndex < 0) token.attrPush([ 'target', '_blank' ])
+      else token.attrs[targetIndex][1] = '_blank'
+
+      const relIndex = token.attrIndex('rel')
+      if (relIndex < 0) token.attrPush([ 'rel', 'noopener noreferrer' ])
+      else token.attrs[relIndex][1] = 'noopener noreferrer'
 
       // pass token to default renderer.
-      return defaultRender(tokens, idx, options, env, self)
+      return defaultRender(tokens, index, options, env, self)
     }
   }