{"record":{"id":"6a781f2284cbc41d","repo":"paascloud/paascloud-master","slug":"deviceid","errorCode":null,"errorMessage":"请在请求头中携带deviceId参数","messagePattern":"请在请求头中携带deviceId参数","errorType":"validation","errorClass":"ValidateCodeException","httpStatus":400,"severity":"error","filePath":"paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/validate/code/impl/RedisValidateCodeRepository.java","lineNumber":90,"sourceCode":"\t\t}\n\t\treturn (ValidateCode) value;\n\t}\n\n\t/**\n\t * Remove.\n\t *\n\t * @param request the request\n\t * @param type    the type\n\t */\n\t@Override\n\tpublic void remove(ServletWebRequest request, ValidateCodeType type) {\n\t\tredisTemplate.delete(buildKey(request, type));\n\t}\n\n\tprivate String buildKey(ServletWebRequest request, ValidateCodeType type) {\n\t\tString deviceId = request.getHeader(\"deviceId\");\n\t\tif (StringUtils.isBlank(deviceId)) {\n\t\t\tthrow new ValidateCodeException(\"请在请求头中携带deviceId参数\");\n\t\t}\n\t\treturn \"code:\" + type.toString().toLowerCase() + \":\" + deviceId;\n\t}\n\n}\n","sourceCodeStart":72,"sourceCodeEnd":96,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-common/paascloud-security-core/src/main/java/com/paascloud/security/core/validate/code/impl/RedisValidateCodeRepository.java#L72-L96","documentation":"RedisValidateCodeRepository.buildKey constructs the Redis key 'code:<type>:<deviceId>' from the request's deviceId header. Codes are stored per device; if the deviceId header is missing or blank, ValidateCodeException '请在请求头中携带deviceId参数' is thrown for any get/put/remove operation.","triggerScenarios":"Calling the validate-code generate or check endpoints without an HTTP header named 'deviceId', or sending it empty — raised from buildKey invoked by key/value/remove.","commonSituations":"Native app or browser frontend forgot to attach the deviceId header; a gateway stripped custom headers; backend test (Postman/curl) omitted the header; after migrating from session-based storage the client wasn't updated.","solutions":["Add a unique, stable 'deviceId' header to every validate-code request (generate and check)","Generate a UUID on the client at install/first-visit and persist it","Check gateways/nginx aren't filtering the custom header","For browser apps, note cookies/session won't help here — the header is required"],"exampleFix":"// before\nfetch('/code/sms', { method: 'POST' });\n// after\nfetch('/code/sms', { method: 'POST', headers: { deviceId: getOrCreateDeviceId() } });","handlingStrategy":"validation","validationCode":"const deviceId = localStorage.deviceId || (localStorage.deviceId = crypto.randomUUID());\nif (!deviceId) throw new Error('deviceId missing');","typeGuard":"function hasDeviceId(headers) { return typeof headers.deviceId === 'string' && headers.deviceId.trim().length > 0; }","tryCatchPattern":"try { await requestSmsCode(); } catch (ValidateCodeException e) { if (e.getMessage().contains(\"deviceId\")) { regenerateDeviceIdAndRetry(); } }","preventionTips":["Attach a persisted deviceId header on every request","Persist the UUID in localStorage/app storage","Verify proxies do not strip custom headers"],"tags":["validation-code","missing-header","redis"],"backgroundTag":"missing-required-argument","analyzedSha":"781281a9503332ed3cef44ea618349d14230a127","analyzedAt":"2026-09-10T10:59:02.070Z","contentChangedAt":"2026-09-10T10:59:02.070Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}