From 0555f023c1e1b2757d555a7a1678f48399017ee3 Mon Sep 17 00:00:00 2001 From: Diana Derevyankina Date: Fri, 18 Dec 2020 17:52:04 +0300 Subject: [PATCH] Move validateObject to kbn-std package and add a description --- ...ibana-plugin-core-server.validateobject.md | 2 +- .../validate_object.test.ts.snap | 0 packages/kbn-std/src/index.ts | 1 + .../kbn-std/src}/validate_object.test.ts | 0 .../kbn-std/src}/validate_object.ts | 0 src/core/server/http/http_tools.ts | 2 +- src/core/server/http/index.ts | 1 - .../server/http/prototype_pollution/index.ts | 20 ------------------- src/core/server/index.ts | 1 - .../vis_type_timeseries/server/routes/vis.ts | 2 +- 10 files changed, 4 insertions(+), 25 deletions(-) rename {src/core/server/http/prototype_pollution => packages/kbn-std/src}/__snapshots__/validate_object.test.ts.snap (100%) rename {src/core/server/http/prototype_pollution => packages/kbn-std/src}/validate_object.test.ts (100%) rename {src/core/server/http/prototype_pollution => packages/kbn-std/src}/validate_object.ts (100%) delete mode 100644 src/core/server/http/prototype_pollution/index.ts diff --git a/docs/development/core/server/kibana-plugin-core-server.validateobject.md b/docs/development/core/server/kibana-plugin-core-server.validateobject.md index 1772c21c873252..638fe6a05d3e15 100644 --- a/docs/development/core/server/kibana-plugin-core-server.validateobject.md +++ b/docs/development/core/server/kibana-plugin-core-server.validateobject.md @@ -14,7 +14,7 @@ export declare function validateObject(obj: any): void; | Parameter | Type | Description | | --- | --- | --- | -| obj | any | | +| obj | any | Is used to validate object properties for containing constructor and prototype with detecting circular references Returns: diff --git a/src/core/server/http/prototype_pollution/__snapshots__/validate_object.test.ts.snap b/packages/kbn-std/src/__snapshots__/validate_object.test.ts.snap similarity index 100% rename from src/core/server/http/prototype_pollution/__snapshots__/validate_object.test.ts.snap rename to packages/kbn-std/src/__snapshots__/validate_object.test.ts.snap diff --git a/packages/kbn-std/src/index.ts b/packages/kbn-std/src/index.ts index c111428017539e..fb0d6e5db2bba6 100644 --- a/packages/kbn-std/src/index.ts +++ b/packages/kbn-std/src/index.ts @@ -27,4 +27,5 @@ export { withTimeout } from './promise'; export { isRelativeUrl, modifyUrl, getUrlOrigin, URLMeaningfulParts } from './url'; export { unset } from './unset'; export { getFlattenedObject } from './get_flattened_object'; +export { validateObject } from './validate_object'; export * from './rxjs_7'; diff --git a/src/core/server/http/prototype_pollution/validate_object.test.ts b/packages/kbn-std/src/validate_object.test.ts similarity index 100% rename from src/core/server/http/prototype_pollution/validate_object.test.ts rename to packages/kbn-std/src/validate_object.test.ts diff --git a/src/core/server/http/prototype_pollution/validate_object.ts b/packages/kbn-std/src/validate_object.ts similarity index 100% rename from src/core/server/http/prototype_pollution/validate_object.ts rename to packages/kbn-std/src/validate_object.ts diff --git a/src/core/server/http/http_tools.ts b/src/core/server/http/http_tools.ts index 8bec26f31fa26b..a215dd8e073751 100644 --- a/src/core/server/http/http_tools.ts +++ b/src/core/server/http/http_tools.ts @@ -29,8 +29,8 @@ import Hoek from '@hapi/hoek'; import type { ServerOptions as TLSOptions } from 'https'; import type { ValidationError } from 'joi'; import uuid from 'uuid'; +import { validateObject } from '@kbn/std'; import { HttpConfig } from './http_config'; -import { validateObject } from './prototype_pollution'; const corsAllowedHeaders = ['Accept', 'Authorization', 'Content-Type', 'If-None-Match', 'kbn-xsrf']; /** diff --git a/src/core/server/http/index.ts b/src/core/server/http/index.ts index 06ea15e89ce0b3..cb842b2f602685 100644 --- a/src/core/server/http/index.ts +++ b/src/core/server/http/index.ts @@ -94,4 +94,3 @@ export { } from './cookie_session_storage'; export * from './types'; export { BasePath, IBasePath } from './base_path_service'; -export { validateObject } from './prototype_pollution'; diff --git a/src/core/server/http/prototype_pollution/index.ts b/src/core/server/http/prototype_pollution/index.ts deleted file mode 100644 index e1a33ffba155e8..00000000000000 --- a/src/core/server/http/prototype_pollution/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Licensed to Elasticsearch B.V. under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch B.V. licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -export { validateObject } from './validate_object'; diff --git a/src/core/server/index.ts b/src/core/server/index.ts index b007def4e81363..0f2761b67437db 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -201,7 +201,6 @@ export { RouteConfigOptionsBody, RouteContentType, validBodyOutput, - validateObject, RouteValidatorConfig, RouteValidationSpec, RouteValidationFunction, diff --git a/src/plugins/vis_type_timeseries/server/routes/vis.ts b/src/plugins/vis_type_timeseries/server/routes/vis.ts index 1ae6aa025eb6a1..ee23e5439511b4 100644 --- a/src/plugins/vis_type_timeseries/server/routes/vis.ts +++ b/src/plugins/vis_type_timeseries/server/routes/vis.ts @@ -19,12 +19,12 @@ import { IRouter, KibanaRequest } from 'kibana/server'; import { schema } from '@kbn/config-schema'; +import { validateObject } from '@kbn/std'; import { getVisData, GetVisDataOptions } from '../lib/get_vis_data'; import { visPayloadSchema } from '../../common/vis_schema'; import { ROUTES } from '../../common/constants'; import { ValidationTelemetryServiceSetup } from '../index'; import { Framework } from '../plugin'; -import { validateObject } from '../../../../core/server'; const escapeHatch = schema.object({}, { unknowns: 'allow' });