{"record":{"id":"f9388b13809924b5","repo":"wuyouzhuguli/SpringAll","slug":"error-f9388b","errorCode":null,"errorMessage":"验证码不存在！","messagePattern":"验证码不存在！","errorType":"validation","errorClass":"ValidateCodeException","httpStatus":null,"severity":"error","filePath":"60.Spring-Security-Logout/src/main/java/cc/mrbird/validate/smscode/SmsCodeFilter.java","lineNumber":54,"sourceCode":"            } catch (ValidateCodeException e) {\n                authenticationFailureHandler.onAuthenticationFailure(httpServletRequest, httpServletResponse, e);\n                return;\n            }\n        }\n        filterChain.doFilter(httpServletRequest, httpServletResponse);\n    }\n\n    private void validateCode(ServletWebRequest servletWebRequest) throws ServletRequestBindingException {\n        String smsCodeInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), \"smsCode\");\n        String mobileInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), \"smsCode\");\n\n        SmsCode codeInSession = (SmsCode) sessionStrategy.getAttribute(servletWebRequest, ValidateController.SESSION_KEY_SMS_CODE + mobileInRequest);\n\n        if (StringUtils.isBlank(smsCodeInRequest)) {\n            throw new ValidateCodeException(\"验证码不能为空！\");\n        }\n        if (codeInSession == null) {\n            throw new ValidateCodeException(\"验证码不存在！\");\n        }\n        if (codeInSession.isExpire()) {\n            sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);\n            throw new ValidateCodeException(\"验证码已过期！\");\n        }\n        if (!StringUtils.equalsIgnoreCase(codeInSession.getCode(), smsCodeInRequest)) {\n            throw new ValidateCodeException(\"验证码不正确！\");\n        }\n        sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);\n\n    }\n}","sourceCodeStart":36,"sourceCodeEnd":66,"githubUrl":"https://github.com/wuyouzhuguli/SpringAll/blob/614d2578d9495acf53cc02f2dee9c6131cc5e51a/60.Spring-Security-Logout/src/main/java/cc/mrbird/validate/smscode/SmsCodeFilter.java#L36-L66","documentation":"Thrown by SmsCodeFilter.validateCode (Logout project) when no SmsCode is in session under SESSION_KEY_SMS_CODE + mobileInRequest. CRITICAL BUG on line 46: mobileInRequest is read from the 'smsCode' param instead of 'mobile', so the session key is built from the SMS code value and will almost never match the stored SESSION_KEY_SMS_CODE+mobile key. This error thus fires on nearly every valid SMS login.","triggerScenarios":"Any SMS login due to the line-46 param bug; or legitimately when /code/sms was not called for that mobile, or the session expired.","commonSituations":"The copy-paste bug dominates; also mobile param mismatch, missing GET /code/sms?mobile=..., session loss.","solutions":["Fix line 46 to read the 'mobile' parameter: ServletRequestUtils.getStringParameter(req, \"mobile\").","Call GET /code/sms?mobile=<number> before POST /login/mobile to store the code.","Ensure the submitted 'mobile' matches the one used to request the code.","Preserve JSESSIONID across both requests."],"exampleFix":"// before\nString mobileInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), \"smsCode\");\n\n// after\nString mobileInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), \"mobile\");","handlingStrategy":"validation","validationCode":"// client-side: request SMS with mobile, submit same mobile + smsCode\nawait fetch(`/code/sms?mobile=${encodeURIComponent(mobile)}`);","typeGuard":null,"tryCatchPattern":"// after fixing line 46, treat '不存在' as '请先获取验证码' in AuthenticationFailureHandler","preventionTips":["FIX line 46: read 'mobile' param, not 'smsCode'.","Always call /code/sms?mobile=... before /login/mobile.","Keep mobile identical across both calls.","Preserve JSESSIONID across the two requests."],"tags":["spring-security","sms","captcha","session","bug","validation","java"],"backgroundTag":null,"analyzedSha":"614d2578d9495acf53cc02f2dee9c6131cc5e51a","analyzedAt":"2026-08-14T04:40:03.488Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}