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

Reporting/bug more blacklisted headers #62389

Merged
merged 2 commits into from
Apr 3, 2020
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
9 changes: 9 additions & 0 deletions x-pack/legacy/plugins/reporting/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export const WHITELISTED_JOB_CONTENT_TYPES = [
'image/png',
];

// See:
// https://github.com/chromium/chromium/blob/3611052c055897e5ebbc5b73ea295092e0c20141/services/network/public/cpp/header_util_unittest.cc#L50
// For a list of headers that chromium doesn't like
export const KBN_SCREENSHOT_HEADER_BLACKLIST = [
'accept-encoding',
'connection',
Expand All @@ -38,8 +41,14 @@ export const KBN_SCREENSHOT_HEADER_BLACKLIST = [
// only for a single transport-level connection, and shouldn't
// be stored by caches or forwarded by proxies.
'transfer-encoding',
'trailer',
'te',
'upgrade',
'keep-alive',
];

export const KBN_SCREENSHOT_HEADER_BLACKLIST_STARTS_WITH_PATTERN = ['proxy-'];

export const UI_SETTINGS_CUSTOM_PDF_LOGO = 'xpackReporting:customPdfLogo';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ test(`omits blacklisted headers`, async () => {
'content-type': '',
host: '',
'transfer-encoding': '',
'proxy-connection': 'bananas',
'proxy-authorization': 'some-base64-encoded-thing',
trailer: 's are for trucks',
};

const filteredHeaders = await omitBlacklistedHeaders({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { omit } from 'lodash';
import { KBN_SCREENSHOT_HEADER_BLACKLIST } from '../../../common/constants';
import {
KBN_SCREENSHOT_HEADER_BLACKLIST,
KBN_SCREENSHOT_HEADER_BLACKLIST_STARTS_WITH_PATTERN,
} from '../../../common/constants';

export const omitBlacklistedHeaders = <JobDocPayloadType>({
job,
Expand All @@ -15,7 +18,12 @@ export const omitBlacklistedHeaders = <JobDocPayloadType>({
}) => {
const filteredHeaders: Record<string, string> = omit(
decryptedHeaders,
KBN_SCREENSHOT_HEADER_BLACKLIST
(_value, header: string) =>
header &&
(KBN_SCREENSHOT_HEADER_BLACKLIST.includes(header) ||
KBN_SCREENSHOT_HEADER_BLACKLIST_STARTS_WITH_PATTERN.some(pattern =>
header?.startsWith(pattern)
))
);
return filteredHeaders;
};