{"record":{"id":"80bbf6bc7b3a8301","repo":"SonarSource/sonarqube","slug":"page-size-must-not-exceed-s","errorCode":null,"errorMessage":"Page size must not exceed %s","messagePattern":"Page size must not exceed (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":400,"severity":"error","filePath":"server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java","lineNumber":126,"sourceCode":"        .setQuery(wsRequest.param(Param.TEXT_QUERY))\n        .setPage(wsRequest.paramAsInt(Param.PAGE))\n        .setPageSize(wsRequest.paramAsInt(Param.PAGE_SIZE));\n\n      validatePaginationParameters(request);\n      checkGlobalAdmin(userSession);\n\n      SearchTemplatesWsResponse searchTemplatesWsResponse = buildResponse(load(dbSession, request));\n      writeProtobuf(searchTemplatesWsResponse, wsRequest, wsResponse);\n    }\n  }\n\n  private static void validatePaginationParameters(SearchTemplatesRequest request) {\n    if (request.getPageSize() != null) {\n      if (request.getPageSize() < 0) {\n        throw new IllegalArgumentException(\"Page size must be >= 0\");\n      }\n      if (request.getPageSize() > RESULTS_MAX_SIZE) {\n        throw new IllegalArgumentException(\"Page size must not exceed \" + RESULTS_MAX_SIZE);\n      }\n    }\n  }\n\n  private static void buildDefaultTemplatesResponse(SearchTemplatesWsResponse.Builder response, SearchTemplatesData data) {\n    TemplateIdQualifier.Builder templateUuidQualifierBuilder = TemplateIdQualifier.newBuilder();\n\n    ResolvedDefaultTemplates resolvedDefaultTemplates = data.defaultTemplates();\n    response.addDefaultTemplates(templateUuidQualifierBuilder\n      .setQualifier(ComponentQualifiers.PROJECT)\n      .setTemplateId(resolvedDefaultTemplates.getProject()));\n\n    resolvedDefaultTemplates.getApplication()\n      .ifPresent(viewDefaultTemplate -> response.addDefaultTemplates(\n        templateUuidQualifierBuilder\n          .clear()\n          .setQualifier(ComponentQualifiers.APP)\n          .setTemplateId(viewDefaultTemplate)));","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/SonarSource/sonarqube/blob/184c821202192afc1c599fc912d0889b69fffa53/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/ws/template/SearchTemplatesAction.java#L108-L144","documentation":"Validation guard in SearchTemplatesAction.validatePaginationParameters: the permission templates search WS call received a 'ps' (page size) parameter larger than the maximum allowed page size (the %s is the configured MAX_PAGE_SIZE). It fires before authorization and DB access, so callers must reduce the requested page size; nothing is wrong on the server side.","triggerScenarios":"GET api/permissions/search_templates with ps greater than RESULTS_MAX_SIZE (e.g. ps=1000 when max is 100); clients that always send a large default page size.","commonSituations":"Bulk-export scripts requesting everything in one call; SDK defaults larger than server maximums; confusion between server-side max page size limits across SonarQube endpoints.","solutions":["Reduce ps to at most RESULTS_MAX_SIZE (use ps=100 or less)","Implement proper pagination using the paging.nextPageToken/total in the response instead of one huge page","Clamp the page size client-side before the request"],"exampleFix":"// before\nawait searchTemplates({ ps: 1000 });\n\n// after\nconst MAX_PS = 100;\nawait searchTemplates({ ps: Math.min(requestedPs, MAX_PS) });","handlingStrategy":"validation","validationCode":"const MAX_PS = 100;\nif (ps > MAX_PS) ps = MAX_PS;\nawait searchTemplates({ ps });","typeGuard":"function isWithinMaxPageSize(ps, max) { return ps == null || (Number.isInteger(ps) && ps <= max); }","tryCatchPattern":"try { await searchTemplates({ ps }); } catch (e) { if (e.message.includes('must not exceed')) { return searchTemplates({ ps: 100 }); } throw e; }","preventionTips":["Clamp ps to the server maximum before requesting","Paginate with repeated smaller pages instead of one large page","Do not assume one endpoint's max page size applies to all endpoints"],"tags":["webapi","permissions","pagination","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"184c821202192afc1c599fc912d0889b69fffa53","analyzedAt":"2026-09-09T12:23:51.573Z","contentChangedAt":"2026-09-09T12:23:51.573Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}