{"record":{"id":"4238677509c1fb13","repo":"wuyouzhuguli/SpringAll","slug":"error-423867","errorCode":null,"errorMessage":"验证码不存在！","messagePattern":"验证码不存在！","errorType":"validation","errorClass":"ValidateCodeException","httpStatus":null,"severity":"warning","filePath":"60.Spring-Security-Logout/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/60.Spring-Security-Logout/src/main/java/cc/mrbird/validate/code/ValidateCodeFilter.java#L33-L65","documentation":"Thrown by ValidateCodeFilter.validateCode (Logout project) when the session has no ImageCode under SESSION_KEY_IMAGE_CODE. No captcha was generated/stored for the session, or the session was lost. Routed to AuthenticationFailureHandler.","triggerScenarios":"POST /login without a prior GET /code/image in the same JSESSIONID; session expired or not shared between the image fetch and the submit.","commonSituations":"Cookies blocked; load balancer without sticky sessions; image endpoint failed; redeploy cleared sessions.","solutions":["Load GET /code/image (stores ImageCode in session) before submitting /login.","Preserve JSESSIONID across both requests.","Verify createCode stores under SESSION_KEY_IMAGE_CODE.","Use sticky sessions or a shared session store behind a load balancer."],"exampleFix":"// before\n// submit /login without loading captcha\n\n// after\nfetch('/code/image').then(() => enableSubmit());","handlingStrategy":"validation","validationCode":"// client-side: load captcha image first\nfetch('/code/image').then(() => enableSubmit());","typeGuard":null,"tryCatchPattern":"// AuthenticationFailureHandler: treat missing session as '请先获取验证码'.","preventionTips":["Always fetch /code/image on page load.","Keep JSESSIONID consistent.","Use sticky sessions behind a load balancer."],"tags":["spring-security","captcha","session","validation","java"],"backgroundTag":null,"analyzedSha":"614d2578d9495acf53cc02f2dee9c6131cc5e51a","analyzedAt":"2026-08-14T04:40:03.488Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}