{"record":{"id":"b8387e2c9d32e277","repo":"wuyouzhuguli/SpringAll","slug":"error-b8387e","errorCode":null,"errorMessage":"验证码不存在！","messagePattern":"验证码不存在！","errorType":"exception","errorClass":"ValidateCodeException","httpStatus":null,"severity":"warning","filePath":"38.Spring-Security-SmsCode/src/main/java/cc/mrbird/validate/code/ValidateCodeFilter.java","lineNumber":51,"sourceCode":"            try {\n                validateCode(new ServletWebRequest(httpServletRequest));\n            } 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        ImageCode codeInSession = (ImageCode) sessionStrategy.getAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);\n        String codeInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), \"imageCode\");\n\n        if (StringUtils.isBlank(codeInRequest)) {\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(), codeInRequest)) {\n            throw new ValidateCodeException(\"验证码不正确！\");\n        }\n        sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);\n\n    }\n\n}\n","sourceCodeStart":33,"sourceCodeEnd":65,"githubUrl":"https://github.com/wuyouzhuguli/SpringAll/blob/614d2578d9495acf53cc02f2dee9c6131cc5e51a/38.Spring-Security-SmsCode/src/main/java/cc/mrbird/validate/code/ValidateCodeFilter.java#L33-L65","documentation":"ValidateCodeException from the image-captcha ValidateCodeFilter in module 38 when the session ImageCode is null (codeInSession == null). Indicates the captcha was never generated for this session or the session changed between generation and submit.","triggerScenarios":"POST to login with a non-empty imageCode but no ImageCode object in the session - /code/image was not called for this session, or a different session is submitting.","commonSituations":"JSESSIONID cookie blocked; captcha image endpoint never hit; session expired before submit; clustered deployment without shared sessions; the image captcha was superseded by the SMS flow in testing.","solutions":["Ensure GET /code/image is requested in the same session before login submit.","Verify the JSESSIONID cookie is present on both requests.","Use a shared session store (Redis) or sticky sessions in clusters.","Check session timeout is sufficient."],"exampleFix":"// before\nPOST /authentication/form  imageCode=ABCD   // no prior GET /code/image -> 不存在\n\n// after\nGET  /code/image           // populates session ImageCode\nPOST /authentication/form  imageCode=ABCD   // same JSESSIONID cookie","handlingStrategy":"retry","validationCode":"// ensure a captcha exists in this session before allowing submit\nfetch('/code/image', { credentials: 'same-origin' })\n  .then(() => enableLoginForm());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Fetch GET /code/image in the same session before login submit.","Send the JSESSIONID cookie on both requests.","Use sticky sessions or a shared session store in clusters."],"tags":["spring-security","captcha","session","validation"],"backgroundTag":null,"analyzedSha":"614d2578d9495acf53cc02f2dee9c6131cc5e51a","analyzedAt":"2026-08-14T04:40:03.488Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}