Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow HEAD requests without kbn-version header (4.x) #7944

Merged
merged 3 commits into from
Aug 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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