Skip to content

Commit

Permalink
Merge branch 'main' into eui-ghost/security
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen authored Oct 19, 2023
2 parents a032ba7 + d6f237a commit 5fcd426
Show file tree
Hide file tree
Showing 79 changed files with 2,290 additions and 543 deletions.
2 changes: 0 additions & 2 deletions .buildkite/pipelines/on_merge_unsupported_ftrs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ steps:
queue: n2-4-spot
depends_on: build
timeout_in_minutes: 120
parallelism: 4
retry:
automatic:
- exit_status: '-1'
Expand All @@ -41,7 +40,6 @@ steps:
queue: n2-4-spot
depends_on: build
timeout_in_minutes: 120
parallelism: 4
retry:
automatic:
- exit_status: '-1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('CspConfig', () => {
CspConfig {
"disableEmbedding": false,
"disableUnsafeEval": true,
"header": "script-src 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'",
"header": "script-src 'report-sample' 'self'; worker-src 'report-sample' 'self' blob:; style-src 'report-sample' 'self' 'unsafe-inline'",
"strict": true,
"warnLegacyBrowsers": true,
}
Expand Down Expand Up @@ -65,7 +65,7 @@ describe('CspConfig', () => {
worker_src: ['foo', 'bar'],
});
expect(config.header).toEqual(
`script-src 'self'; worker-src blob: 'self' foo bar; style-src 'unsafe-inline' 'self'`
`script-src 'report-sample' 'self'; worker-src 'report-sample' 'self' blob: foo bar; style-src 'report-sample' 'self' 'unsafe-inline'`
);
});

Expand All @@ -76,7 +76,7 @@ describe('CspConfig', () => {
});

expect(config.header).toEqual(
`script-src 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self' foo bar`
`script-src 'report-sample' 'self'; worker-src 'report-sample' 'self' blob:; style-src 'report-sample' 'self' 'unsafe-inline' foo bar`
);
});

Expand All @@ -87,7 +87,7 @@ describe('CspConfig', () => {
});

expect(config.header).toEqual(
`script-src 'self' foo bar; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'`
`script-src 'report-sample' 'self' foo bar; worker-src 'report-sample' 'self' blob:; style-src 'report-sample' 'self' 'unsafe-inline'`
);
});

Expand All @@ -99,7 +99,7 @@ describe('CspConfig', () => {
style_src: ['style', 'dolly'],
});
expect(config.header).toEqual(
`script-src 'self' script foo; worker-src blob: 'self' worker bar; style-src 'unsafe-inline' 'self' style dolly`
`script-src 'report-sample' 'self' script foo; worker-src 'report-sample' 'self' blob: worker bar; style-src 'report-sample' 'self' 'unsafe-inline' style dolly`
);
});

Expand All @@ -111,7 +111,7 @@ describe('CspConfig', () => {
style_src: ['style'],
});
expect(config.header).toEqual(
`script-src 'self' script; worker-src blob: 'self' worker; style-src 'unsafe-inline' 'self' style`
`script-src 'report-sample' 'self' script; worker-src 'report-sample' 'self' blob: worker; style-src 'report-sample' 'self' 'unsafe-inline' style`
);
});

Expand All @@ -124,7 +124,7 @@ describe('CspConfig', () => {
});

expect(config.header).toEqual(
`script-src 'self' foo bar; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'`
`script-src 'report-sample' 'self' foo bar; worker-src 'report-sample' 'self' blob:; style-src 'report-sample' 'self' 'unsafe-inline'`
);
});

Expand All @@ -136,7 +136,7 @@ describe('CspConfig', () => {
});

expect(config.header).toEqual(
`script-src 'self' 'unsafe-eval' foo bar; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'`
`script-src 'report-sample' 'self' 'unsafe-eval' foo bar; worker-src 'report-sample' 'self' blob:; style-src 'report-sample' 'self' 'unsafe-inline'`
);
});

Expand All @@ -147,7 +147,7 @@ describe('CspConfig', () => {
});

expect(config.header).toEqual(
`script-src 'self' foo bar; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'`
`script-src 'report-sample' 'self' foo bar; worker-src 'report-sample' 'self' blob:; style-src 'report-sample' 'self' 'unsafe-inline'`
);
});
});
Expand All @@ -160,7 +160,7 @@ describe('CspConfig', () => {
expect(config.disableEmbedding).toEqual(disableEmbedding);
expect(config.disableEmbedding).not.toEqual(CspConfig.DEFAULT.disableEmbedding);
expect(config.header).toMatchInlineSnapshot(
`"script-src 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'; frame-ancestors 'self'"`
`"script-src 'report-sample' 'self'; worker-src 'report-sample' 'self' blob:; style-src 'report-sample' 'self' 'unsafe-inline'; frame-ancestors 'self'"`
);
});

Expand All @@ -173,7 +173,7 @@ describe('CspConfig', () => {
expect(config.disableEmbedding).toEqual(disableEmbedding);
expect(config.disableEmbedding).not.toEqual(CspConfig.DEFAULT.disableEmbedding);
expect(config.header).toMatchInlineSnapshot(
`"script-src 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'; frame-ancestors 'self'"`
`"script-src 'report-sample' 'self'; worker-src 'report-sample' 'self' blob:; style-src 'report-sample' 'self' 'unsafe-inline'; frame-ancestors 'self'"`
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('CspDirectives', () => {
const config = cspConfig.schema.validate({});
const directives = CspDirectives.fromConfig(config);
expect(directives.getCspHeader()).toMatchInlineSnapshot(
`"script-src 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'"`
`"script-src 'report-sample' 'self'; worker-src 'report-sample' 'self' blob:; style-src 'report-sample' 'self' 'unsafe-inline'"`
);
});

Expand All @@ -91,7 +91,7 @@ describe('CspDirectives', () => {
const directives = CspDirectives.fromConfig(config);

expect(directives.getCspHeader()).toMatchInlineSnapshot(
`"script-src 'self' baz; worker-src blob: 'self' foo; style-src 'unsafe-inline' 'self' bar dolly"`
`"script-src 'report-sample' 'self' baz; worker-src 'report-sample' 'self' blob: foo; style-src 'report-sample' 'self' 'unsafe-inline' bar dolly"`
);
});

Expand All @@ -108,7 +108,7 @@ describe('CspDirectives', () => {
});
const directives = CspDirectives.fromConfig(config);
expect(directives.getCspHeader()).toMatchInlineSnapshot(
`"script-src 'self'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'; connect-src 'self' connect-src; default-src 'self' default-src; font-src 'self' font-src; frame-src 'self' frame-src; img-src 'self' img-src; frame-ancestors 'self' frame-ancestors; report-uri report-uri; report-to report-to"`
`"script-src 'report-sample' 'self'; worker-src 'report-sample' 'self' blob:; style-src 'report-sample' 'self' 'unsafe-inline'; connect-src 'self' connect-src; default-src 'self' default-src; font-src 'self' font-src; frame-src 'self' frame-src; img-src 'self' img-src; frame-ancestors 'self' frame-ancestors; report-uri report-uri; report-to report-to"`
);
});

Expand All @@ -118,7 +118,7 @@ describe('CspDirectives', () => {
});
const directives = CspDirectives.fromConfig(config);
expect(directives.getCspHeader()).toMatchInlineSnapshot(
`"script-src 'self' 'unsafe-hashes'; worker-src blob: 'self'; style-src 'unsafe-inline' 'self'"`
`"script-src 'report-sample' 'self' 'unsafe-hashes'; worker-src 'report-sample' 'self' blob:; style-src 'report-sample' 'self' 'unsafe-inline'"`
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export type CspDirectiveName =
* The default directives rules that are always applied
*/
export const defaultRules: Partial<Record<CspDirectiveName, string[]>> = {
'script-src': [`'self'`],
'worker-src': [`blob:`, `'self'`],
'style-src': [`'unsafe-inline'`, `'self'`],
'script-src': [`'report-sample'`, `'self'`],
'worker-src': [`'report-sample'`, `'self'`, `blob:`],
'style-src': [`'report-sample'`, `'self'`, `'unsafe-inline'`],
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ export class HttpServer {
// Hapi does not allow payload validation to be specified for 'head' or 'get' requests
const validate = isSafeMethod(route.method) ? undefined : { payload: true };
const { authRequired, tags, body = {}, timeout } = route.options;
const { accepts: allow, maxBytes, output, parse } = body;
const { accepts: allow, override, maxBytes, output, parse } = body;

const kibanaRouteOptions: KibanaRouteOptions = {
xsrfRequired: route.options.xsrfRequired ?? !isSafeMethod(route.method),
Expand All @@ -632,9 +632,12 @@ export class HttpServer {
// (All NP routes are already required to specify their own validation in order to access the payload)
validate,
// @ts-expect-error Types are outdated and doesn't allow `payload.multipart` to be `true`
payload: [allow, maxBytes, output, parse, timeout?.payload].some((x) => x !== undefined)
payload: [allow, override, maxBytes, output, parse, timeout?.payload].some(
(x) => x !== undefined
)
? {
allow,
override,
maxBytes,
output,
parse,
Expand Down
5 changes: 5 additions & 0 deletions packages/core/http/core-http-server/src/router/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export interface RouteConfigOptionsBody {
*/
accepts?: RouteContentType | RouteContentType[] | string | string[];

/**
* A mime type string overriding the 'Content-Type' header value received.
*/
override?: string;

/**
* Limits the size of incoming payloads to the specified byte count. Allowing very large payloads may cause the server to run out of memory.
*
Expand Down
18 changes: 15 additions & 3 deletions packages/kbn-resizable-layout/src/panels_resizable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ export const PanelsResizable = ({
() => setResizeWithPortalsHackIsResizing(false),
[]
);
const baseButtonCss = css`
background-color: transparent !important;
gap: 0 !important;
&:not(:hover):not(:focus) {
&:before,
&:after {
width: 0;
}
}
`;
const defaultButtonCss = css`
z-index: 3;
`;
Expand Down Expand Up @@ -207,9 +218,10 @@ export const PanelsResizable = ({
</EuiResizablePanel>
<EuiResizableButton
className={resizeButtonClassName}
css={
resizeWithPortalsHackIsResizing ? resizeWithPortalsHackButtonCss : defaultButtonCss
}
css={[
baseButtonCss,
resizeWithPortalsHackIsResizing ? resizeWithPortalsHackButtonCss : defaultButtonCss,
]}
data-test-subj={`${dataTestSubj}ResizableButton`}
/>
<EuiResizablePanel
Expand Down
6 changes: 5 additions & 1 deletion packages/kbn-unified-data-table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
*/

export { UnifiedDataTable, DataLoadingState } from './src/components/data_table';
export type { UnifiedDataTableProps } from './src/components/data_table';
export type {
UnifiedDataTableProps,
UnifiedDataTableRenderCustomToolbar,
UnifiedDataTableRenderCustomToolbarProps,
} from './src/components/data_table';
export { getDisplayedColumns } from './src/utils/columns';
export { getTextBasedColumnTypes } from './src/utils/get_column_types';
export { ROWS_HEIGHT_OPTIONS } from './src/constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
.euiDataGrid--rowHoverHighlight .euiDataGridRow:hover .euiDataGridRowCell__actions--overlay {
background-color: tintOrShade($euiColorLightShade, 50%, 0);
}

.euiDataGrid__scrollOverlay .euiDataGrid__scrollBarOverlayRight {
background-color: transparent; // otherwise the grid scrollbar border visually conflicts with the grid toolbar controls
}
}

.unifiedDataTable__table {
Expand Down
52 changes: 49 additions & 3 deletions packages/kbn-unified-data-table/src/components/data_table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ describe('UnifiedDataTable', () => {

expect(component.find(EuiDataGrid).prop('toolbarVisibility')).toMatchInlineSnapshot(`
Object {
"additionalControls": <React.Fragment />,
"additionalControls": null,
"showColumnSelector": false,
"showDisplaySelector": Object {
"additionalDisplaySettings": <UnifiedDataTableAdditionalDisplaySettings
Expand All @@ -339,7 +339,7 @@ describe('UnifiedDataTable', () => {

expect(component.find(EuiDataGrid).prop('toolbarVisibility')).toMatchInlineSnapshot(`
Object {
"additionalControls": <React.Fragment />,
"additionalControls": null,
"showColumnSelector": false,
"showDisplaySelector": Object {
"allowDensity": false,
Expand All @@ -360,7 +360,7 @@ describe('UnifiedDataTable', () => {

expect(component.find(EuiDataGrid).prop('toolbarVisibility')).toMatchInlineSnapshot(`
Object {
"additionalControls": <React.Fragment />,
"additionalControls": null,
"showColumnSelector": false,
"showDisplaySelector": undefined,
"showFullScreenSelector": true,
Expand Down Expand Up @@ -511,6 +511,52 @@ describe('UnifiedDataTable', () => {
});
});

describe('renderCustomToolbar', () => {
it('should render a custom toolbar', async () => {
let toolbarParams: Record<string, unknown> = {};
let gridParams: Record<string, unknown> = {};
const renderCustomToolbarMock = jest.fn((props) => {
toolbarParams = props.toolbarProps;
gridParams = props.gridProps;
return <div data-test-subj="custom-toolbar">Custom layout</div>;
});
const component = await getComponent({
...getProps(),
renderCustomToolbar: renderCustomToolbarMock,
});

// custom toolbar should be rendered
expect(findTestSubject(component, 'custom-toolbar').exists()).toBe(true);

expect(renderCustomToolbarMock).toHaveBeenLastCalledWith(
expect.objectContaining({
toolbarProps: expect.objectContaining({
hasRoomForGridControls: true,
}),
gridProps: expect.objectContaining({
additionalControls: null,
}),
})
);

// the default eui controls should be available for custom rendering
expect(toolbarParams?.columnSortingControl).toBeTruthy();
expect(toolbarParams?.keyboardShortcutsControl).toBeTruthy();
expect(gridParams?.additionalControls).toBe(null);

// additional controls become available after selecting a document
act(() => {
component
.find('[data-gridcell-column-id="select"] .euiCheckbox__input')
.first()
.simulate('change');
});

expect(toolbarParams?.keyboardShortcutsControl).toBeTruthy();
expect(gridParams?.additionalControls).toBeTruthy();
});
});

describe('gridStyleOverride', () => {
it('should render the grid with the default style if no gridStyleOverride is provided', async () => {
const component = await getComponent({
Expand Down
Loading

0 comments on commit 5fcd426

Please sign in to comment.