Skip to content

Commit 715ff2a

Browse files
authored
[Security Solution][Exceptions] - Require non empty entries and non empty string values in exception list items (#72748) (#72780)
## Summary This PR updates the exception list entries schemas. - **Prior:** `entries` could be `undefined` or empty array on `ExceptionListItemSchema` - **Now:** `entries` is a required field that cannot be empty - there's really no use for an item without `entries` - **Prior:** `field` and `value` could be empty string in `EntryMatch` - **Now:** `field` and `value` can no longer be empty strings - **Prior:** `field` could be empty string and `value` could be empty array in `EntryMatchAny` - **Now:** `field` and `value` can no longer be empty string and array respectively - **Prior:** `field` and `list.id` could be empty string in `EntryList` - **Now:** `field` and `list.id` can no longer be empty strings - **Prior:** `field` could be empty string in `EntryExists` - **Now:** `field` can no longer be empty string - **Prior:** `field` could be empty string in `EntryNested` - **Now:** `field` can no longer be empty string - **Prior:** `entries` could be empty array in `EntryNested` - **Now:** `entries` can no longer be empty array
1 parent 2076a7e commit 715ff2a

File tree

52 files changed

+1481
-570
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1481
-570
lines changed

x-pack/plugins/lists/common/schemas/request/create_endpoint_list_item_schema.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('create_endpoint_list_item_schema', () => {
142142
expect(message.schema).toEqual({});
143143
});
144144

145-
test('it should validate an undefined for "entries" but return an array', () => {
145+
test('it should NOT validate an undefined for "entries"', () => {
146146
const inputPayload = getCreateEndpointListItemSchemaMock();
147147
const outputPayload = getCreateEndpointListItemSchemaMock();
148148
delete inputPayload.entries;
@@ -151,8 +151,10 @@ describe('create_endpoint_list_item_schema', () => {
151151
const checked = exactCheck(inputPayload, decoded);
152152
const message = pipe(checked, foldLeftRight);
153153
delete (message.schema as CreateEndpointListItemSchema).item_id;
154-
expect(getPaths(left(message.errors))).toEqual([]);
155-
expect(message.schema).toEqual(outputPayload);
154+
expect(getPaths(left(message.errors))).toEqual([
155+
'Invalid value "undefined" supplied to "entries"',
156+
]);
157+
expect(message.schema).toEqual({});
156158
});
157159

158160
test('it should validate an undefined for "tags" but return an array and generate a correct body not counting the auto generated uuid', () => {

x-pack/plugins/lists/common/schemas/request/create_endpoint_list_item_schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,15 @@ import {
2020
tags,
2121
} from '../common/schemas';
2222
import { RequiredKeepUndefined } from '../../types';
23-
import { CreateCommentsArray, DefaultCreateCommentsArray, DefaultEntryArray } from '../types';
23+
import { CreateCommentsArray, DefaultCreateCommentsArray, nonEmptyEntriesArray } from '../types';
2424
import { EntriesArray } from '../types/entries';
2525
import { DefaultUuid } from '../../siem_common_deps';
2626

2727
export const createEndpointListItemSchema = t.intersection([
2828
t.exact(
2929
t.type({
3030
description,
31+
entries: nonEmptyEntriesArray,
3132
name,
3233
type: exceptionListItemType,
3334
})
@@ -36,7 +37,6 @@ export const createEndpointListItemSchema = t.intersection([
3637
t.partial({
3738
_tags, // defaults to empty array if not set during decode
3839
comments: DefaultCreateCommentsArray, // defaults to empty array if not set during decode
39-
entries: DefaultEntryArray, // defaults to empty array if not set during decode
4040
item_id: DefaultUuid, // defaults to GUID (uuid v4) if not set during decode
4141
meta, // defaults to undefined if not set during decode
4242
tags, // defaults to empty array if not set during decode

x-pack/plugins/lists/common/schemas/request/create_exception_list_item_schema.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe('create_exception_list_item_schema', () => {
130130
expect(message.schema).toEqual({});
131131
});
132132

133-
test('it should validate an undefined for "entries" but return an array', () => {
133+
test('it should NOT validate an undefined for "entries"', () => {
134134
const inputPayload = getCreateExceptionListItemSchemaMock();
135135
const outputPayload = getCreateExceptionListItemSchemaMock();
136136
delete inputPayload.entries;
@@ -139,8 +139,10 @@ describe('create_exception_list_item_schema', () => {
139139
const checked = exactCheck(inputPayload, decoded);
140140
const message = pipe(checked, foldLeftRight);
141141
delete (message.schema as CreateExceptionListItemSchema).item_id;
142-
expect(getPaths(left(message.errors))).toEqual([]);
143-
expect(message.schema).toEqual(outputPayload);
142+
expect(getPaths(left(message.errors))).toEqual([
143+
'Invalid value "undefined" supplied to "entries"',
144+
]);
145+
expect(message.schema).toEqual({});
144146
});
145147

146148
test('it should validate an undefined for "namespace_type" but return enum "single" and generate a correct body not counting the auto generated uuid', () => {

x-pack/plugins/lists/common/schemas/request/create_exception_list_item_schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import { RequiredKeepUndefined } from '../../types';
2525
import {
2626
CreateCommentsArray,
2727
DefaultCreateCommentsArray,
28-
DefaultEntryArray,
2928
NamespaceType,
29+
nonEmptyEntriesArray,
3030
} from '../types';
3131
import { EntriesArray } from '../types/entries';
3232
import { DefaultUuid } from '../../siem_common_deps';
@@ -35,6 +35,7 @@ export const createExceptionListItemSchema = t.intersection([
3535
t.exact(
3636
t.type({
3737
description,
38+
entries: nonEmptyEntriesArray,
3839
list_id,
3940
name,
4041
type: exceptionListItemType,
@@ -44,7 +45,6 @@ export const createExceptionListItemSchema = t.intersection([
4445
t.partial({
4546
_tags, // defaults to empty array if not set during decode
4647
comments: DefaultCreateCommentsArray, // defaults to empty array if not set during decode
47-
entries: DefaultEntryArray, // defaults to empty array if not set during decode
4848
item_id: DefaultUuid, // defaults to GUID (uuid v4) if not set during decode
4949
meta, // defaults to undefined if not set during decode
5050
namespace_type, // defaults to 'single' if not set during decode

x-pack/plugins/lists/common/schemas/request/update_endpoint_list_item_schema.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,18 @@ describe('update_endpoint_list_item_schema', () => {
9797
expect(message.schema).toEqual(outputPayload);
9898
});
9999

100-
test('it should accept an undefined for "entries" but return an array', () => {
100+
test('it should NOT accept an undefined for "entries"', () => {
101101
const inputPayload = getUpdateEndpointListItemSchemaMock();
102102
const outputPayload = getUpdateEndpointListItemSchemaMock();
103103
delete inputPayload.entries;
104104
outputPayload.entries = [];
105105
const decoded = updateEndpointListItemSchema.decode(inputPayload);
106106
const checked = exactCheck(inputPayload, decoded);
107107
const message = pipe(checked, foldLeftRight);
108-
expect(getPaths(left(message.errors))).toEqual([]);
109-
expect(message.schema).toEqual(outputPayload);
108+
expect(getPaths(left(message.errors))).toEqual([
109+
'Invalid value "undefined" supplied to "entries"',
110+
]);
111+
expect(message.schema).toEqual({});
110112
});
111113

112114
test('it should accept an undefined for "tags" but return an array', () => {

x-pack/plugins/lists/common/schemas/request/update_endpoint_list_item_schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@ import {
2222
} from '../common/schemas';
2323
import { RequiredKeepUndefined } from '../../types';
2424
import {
25-
DefaultEntryArray,
2625
DefaultUpdateCommentsArray,
2726
EntriesArray,
2827
UpdateCommentsArray,
28+
nonEmptyEntriesArray,
2929
} from '../types';
3030

3131
export const updateEndpointListItemSchema = t.intersection([
3232
t.exact(
3333
t.type({
3434
description,
35+
entries: nonEmptyEntriesArray,
3536
name,
3637
type: exceptionListItemType,
3738
})
@@ -41,7 +42,6 @@ export const updateEndpointListItemSchema = t.intersection([
4142
_tags, // defaults to empty array if not set during decode
4243
_version, // defaults to undefined if not set during decode
4344
comments: DefaultUpdateCommentsArray, // defaults to empty array if not set during decode
44-
entries: DefaultEntryArray, // defaults to empty array if not set during decode
4545
id, // defaults to undefined if not set during decode
4646
item_id: t.union([t.string, t.undefined]),
4747
meta, // defaults to undefined if not set during decode

x-pack/plugins/lists/common/schemas/request/update_exception_list_item_schema.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,18 @@ describe('update_exception_list_item_schema', () => {
9797
expect(message.schema).toEqual(outputPayload);
9898
});
9999

100-
test('it should accept an undefined for "entries" but return an array', () => {
100+
test('it should NOT accept an undefined for "entries"', () => {
101101
const inputPayload = getUpdateExceptionListItemSchemaMock();
102102
const outputPayload = getUpdateExceptionListItemSchemaMock();
103103
delete inputPayload.entries;
104104
outputPayload.entries = [];
105105
const decoded = updateExceptionListItemSchema.decode(inputPayload);
106106
const checked = exactCheck(inputPayload, decoded);
107107
const message = pipe(checked, foldLeftRight);
108-
expect(getPaths(left(message.errors))).toEqual([]);
109-
expect(message.schema).toEqual(outputPayload);
108+
expect(getPaths(left(message.errors))).toEqual([
109+
'Invalid value "undefined" supplied to "entries"',
110+
]);
111+
expect(message.schema).toEqual({});
110112
});
111113

112114
test('it should accept an undefined for "namespace_type" but return enum "single"', () => {

x-pack/plugins/lists/common/schemas/request/update_exception_list_item_schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@ import {
2323
} from '../common/schemas';
2424
import { RequiredKeepUndefined } from '../../types';
2525
import {
26-
DefaultEntryArray,
2726
DefaultUpdateCommentsArray,
2827
EntriesArray,
2928
NamespaceType,
3029
UpdateCommentsArray,
30+
nonEmptyEntriesArray,
3131
} from '../types';
3232

3333
export const updateExceptionListItemSchema = t.intersection([
3434
t.exact(
3535
t.type({
3636
description,
37+
entries: nonEmptyEntriesArray,
3738
name,
3839
type: exceptionListItemType,
3940
})
@@ -43,7 +44,6 @@ export const updateExceptionListItemSchema = t.intersection([
4344
_tags, // defaults to empty array if not set during decode
4445
_version, // defaults to undefined if not set during decode
4546
comments: DefaultUpdateCommentsArray, // defaults to empty array if not set during decode
46-
entries: DefaultEntryArray, // defaults to empty array if not set during decode
4747
id, // defaults to undefined if not set during decode
4848
item_id: t.union([t.string, t.undefined]),
4949
meta, // defaults to undefined if not set during decode

x-pack/plugins/lists/common/schemas/types/default_entries_array.test.ts

Lines changed: 0 additions & 99 deletions
This file was deleted.

x-pack/plugins/lists/common/schemas/types/default_entries_array.ts

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)