Skip to content

Commit

Permalink
[7.12] [core.http] Cleanup catch-all route for paths with trailing sl…
Browse files Browse the repository at this point in the history
…ashes. (#96889) (#97677)

* [core.http] Cleanup catch-all route for paths with trailing slashes. (#96889)

# Conflicts:
#	src/core/server/core_app/core_app.ts
#	src/core/server/core_app/integration_tests/core_app_routes.test.ts

* Fix eslint failures.
  • Loading branch information
lukeelmers authored Apr 20, 2021
1 parent d075a04 commit abb04c5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/legacy/server/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default async function (kbnServer, server) {
path: '/{p*}',
handler: function (req, h) {
const path = req.path;
if (path === '/' || path.charAt(path.length - 1) !== '/') {
if (path === '/' || path.charAt(path.length - 1) !== '/' || path.charAt(0) === '/') {
throw Boom.notFound();
}

Expand Down
39 changes: 39 additions & 0 deletions src/legacy/server/http/integration_tests/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import * as kbnTestServer from '../../../../core/test_helpers/kbn_server';

describe('Core app routes', () => {
let root;

beforeAll(async function () {
root = kbnTestServer.createRoot({
plugins: { initialize: false },
server: {
basePath: '/base-path',
},
});

await root.setup();
await root.start();
});

afterAll(async function () {
await root.shutdown();
});

describe('`/{path*}` route', () => {
it('does not redirect if the path starts with `//`', async () => {
await kbnTestServer.request.get(root, '//some-path/').expect(404);
});

it('does not redirect if the path does not end with `/`', async () => {
await kbnTestServer.request.get(root, '/some-path').expect(404);
});
});
});

0 comments on commit abb04c5

Please sign in to comment.