Skip to content

Commit e30a12f

Browse files
authored
[server] increase pagesize and fail when too much is requested. (#19817)
1 parent c465cde commit e30a12f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

components/public-api/typescript-common/src/public-api-pagination.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ const DEFAULT_PAGE_SIZE = 50;
1616
export function parsePagination(
1717
pagination: Partial<PaginationRequest> | undefined,
1818
defaultPageSize = DEFAULT_PAGE_SIZE,
19+
maxPageSize = MAX_PAGE_SIZE,
1920
): ParsedPagination {
2021
let pageSize = pagination?.pageSize ?? defaultPageSize;
2122
if (!Number.isInteger(pageSize)) {
2223
pageSize = defaultPageSize;
2324
}
2425
if (pageSize < 0) {
2526
pageSize = defaultPageSize;
26-
} else if (pageSize > MAX_PAGE_SIZE) {
27-
pageSize = MAX_PAGE_SIZE;
27+
} else if (pageSize > maxPageSize) {
28+
pageSize = maxPageSize;
2829
}
2930
let page = pagination?.page ?? 0;
3031
if (!Number.isInteger(page) || (page ?? 0) < 0) {

components/server/src/api/workspace-service-api.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
9090
}
9191

9292
async listWorkspaces(req: ListWorkspacesRequest, _: HandlerContext): Promise<ListWorkspacesResponse> {
93-
const { limit } = parsePagination(req.pagination, 50);
93+
if (req.pagination?.pageSize && req.pagination?.pageSize > 400) {
94+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "Pagesize must not exceed 400");
95+
}
96+
const { limit } = parsePagination(req.pagination, 50, 400);
9497
if (!uuidValidate(req.organizationId)) {
9598
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "organizationId is required");
9699
}
@@ -112,7 +115,10 @@ export class WorkspaceServiceAPI implements ServiceImpl<typeof WorkspaceServiceI
112115
req: ListWorkspaceSessionsRequest,
113116
_: HandlerContext,
114117
): Promise<ListWorkspaceSessionsResponse> {
115-
const page = parsePagination(req.pagination, 50);
118+
if (req.pagination?.pageSize && req.pagination?.pageSize > 400) {
119+
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "Pagesize must not exceed 400");
120+
}
121+
const page = parsePagination(req.pagination, 100, 400);
116122
if (!uuidValidate(req.organizationId)) {
117123
throw new ApplicationError(ErrorCodes.BAD_REQUEST, "organizationId is required");
118124
}

0 commit comments

Comments
 (0)