0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

meta referrer improvements (#7088)

closes #7060
- changed meta referrer from origin to origin-when-cross-origi
- made referrer policy configurable via referrerPolicy option in config js
- added example to config.example.js
-modified test to reflect new defaul origin-when-cross-origin
-added a test for configuration changed referrerPolicy
This commit is contained in:
Lukas Strassel 2016-07-14 18:14:59 +02:00 committed by Katharina Irrgang
parent 9c2d14949d
commit 6439d60bc8
3 changed files with 36 additions and 4 deletions

View file

@ -33,6 +33,11 @@ config = {
// Change this to your Ghost blog's published URL.
url: 'http://localhost:2368',
// Example refferer policy
// Visit https://www.w3.org/TR/referrer-policy/ for instructions
// default 'origin-when-cross-origin',
// referrerPolicy: 'origin-when-cross-origin',
// Example mail config
// Visit http://support.ghost.org/mail for instructions
// ```

View file

@ -80,14 +80,15 @@ function ghost_head(options) {
head = [],
context = this.context ? this.context[0] : null,
useStructuredData = !config.isPrivacyDisabled('useStructuredData'),
safeVersion = this.safeVersion;
safeVersion = this.safeVersion,
referrerPolicy = config.referrerPolicy ? config.referrerPolicy : 'origin-when-cross-origin';
return getClient().then(function (client) {
if (context) {
// head is our main array that holds our meta data
head.push('<link rel="canonical" href="' +
escapeExpression(metaData.canonicalUrl) + '" />');
head.push('<meta name="referrer" content="origin" />');
head.push('<meta name="referrer" content="' + referrerPolicy + '" />');
if (metaData.previousUrl) {
head.push('<link rel="prev" href="' +

View file

@ -83,7 +83,7 @@ describe('{{ghost_head}} helper', function () {
).then(function (rendered) {
should.exist(rendered);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/" \/>/);
rendered.string.should.match(/<meta name="referrer" content="origin" \/>/);
rendered.string.should.match(/<meta name="referrer" content="origin-when-cross-origin" \/>/);
rendered.string.should.match(/<meta property="og:site_name" content="Ghost" \/>/);
rendered.string.should.match(/<meta property="og:type" content="website" \/>/);
rendered.string.should.match(/<meta property="og:title" content="Ghost" \/>/);
@ -135,7 +135,7 @@ describe('{{ghost_head}} helper', function () {
).then(function (rendered) {
should.exist(rendered);
rendered.string.should.match(/<link rel="canonical" href="http:\/\/testurl.com\/about\/" \/>/);
rendered.string.should.match(/<meta name="referrer" content="origin" \/>/);
rendered.string.should.match(/<meta name="referrer" content="origin-when-cross-origin" \/>/);
rendered.string.should.match(/<meta property="og:site_name" content="Ghost" \/>/);
rendered.string.should.match(/<meta property="og:type" content="website" \/>/);
rendered.string.should.match(/<meta property="og:title" content="About" \/>/);
@ -803,6 +803,32 @@ describe('{{ghost_head}} helper', function () {
});
});
describe('with changed origin in config file', function () {
beforeEach(function () {
configUtils.set({
url: 'http://testurl.com/blog/',
theme: {
title: 'Ghost',
description: 'blog description',
cover: '/content/images/blog-cover.png'
},
referrerPolicy: 'origin'
});
});
it('contains the changed origin', function (done) {
helpers.ghost_head.call(
{safeVersion: '0.3', context: ['paged', 'index']},
{data: {root: {context: []}}}
).then(function (rendered) {
should.exist(rendered);
rendered.string.should.match(/<meta name="referrer" content="origin" \/>/);
done();
}).catch(done);
});
});
describe('with useStructuredData is set to false in config file', function () {
beforeEach(function () {
configUtils.set({