Skip to content

Commit

Permalink
Removes osd-name from response headers
Browse files Browse the repository at this point in the history
Addresses a potential security risk where the header could be used for
targeted attacks.

Signed-off-by: Tommy Markley <markleyt@amazon.com>
  • Loading branch information
Tommy Markley committed Jun 30, 2021
1 parent 570858a commit 17002b1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 60 deletions.
17 changes: 3 additions & 14 deletions src/core/server/http/integration_tests/lifecycle_handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const pkg = require('../../../../../package.json');
const actualVersion = pkg.version;
const versionHeader = 'osd-version';
const xsrfHeader = 'osd-xsrf';
const nameHeader = 'osd-name';
const whitelistedTestPath = '/xsrf/test/route/whitelisted';
const xsrfDisabledTestPath = '/xsrf/test/route/disabled';
const opensearchDashboardsName = 'my-opensearch-dashboards-name';
Expand Down Expand Up @@ -137,22 +136,12 @@ describe('core lifecycle handlers', () => {
await server.start();
});

it('adds the osd-name header', async () => {
it('does not add the osd-name header', async () => {
const result = await supertest(innerServer.listener).get(testRoute).expect(200, 'ok');
const headers = result.header as Record<string, string>;
expect(headers).toEqual(
expect.objectContaining({
[nameHeader]: opensearchDashboardsName,
})
);
});

it('adds the osd-name header in case of error', async () => {
const result = await supertest(innerServer.listener).get(testErrorRoute).expect(400);
const headers = result.header as Record<string, string>;
expect(headers).toEqual(
expect.objectContaining({
[nameHeader]: opensearchDashboardsName,
expect.not.objectContaining({
'osd-name': opensearchDashboardsName,
})
);
});
Expand Down
34 changes: 0 additions & 34 deletions src/core/server/http/lifecycle_handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,6 @@ describe('customHeaders pre-response handler', () => {
toolkit = httpServerMock.createToolkit();
});

it('adds the osd-name header to the response', () => {
const config = createConfig({ name: 'my-server-name' });
const handler = createCustomHeadersPreResponseHandler(config as HttpConfig);

handler({} as any, {} as any, toolkit);

expect(toolkit.next).toHaveBeenCalledTimes(1);
expect(toolkit.next).toHaveBeenCalledWith({ headers: { 'osd-name': 'my-server-name' } });
});

it('adds the custom headers defined in the configuration', () => {
const config = createConfig({
name: 'my-server-name',
Expand All @@ -284,30 +274,6 @@ describe('customHeaders pre-response handler', () => {
expect(toolkit.next).toHaveBeenCalledTimes(1);
expect(toolkit.next).toHaveBeenCalledWith({
headers: {
'osd-name': 'my-server-name',
headerA: 'value-A',
headerB: 'value-B',
},
});
});

it('preserve the osd-name value from server.name if definied in custom headders ', () => {
const config = createConfig({
name: 'my-server-name',
customResponseHeaders: {
'osd-name': 'custom-name',
headerA: 'value-A',
headerB: 'value-B',
},
});
const handler = createCustomHeadersPreResponseHandler(config as HttpConfig);

handler({} as any, {} as any, toolkit);

expect(toolkit.next).toHaveBeenCalledTimes(1);
expect(toolkit.next).toHaveBeenCalledWith({
headers: {
'osd-name': 'my-server-name',
headerA: 'value-A',
headerB: 'value-B',
},
Expand Down
13 changes: 1 addition & 12 deletions src/core/server/http/lifecycle_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { LifecycleRegistrar } from './http_server';

const VERSION_HEADER = 'osd-version';
const XSRF_HEADER = 'osd-xsrf';
const OPENSEARCH_DASHBOARDS_NAME_HEADER = 'osd-name';

export const createXsrfPostAuthHandler = (config: HttpConfig): OnPostAuthHandler => {
const { whitelist, disableProtection } = config.xsrf;
Expand Down Expand Up @@ -88,17 +87,7 @@ export const createVersionCheckPostAuthHandler = (
};

export const createCustomHeadersPreResponseHandler = (config: HttpConfig): OnPreResponseHandler => {
const serverName = config.name;
const customHeaders = config.customResponseHeaders;

return (request, response, toolkit) => {
const additionalHeaders = {
...customHeaders,
[OPENSEARCH_DASHBOARDS_NAME_HEADER]: serverName,
};

return toolkit.next({ headers: additionalHeaders });
};
return (request, response, toolkit) => toolkit.next({ headers: config.customResponseHeaders });
};

export const registerCoreHandlers = (
Expand Down

0 comments on commit 17002b1

Please sign in to comment.