Skip to content

Commit 25d8297

Browse files
committed
Removed support for mixed http/https mode
refs: TryGhost/Ghost#14446 - currently ghost will upgrade configured urls to https if a secure request comes into a http configured site - we no longer want to support this feature - instead, ghost will strictly honour the configured URL
1 parent dd64149 commit 25d8297

File tree

2 files changed

+6
-49
lines changed

2 files changed

+6
-49
lines changed

packages/url-utils/lib/url-utils.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,14 @@ module.exports = class UrlUtils {
7070
// Parameters:
7171
// - urlPath - string which must start and end with a slash
7272
// - absolute (optional, default:false) - boolean whether or not the url should be absolute
73-
// - secure (optional, default:false) - boolean whether or not to force SSL
7473
// Returns:
7574
// - a URL which always ends with a slash
76-
createUrl(urlPath = '/', absolute = false, secure, trailingSlash) {
75+
createUrl(urlPath = '/', absolute = false, trailingSlash) {
7776
let base;
7877

7978
// create base of url, always ends without a slash
8079
if (absolute) {
81-
base = this.getSiteUrl(secure);
80+
base = this.getSiteUrl();
8281
} else {
8382
base = this.getSubdir();
8483
}
@@ -109,7 +108,6 @@ module.exports = class UrlUtils {
109108
// @TODO: rewrite, very hard to read, create private functions!
110109
urlFor(context, data, absolute) {
111110
let urlPath = '/';
112-
let secure;
113111
let imagePathRe;
114112
let knownObjects = ['image', 'nav'];
115113
let baseUrl;
@@ -127,9 +125,6 @@ module.exports = class UrlUtils {
127125
data = null;
128126
}
129127

130-
// Can pass 'secure' flag in either context or data arg
131-
secure = (context && context.secure) || (data && data.secure);
132-
133128
if (_.isObject(context) && context.relativeUrl) {
134129
urlPath = context.relativeUrl;
135130
} else if (_.isString(context) && _.indexOf(knownObjects, context) !== -1) {
@@ -141,15 +136,14 @@ module.exports = class UrlUtils {
141136
if (absolute) {
142137
// Remove the sub-directory from the URL because ghostConfig will add it back.
143138
urlPath = urlPath.replace(new RegExp('^' + this.getSubdir()), '');
144-
baseUrl = this.getSiteUrl(secure).replace(/\/$/, '');
139+
baseUrl = this.getSiteUrl().replace(/\/$/, '');
145140
urlPath = baseUrl + urlPath;
146141
}
147142

148143
return urlPath;
149144
} else if (context === 'nav' && data.nav) {
150145
urlPath = data.nav.url;
151-
secure = data.nav.secure || secure;
152-
baseUrl = this.getSiteUrl(secure);
146+
baseUrl = this.getSiteUrl();
153147
hostname = baseUrl.split('//')[1];
154148

155149
// If the hostname is present in the url
@@ -165,7 +159,7 @@ module.exports = class UrlUtils {
165159
}
166160
}
167161
} else if (context === 'home' && absolute) {
168-
urlPath = this.getSiteUrl(secure);
162+
urlPath = this.getSiteUrl();
169163

170164
// CASE: there are cases where urlFor('home') needs to be returned without trailing
171165
// slash e. g. the `{{@site.url}}` helper. See https://github.com/TryGhost/Ghost/issues/8569
@@ -210,7 +204,7 @@ module.exports = class UrlUtils {
210204
return urlPath;
211205
}
212206

213-
return this.createUrl(urlPath, absolute, secure);
207+
return this.createUrl(urlPath, absolute);
214208
}
215209

216210
redirect301(res, redirectUrl) {

packages/url-utils/test/unit/url-utils.test.js

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -128,55 +128,35 @@ describe('UrlUtils', function () {
128128
fakeConfig.url = 'http://my-ghost-blog.com';
129129
utils.urlFor(testContext).should.equal('/');
130130
utils.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/');
131-
utils.urlFor(testContext, {secure: true}, true).should.equal('https://my-ghost-blog.com/');
132131

133132
fakeConfig.url = 'http://my-ghost-blog.com/';
134133
utils.urlFor(testContext).should.equal('/');
135134
utils.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/');
136-
utils.urlFor(testContext, {secure: true}, true).should.equal('https://my-ghost-blog.com/');
137135

138136
fakeConfig.url = 'http://my-ghost-blog.com/blog';
139137
utils.urlFor(testContext).should.equal('/blog/');
140138
utils.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/');
141-
utils.urlFor(testContext, {secure: true}, true).should.equal('https://my-ghost-blog.com/blog/');
142139

143140
fakeConfig.url = 'http://my-ghost-blog.com/blog/';
144141
utils.urlFor(testContext).should.equal('/blog/');
145142
utils.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/');
146-
utils.urlFor(testContext, {secure: true}, true).should.equal('https://my-ghost-blog.com/blog/');
147143

148144
// Output blog url without trailing slash
149145
fakeConfig.url = 'http://my-ghost-blog.com';
150146
utils.urlFor(testContext).should.equal('/');
151147
utils.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/');
152-
utils.urlFor(testContext, {
153-
secure: true,
154-
trailingSlash: false
155-
}, true).should.equal('https://my-ghost-blog.com');
156148

157149
fakeConfig.url = 'http://my-ghost-blog.com/';
158150
utils.urlFor(testContext).should.equal('/');
159151
utils.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/');
160-
utils.urlFor(testContext, {
161-
secure: true,
162-
trailingSlash: false
163-
}, true).should.equal('https://my-ghost-blog.com');
164152

165153
fakeConfig.url = 'http://my-ghost-blog.com/blog';
166154
utils.urlFor(testContext).should.equal('/blog/');
167155
utils.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/');
168-
utils.urlFor(testContext, {
169-
secure: true,
170-
trailingSlash: false
171-
}, true).should.equal('https://my-ghost-blog.com/blog');
172156

173157
fakeConfig.url = 'http://my-ghost-blog.com/blog/';
174158
utils.urlFor(testContext).should.equal('/blog/');
175159
utils.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/');
176-
utils.urlFor(testContext, {
177-
secure: true,
178-
trailingSlash: false
179-
}, true).should.equal('https://my-ghost-blog.com/blog');
180160
});
181161

182162
it('should handle weird cases by always returning /', function () {
@@ -201,14 +181,6 @@ describe('UrlUtils', function () {
201181
utils.urlFor(testContext).should.equal('/blog/about/');
202182
utils.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/about/');
203183

204-
testContext.secure = true;
205-
utils.urlFor(testContext, true).should.equal('https://my-ghost-blog.com/blog/about/');
206-
207-
testContext.secure = false;
208-
utils.urlFor(testContext, true).should.equal('http://my-ghost-blog.com/blog/about/');
209-
210-
testContext.secure = false;
211-
212184
fakeConfig.url = 'https://my-ghost-blog.com';
213185
utils.urlFor(testContext, true).should.equal('https://my-ghost-blog.com/about/');
214186
});
@@ -254,12 +226,6 @@ describe('UrlUtils', function () {
254226
testData = {image: '/blog/static/images/my-image4.jpg'};
255227
utils.urlFor(testContext, testData).should.equal('/blog/static/images/my-image4.jpg');
256228
utils.urlFor(testContext, testData, true).should.equal('http://my-ghost-blog.com/blog/static/images/my-image4.jpg');
257-
258-
// Test case for blogs with optional https -
259-
// they may be configured with http url but the actual connection may be over https (#8373)
260-
fakeConfig.url = 'http://my-ghost-blog.com';
261-
testData = {image: '/static/images/my-image.jpg', secure: true};
262-
utils.urlFor(testContext, testData, true).should.equal('https://my-ghost-blog.com/static/images/my-image.jpg');
263229
});
264230

265231
it('should return a url for a nav item when asked for it', function () {
@@ -272,9 +238,6 @@ describe('UrlUtils', function () {
272238
testData = {nav: {url: 'http://my-ghost-blog.com/short-and-sweet/'}};
273239
utils.urlFor(testContext, testData).should.equal('http://my-ghost-blog.com/short-and-sweet/');
274240

275-
testData = {nav: {url: 'http://my-ghost-blog.com//short-and-sweet/'}, secure: true};
276-
utils.urlFor(testContext, testData).should.equal('https://my-ghost-blog.com/short-and-sweet/');
277-
278241
testData = {nav: {url: 'http://my-ghost-blog.com:3000/'}};
279242
utils.urlFor(testContext, testData).should.equal('http://my-ghost-blog.com:3000/');
280243

0 commit comments

Comments
 (0)