Skip to content

Commit 8cfa0cf

Browse files
authored
Add data states limit (#346)
1 parent f2d99c2 commit 8cfa0cf

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

src/components/zod/custom-types/limited-object.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ export const limitedObject = ({limit}: {limit: number}) =>
1010
},
1111
{
1212
message: `Object can't contain more than ${limit} characters`,
13+
params: {code: 'OBJECT_SIZE_LIMIT_EXCEEDED'},
1314
},
1415
);

src/const/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export const ENCODED_ID_LENGTH = 13;
153153
export const MAX_META_OBJECT_SYMBOLS = 2000;
154154
export const MAX_UNVERSIONED_DATA_OBJECT_SYMBOLS = 5000;
155155
export const MAX_BRANDING_OBJECT_SYMBOLS = 15000;
156+
export const MAX_STATE_DATA_OBJECT_SYMBOLS = 50000;
156157

157158
export const AJV_PATTERN_KEYS_NOT_OBJECT = {
158159
'.*': {

src/controllers/states/create-state.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {AppRouteHandler} from '@gravity-ui/expresskit';
22

33
import {ApiTag} from '../../components/api-docs';
44
import {makeReqParser, z, zc} from '../../components/zod';
5-
import {CONTENT_TYPE_JSON} from '../../const';
5+
import {CONTENT_TYPE_JSON, MAX_STATE_DATA_OBJECT_SYMBOLS} from '../../const';
66
import {createState} from '../../services/new/state';
77

88
import {stateHashModel} from './response-models';
@@ -12,7 +12,9 @@ const requestSchema = {
1212
entryId: zc.encodedId(),
1313
}),
1414
body: z.object({
15-
data: z.record(z.string(), z.unknown()),
15+
data: zc.limitedObject({
16+
limit: MAX_STATE_DATA_OBJECT_SYMBOLS,
17+
}),
1618
}),
1719
};
1820

0 commit comments

Comments
 (0)