{"record":{"id":"0ad5be0648ea0604","repo":"dromara/Sa-Token","slug":"32","errorCode":null,"errorMessage":"裁剪前缀长度必须小于 32 位","messagePattern":"裁剪前缀长度必须小于 32 位","errorType":"exception","errorClass":"SaTokenException","httpStatus":null,"severity":"error","filePath":"sa-token-core/src/main/java/cn/dev33/satoken/temp/SaTempTemplate.java","lineNumber":356,"sourceCode":"\t\tString key = splicingTempTokenSaveKey(token);\n\t\tSaManager.getSaTokenDao().deleteObject(key);\n\t}\n\tprotected long _getTimeout(String token) {\n\t\tString key = splicingTempTokenSaveKey(token);\n\t\treturn SaManager.getSaTokenDao().getObjectTimeout(key);\n\t}\n\n\n\n\t// -------- 其它\n\n\t/**\n\t * 检查裁剪前缀长度\n\t * @param cutPrefix /\n\t */\n\tprotected static void checkCutPrefixLength(String cutPrefix) {\n\t\tif(cutPrefix.length() >= 32) {\n\t\t\tthrow new SaTokenException(\"裁剪前缀长度必须小于 32 位\");\n\t\t}\n\t}\n\n\t/**\n\t * 获取：在存储临时 token 数据时，应该使用的 key\n\t * @param token token值\n\t * @return key\n\t */\n\tpublic String splicingTempTokenSaveKey(String token) {\n\t\treturn SaManager.getConfig().getTokenName() + \":\" + namespace + \":\" + token;\n\t}\n\n\t/**\n\t * @return jwt秘钥 (只有集成 sa-token-temp-jwt 模块时此参数才会生效)\n\t */\n\tpublic String getJwtSecretKey() {\n\t\treturn null;\n\t}","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/dromara/Sa-Token/blob/ac2c7f6e94a78573cf0bcb932dd8b04e68fad189/sa-token-core/src/main/java/cn/dev33/satoken/temp/SaTempTemplate.java#L338-L374","documentation":"checkCutPrefixLength is called before creating a temporary token display string with a cut (recognition) prefix; it throws SaTokenException when the prefix is 32 characters or longer. The limit reserves room in the token string: the random token body plus prefix must fit fixed-length formats, so a 32+ char prefix would overflow them.","triggerScenarios":"Calling SaTempTemplate.createToken(value, cutPrefix) (or a related API that funnels through checkCutPrefixLength) with a cutPrefix of length >= 32, e.g. a long business identifier used verbatim as the prefix.","commonSituations":"Using the full business key ('order-payment-channel-2024-...') as the cut prefix instead of a short marker; switching a previously short prefix to a namespaced one that crosses 31 chars.","solutions":["Shorten the prefix to < 32 characters (aim for a short stable marker like 'odr:')","Move long identifying data into the value parameter, not the cutPrefix","Add a startup/unit assertion on your prefix constant so regressions are caught before runtime"],"exampleFix":"// before\nsaTempTemplate.createToken(value, \"order-payment-channel-2024-internal\"); // 37 chars -> throws\n\n// after\nsaTempTemplate.createToken(value, \"opc:\");","handlingStrategy":"validation","validationCode":"if (cutPrefix != null && cutPrefix.length() < 32) {\n    saTempTemplate.createToken(value, cutPrefix);\n} else {\n    // shorten prefix: derive a short stable marker instead of the full business id\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep cut prefixes short and constant (e.g. 'tmp:', 'odr:')","Put long identifiers in the value argument, not the prefix","Unit-test your prefix constants against the 32-char bound"],"tags":["sa-token","temp-token","validation","input-length"],"backgroundTag":null,"analyzedSha":"ac2c7f6e94a78573cf0bcb932dd8b04e68fad189","analyzedAt":"2026-08-14T14:36:10.271Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}