Add a BlackFriday option for rel="noreferrer" on external links
authorStefan Neuhaus <stefan@stefanneuhaus.org>
Sun, 27 May 2018 21:20:39 +0000 (23:20 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 29 May 2018 14:54:43 +0000 (16:54 +0200)
Add a configuration option "noreferrerLinks". When set to "true" the "HTML_NOREFERRER_LINKS" flag is being passed to Blackfriday. Thereby all *absolute* links will get a "noreferrer" value for their "rel" attribute.

See #4722

docs/content/en/readfiles/bfconfig.md
helpers/content.go
helpers/content_test.go

index a7e74566a8c056aced24eb718bb0655f12220a3b..936aef52dec15032f7c04084617b5008db88cba2 100644 (file)
     Blackfriday flag: **`HTML_NOFOLLOW_LINKS`** <br>
     Purpose: `true` creates <s>external links</s> **absolute** links with `nofollow` being added to their `rel` attribute. Thereby crawlers are advised to not follow the link. While the `rel="nofollow"` attribute is typically used for external links, Blackfriday does that for _all_ absolute links. One needs to make note of this if they use absolute links throughout, for internal links too (for example, by setting `canonifyURLs` to `true` or via `absURL`).
 
+`noreferrerLinks`
+: default: **`false`** <br>
+    Blackfriday flag: **`HTML_NOREFERRER_LINKS`** <br>
+    Purpose: `true` creates <s>external links</s> **absolute** links with `noreferrer` being added to their `rel` attribute. Thus when following the link no referrer information will be leaked. While the `rel="noreferrer"` attribute is typically used for external links, Blackfriday does that for _all_ absolute links. One needs to make note of this if they use absolute links throughout, for internal links too (for example, by setting `canonifyURLs` to `true` or via `absURL`).
+
 `plainIDAnchors`
 : default **`true`** <br>
     Blackfriday flag: **`FootnoteAnchorPrefix` and `HeaderIDSuffix`** <br>
index 4a46ecb77c765b89517268311c95ce71198f51fc..1c0a7b7e9289d6173874e695e5877213a8a7127f 100644 (file)
@@ -109,6 +109,7 @@ type BlackFriday struct {
        Fractions             bool
        HrefTargetBlank       bool
        NofollowLinks         bool
+       NoreferrerLinks       bool
        SmartDashes           bool
        LatexDashes           bool
        TaskLists             bool
@@ -126,6 +127,7 @@ func newBlackfriday(config map[string]interface{}) *BlackFriday {
                "fractions":             true,
                "hrefTargetBlank":       false,
                "nofollowLinks":         false,
+               "noreferrerLinks":       false,
                "smartDashes":           true,
                "latexDashes":           true,
                "plainIDAnchors":        true,
@@ -283,6 +285,10 @@ func (c *ContentSpec) getHTMLRenderer(defaultFlags int, ctx *RenderingContext) b
                htmlFlags |= blackfriday.HTML_NOFOLLOW_LINKS
        }
 
+       if ctx.Config.NoreferrerLinks {
+               htmlFlags |= blackfriday.HTML_NOREFERRER_LINKS
+       }
+
        if ctx.Config.SmartDashes {
                htmlFlags |= blackfriday.HTML_SMARTYPANTS_DASHES
        }
index fe670bd7473135f71146e1b4efeba6a4b6271cb4..5297df2de2ab8a9a437a02c034c8180d5de1c4fa 100644 (file)
@@ -205,6 +205,7 @@ func TestGetHTMLRendererAllFlags(t *testing.T) {
                {blackfriday.HTML_SMARTYPANTS_FRACTIONS},
                {blackfriday.HTML_HREF_TARGET_BLANK},
                {blackfriday.HTML_NOFOLLOW_LINKS},
+               {blackfriday.HTML_NOREFERRER_LINKS},
                {blackfriday.HTML_SMARTYPANTS_DASHES},
                {blackfriday.HTML_SMARTYPANTS_LATEX_DASHES},
        }
@@ -214,6 +215,7 @@ func TestGetHTMLRendererAllFlags(t *testing.T) {
        ctx.Config.Fractions = true
        ctx.Config.HrefTargetBlank = true
        ctx.Config.NofollowLinks = true
+       ctx.Config.NoreferrerLinks = true
        ctx.Config.LatexDashes = true
        ctx.Config.PlainIDAnchors = true
        ctx.Config.SmartDashes = true