{"record":{"id":"6b26bcc34dc61279","repo":"alibaba/nacos","slug":"invalid-tenant","errorCode":null,"errorMessage":"invalid tenant","messagePattern":"invalid tenant","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"config/src/main/java/com/alibaba/nacos/config/server/utils/ParamUtils.java","lineNumber":234,"sourceCode":"                throw new NacosApiException(HttpStatus.BAD_REQUEST.value(),\n                    ErrorCode.PARAMETER_VALIDATE_ERROR,\n                    \"invalid tag : \" + tag);\n            }\n            if (tag.length() > TAG_MAX_LEN) {\n                throw new NacosApiException(HttpStatus.BAD_REQUEST.value(),\n                    ErrorCode.PARAMETER_VALIDATE_ERROR,\n                    \"too long tag, over 16\");\n            }\n        }\n    }\n    \n    /**\n     * Check the tenant for [v1].\n     */\n    public static void checkTenant(String tenant) {\n        if (StringUtils.isNotBlank(tenant)) {\n            if (!isValid(tenant.trim())) {\n                throw new IllegalArgumentException(\"invalid tenant\");\n            }\n            if (tenant.length() > TENANT_MAX_LEN) {\n                throw new IllegalArgumentException(\"too long tenant, over 128\");\n            }\n        }\n    }\n    \n    /**\n     * Check the namespaceId for [v2].\n     */\n    public static void checkTenantV2(String namespaceId) throws NacosApiException {\n        if (StringUtils.isNotBlank(namespaceId)) {\n            if (!isValid(namespaceId.trim())) {\n                throw new NacosApiException(HttpStatus.BAD_REQUEST.value(),\n                    ErrorCode.PARAMETER_VALIDATE_ERROR,\n                    \"invalid namespaceId\");\n            }\n            if (namespaceId.length() > TENANT_MAX_LEN) {","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/config/src/main/java/com/alibaba/nacos/config/server/utils/ParamUtils.java#L216-L252","documentation":"Thrown by the v1 ParamUtils.checkTenant(String tenant) as an IllegalArgumentException (unchecked, no error code/HTTP status) when tenant.trim() fails isValid(): only letters, digits, and '_' '-' '.' ':' are allowed. 'tenant' is the legacy name for namespaceId and is used as a storage partition key.","triggerScenarios":"A v1 config operation passing a non-blank tenant containing spaces or special characters (e.g. 'prod env', 'tenant/1').","commonSituations":"Using a descriptive namespace name with spaces as tenant, embedding slashes, or copying a tenant id from a URL with encoded characters.","solutions":["Sanitize the tenant to the allowed charset [A-Za-z0-9_.-:].","Prefer the v2 API (checkTenantV2) for a structured NacosApiException.","Use the namespace's generated id rather than its display name as the tenant value."],"exampleFix":"// before\nParamUtils.checkTenant(\"prod environment\");\n\n// after\nParamUtils.checkTenant(\"prod-env\"); // whitelist-safe","handlingStrategy":"validation","validationCode":"private static final Pattern TENANT = Pattern.compile(\"^[A-Za-z0-9_.\\\\-:]+$\");\nboolean validTenant(String tenant) {\n    return tenant == null || tenant.isBlank() || (TENANT.matcher(tenant.trim()).matches() && tenant.length() <= 128);\n}","typeGuard":null,"tryCatchPattern":"try {\n    ParamUtils.checkTenant(tenant);\n} catch (IllegalArgumentException e) {\n    handleInvalidTenant(e.getMessage());\n}","preventionTips":["Use the namespace's generated id, not its display name, as tenant.","Prefer the v2 API (checkTenantV2) for structured errors.","Sanitize tenant to the whitelist charset."],"tags":["config","validation","tenant","namespace","v1","illegal-argument"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}