{"record":{"id":"ef0ac47344f6d3aa","repo":"wuyouzhuguli/SpringAll","slug":"error-ef0ac4","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":55,"sourceCode":"                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":37,"sourceCodeEnd":65,"githubUrl":"https://github.com/wuyouzhuguli/SpringAll/blob/614d2578d9495acf53cc02f2dee9c6131cc5e51a/38.Spring-Security-SmsCode/src/main/java/cc/mrbird/validate/code/ValidateCodeFilter.java#L37-L65","documentation":"ValidateCodeException from the image-captcha ValidateCodeFilter in module 38 when the session ImageCode is present but expired (isExpire() true). The filter removes the stale attribute, then throws, requiring a fresh captcha.","triggerScenarios":"POST to login with a present imageCode whose age exceeds the configured expireIn window.","commonSituations":"User lingered past the captcha TTL; expireIn configured too short; slow submit.","solutions":["Refresh the captcha image and resubmit promptly.","Increase expireIn (seconds) in the captcha-generation config.","Auto-refresh the image when it goes stale.","Show the code's remaining lifetime to the user."],"exampleFix":"// before\nimageCode.setExpireTime(LocalDateTime.now().plusSeconds(30));\n\n// after\nimageCode.setExpireTime(LocalDateTime.now().plusSeconds(180));","handlingStrategy":"retry","validationCode":"// client-side: refresh the captcha and track its lifetime\nfunction refreshCaptcha() {\n    document.getElementById('captchaImg').src = '/code/image?t=' + Date.now();\n    captchaGeneratedAt = Date.now();\n}\nif (Date.now() - captchaGeneratedAt > TTL_MS) refreshCaptcha();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Refresh the captcha image immediately before submitting if time has passed.","Set expireIn long enough for realistic input.","Show a countdown of the code's remaining lifetime."],"tags":["spring-security","captcha","expiry","validation"],"backgroundTag":null,"analyzedSha":"614d2578d9495acf53cc02f2dee9c6131cc5e51a","analyzedAt":"2026-08-14T04:40:03.488Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}