{"record":{"id":"05e75125150a0de2","repo":"wuyouzhuguli/SpringAll","slug":"error-05e751","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":48,"sourceCode":"    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {\n        if (StringUtils.equalsIgnoreCase(\"/login\", httpServletRequest.getRequestURI())\n                && StringUtils.equalsIgnoreCase(httpServletRequest.getMethod(), \"post\")) {\n            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":30,"sourceCodeEnd":65,"githubUrl":"https://github.com/wuyouzhuguli/SpringAll/blob/614d2578d9495acf53cc02f2dee9c6131cc5e51a/60.Spring-Security-Logout/src/main/java/cc/mrbird/validate/code/ValidateCodeFilter.java#L30-L65","documentation":"Thrown by ValidateCodeFilter.validateCode in the Logout project when a POST /login is missing a blank/absent 'imageCode' request parameter. Identical logic to the SessionManager project: a ValidateCodeException from the first captcha gate, routed to AuthenticationFailureHandler.","triggerScenarios":"A POST /login form submission that omits imageCode, sends it empty, or uses a different field name. Filter runs only for requestURI '/login' and POST.","commonSituations":"Front-end field named differently; AJAX login missing the captcha; field disabled/hidden.","solutions":["Include a parameter named 'imageCode' in the POST /login body.","Verify the front-end input name equals 'imageCode'.","Ensure the filter only intercepts /login POST.","Gate validateCode on param presence if captcha is optional on some flows."],"exampleFix":"// before\nformData.append(\"captcha\", userTypedCode);\n\n// after\nformData.append(\"imageCode\", userTypedCode);","handlingStrategy":"validation","validationCode":"// client-side: ensure imageCode present before submit\nconst code = form.get('imageCode');\nif (!code || !code.trim()) { showError('请输入验证码'); return; }","typeGuard":null,"tryCatchPattern":"// AuthenticationFailureHandler surfaces the message; do not swallow.","preventionTips":["Standardize the imageCode field name.","Disable submit until filled.","Confirm the filter only intercepts /login."],"tags":["spring-security","captcha","validation","filter","java"],"backgroundTag":null,"analyzedSha":"614d2578d9495acf53cc02f2dee9c6131cc5e51a","analyzedAt":"2026-08-14T04:40:03.488Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}