mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
🐛Fixed generic 500 for bad key param in content API (#10977)
refs #10948 - Throws 400 when using multiple key query-values instead of a 500 error
This commit is contained in:
parent
9037c19e50
commit
730e307d18
4 changed files with 34 additions and 0 deletions
|
@ -7,6 +7,13 @@ const authenticateContentApiKey = function authenticateContentApiKey(req, res, n
|
||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (req.query.key.constructor === Array) {
|
||||||
|
return next(new common.errors.BadRequestError({
|
||||||
|
message: common.i18n.t('errors.middleware.auth.invalidRequest'),
|
||||||
|
code: 'INVALID_REQUEST'
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
let key = req.query.key;
|
let key = req.query.key;
|
||||||
|
|
||||||
models.ApiKey.findOne({secret: key}).then((apiKey) => {
|
models.ApiKey.findOne({secret: key}).then((apiKey) => {
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
"unknownContentApiKey": "Unknown Content API Key",
|
"unknownContentApiKey": "Unknown Content API Key",
|
||||||
"adminApiKidMissing": "Admin API kid missing.",
|
"adminApiKidMissing": "Admin API kid missing.",
|
||||||
"invalidApiKeyType": "Invalid API Key type",
|
"invalidApiKeyType": "Invalid API Key type",
|
||||||
|
"invalidRequest": "Invalid Request",
|
||||||
"invalidToken": "Invalid token",
|
"invalidToken": "Invalid token",
|
||||||
"invalidTokenWithMessage": "Invalid token: {message}",
|
"invalidTokenWithMessage": "Invalid token: {message}",
|
||||||
"incorrectAuthHeaderFormat": "Authorization header format is \"Authorization: Ghost [token]\""
|
"incorrectAuthHeaderFormat": "Authorization header format is \"Authorization: Ghost [token]\""
|
||||||
|
|
|
@ -154,4 +154,13 @@ describe('Posts', function () {
|
||||||
localUtils.API.checkResponse(res.body.posts[0], 'post', null, null, ['id', 'title', 'slug']);
|
localUtils.API.checkResponse(res.body.posts[0], 'post', null, null, ['id', 'title', 'slug']);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can\'t read page with multiple keys', function () {
|
||||||
|
return request
|
||||||
|
.get(localUtils.API.getApiQuery(`posts?key=${validKey}&key=&fields=title,slug`))
|
||||||
|
.set('Origin', testUtils.API.getURL())
|
||||||
|
.expect('Content-Type', /json/)
|
||||||
|
.expect('Cache-Control', testUtils.cacheRules.private)
|
||||||
|
.expect(400);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -78,4 +78,21 @@ describe('Content API Key Auth', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('shouldn\'t authenticate with invalid request', function (done) {
|
||||||
|
const req = {
|
||||||
|
query: {
|
||||||
|
key: [this.fakeApiKey.secret, '']
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const res = {};
|
||||||
|
|
||||||
|
authenticateContentApiKey(req, res, function next(err) {
|
||||||
|
should.exist(err);
|
||||||
|
should.equal(err instanceof common.errors.BadRequestError, true);
|
||||||
|
err.code.should.eql('INVALID_REQUEST');
|
||||||
|
should.not.exist(req.api_key);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue