Skip to content

Commit

Permalink
Merge pull request #7944 from lukasolson/fix/4.x/allow-head
Browse files Browse the repository at this point in the history
Allow HEAD requests without kbn-version header (4.x)
  • Loading branch information
epixa authored Aug 6, 2016
2 parents ce0c2ce + cea41cd commit d4a0308
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/server/http/__tests__/xsrf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { resolve } from 'path';
const requireFromTest = require('requirefrom')('test');
const kbnTestServer = requireFromTest('utils/kbn_server');

const nonDestructiveMethods = ['GET'];
const nonDestructiveMethods = ['GET', 'HEAD'];
const destructiveMethods = ['POST', 'PUT', 'DELETE'];
const src = resolve.bind(null, __dirname, '../../../../src');

Expand All @@ -30,9 +30,10 @@ describe('xsrf request filter', function () {

await kbnServer.ready();

const routeMethods = nonDestructiveMethods.filter(method => method !== 'HEAD').concat(destructiveMethods);
kbnServer.server.route({
path: '/xsrf/test/route',
method: [...nonDestructiveMethods, ...destructiveMethods],
method: routeMethods,
handler: function (req, reply) {
reply(null, 'ok');
}
Expand All @@ -54,7 +55,8 @@ describe('xsrf request filter', function () {
});

expect(resp.statusCode).to.be(200);
expect(resp.payload).to.be('ok');
if (method === 'HEAD') expect(resp.payload).to.be.empty();
else expect(resp.payload).to.be('ok');
});

it('failes on invalid tokens', async function () {
Expand All @@ -68,7 +70,8 @@ describe('xsrf request filter', function () {

expect(resp.statusCode).to.be(400);
expect(resp.headers).to.have.property(xsrfHeader, version);
expect(resp.payload).to.match(/"Browser client is out of date/);
if (method === 'HEAD') expect(resp.payload).to.be.empty();
else expect(resp.payload).to.match(/"Browser client is out of date/);
});
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/server/http/xsrf.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function (kbnServer, server, config) {
const header = 'kbn-version';

server.ext('onPostAuth', function (req, reply) {
const noHeaderGet = req.method === 'get' && !req.headers[header];
const noHeaderGet = (req.method === 'get' || req.method === 'head') && !req.headers[header];
if (disabled || noHeaderGet) return reply.continue();

const submission = req.headers[header];
Expand Down

0 comments on commit d4a0308

Please sign in to comment.