Skip to content

Commit d798043

Browse files
Switched to "safe" version in default request user-agent header (#217)
no issue - we don't usually want to expose the full patch version of software, instead limiting to the `major.minor` part - switched from `ghostVersion.original` to `ghostVersion.safe` in the default user-agent to limit the exposed data
1 parent 3f222f1 commit d798043

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

packages/request/lib/request.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let cacheableLookup;
1111

1212
const defaultOptions = {
1313
headers: {
14-
'user-agent': 'Ghost/' + ghostVersion.original + ' (https://github.com/TryGhost/Ghost)'
14+
'user-agent': 'Ghost/' + ghostVersion.safe + ' (https://github.com/TryGhost/Ghost)'
1515
},
1616
method: 'GET'
1717
};

packages/request/test/request.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ const nock = require('nock');
77
const request = require('../lib/request');
88

99
describe('Request', function () {
10+
it('has "safe" version in default user-agent header', function () {
11+
const url = 'http://some-website.com/endpoint/';
12+
13+
nock('http://some-website.com')
14+
.get('/endpoint/')
15+
.reply(200, 'Response body');
16+
17+
return request(url, {}).then(function ({req}) {
18+
req.headers['user-agent'].should.match(/Ghost\/[0-9]+\.[0-9]+\s/);
19+
});
20+
});
21+
1022
it('[success] should return response for http request', function () {
1123
const url = 'http://some-website.com/endpoint/';
1224
const expectedResponse = {

0 commit comments

Comments
 (0)