{"record":{"id":"8d565db5a39ba41a","repo":"gchq/CyberChef","slug":"this-name-length-cannot-exceed-this-maxlength","errorCode":null,"errorMessage":"${this.name} length cannot exceed ${this.maxLength}.","messagePattern":"(.+?) length cannot exceed (.+?)\\.","errorType":"validation","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/Ingredient.mjs","lineNumber":117,"sourceCode":"        }\n\n        if (isEmpty) {\n            let isAllowedOptionEmpty = false;\n            if (this.type === \"option\" && Array.isArray(this.defaultValue)) {\n                isAllowedOptionEmpty = this.defaultValue.includes(\"\");\n            } else if (this.type === \"argSelector\" && Array.isArray(this.defaultValue)) {\n                isAllowedOptionEmpty = this.defaultValue.some(opt => opt.name === \"\");\n            }\n            if (this.allowEmpty === false || ((this.type === \"option\" || this.type === \"argSelector\") && !isAllowedOptionEmpty)) {\n                throw new OperationError(`${this.name} cannot be empty.`);\n            }\n            return true;\n        }\n\n        // 2. maxLength check\n        if (typeof this.maxLength === \"number\" && checkVal !== null && checkVal !== undefined) {\n            if (typeof checkVal === \"string\" && checkVal.length > this.maxLength) {\n                throw new OperationError(`${this.name} length cannot exceed ${this.maxLength}.`);\n            }\n            if (Array.isArray(checkVal) && checkVal.length > this.maxLength) {\n                throw new OperationError(`${this.name} length cannot exceed ${this.maxLength}.`);\n            }\n            if (checkVal instanceof Uint8Array && checkVal.length > this.maxLength) {\n                throw new OperationError(`${this.name} length cannot exceed ${this.maxLength}.`);\n            }\n        }\n\n        // 3. number checks\n        if (this.type === \"number\") {\n            if (checkVal === null || checkVal === undefined || isNaN(checkVal)) {\n                throw new OperationError(`${this.name} must be a number.`);\n            }\n            if (this.integer && !Number.isInteger(checkVal)) {\n                throw new OperationError(`${this.name} must be an integer.`);\n            }\n            if (typeof this.min === \"number\" && checkVal < this.min) {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/Ingredient.mjs#L99-L135","documentation":"Thrown by Ingredient.validate() maxLength check when checkVal is a string whose .length exceeds the ingredient's configured maxLength. maxLength is an optional numeric cap declared in the ingredient config; when set, it bounds string, Array, and Uint8Array values. Only the string branch is reported here (line 117).","triggerScenarios":"A string ingredient with maxLength:N receives a string longer than N characters; e.g. a key/delimiter ingredient capped at 32 chars gets a 64-char value from the recipe.","commonSituations":"User pastes a long key/salt/IV into a capped field; a recipe generated programmatically passes an oversized string; a delimiter or seed field overflow.","solutions":["Truncate or shorten the input string to be within maxLength.","If the cap is wrong for your use case, raise maxLength in the ingredient config (and re-verify the operation can handle larger input).","Validate length client-side before assigning ingValues."],"exampleFix":"// before\nop.ingValues = ['abcdefghijklmnopqrstuvwxyz0123456789']; // 36 chars, maxLength 32\n\n// after\nop.ingValues = ['abcdefghijklmnopqrstuvwxyz012345']; // <= 32","handlingStrategy":"validation","validationCode":"if (typeof val === 'string' && maxLength != null && val.length > maxLength) {\n  throw new Error(`string length ${val.length} > maxLength ${maxLength}`);\n}","typeGuard":"function fitsMaxLength(v, max): v is string { return typeof v === 'string' && (max == null || v.length <= max); }","tryCatchPattern":"try { op.ingValues = [val]; } catch (e) { if (/length cannot exceed/.test(e.message)) { /* truncate */ } }","preventionTips":["Check string length against ingredient.maxLength before assigning.","Truncate oversized user input on the client side before building the recipe.","Raise maxLength in config only if the operation truly handles longer input."],"tags":["ingredient","validation","length-limit","string","operationerror"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}