wuyouzhuguli/SpringAll · warning · ValidateCodeException
验证码已过期!
Error message
验证码已过期!
What it means
Thrown by SmsCodeFilter.validateCode (Logout project) when the session SmsCode is expired (isExpire() true, default 60s). BUG: line 57 removeAttribute clears SESSION_KEY_IMAGE_CODE instead of the SMS key, so it fails to remove the actual expired SMS entry and clears an unrelated image-captcha entry.
Source
Thrown at 60.Spring-Security-Logout/src/main/java/cc/mrbird/validate/smscode/SmsCodeFilter.java:58
}
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
private void validateCode(ServletWebRequest servletWebRequest) throws ServletRequestBindingException {
String smsCodeInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), "smsCode");
String mobileInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), "smsCode");
SmsCode codeInSession = (SmsCode) sessionStrategy.getAttribute(servletWebRequest, ValidateController.SESSION_KEY_SMS_CODE + mobileInRequest);
if (StringUtils.isBlank(smsCodeInRequest)) {
throw new ValidateCodeException("验证码不能为空!");
}
if (codeInSession == null) {
throw new ValidateCodeException("验证码不存在!");
}
if (codeInSession.isExpire()) {
sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);
throw new ValidateCodeException("验证码已过期!");
}
if (!StringUtils.equalsIgnoreCase(codeInSession.getCode(), smsCodeInRequest)) {
throw new ValidateCodeException("验证码不正确!");
}
sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);
}
}View on GitHub (pinned to 614d2578d9)
Solutions
- Submit the SMS code within the 60-second window.
- Re-request the code via GET /code/sms?mobile=<number> and resubmit.
- Raise the SmsCode TTL in createSmsCode.
- Fix line 57 to remove SESSION_KEY_SMS_CODE + mobileInRequest.
Example fix
// before return new SmsCode(code, 60); // after return new SmsCode(code, 180);
Defensive patterns
Strategy: validation
Validate before calling
// client-side countdown for the 60s SMS TTL
let ttl = 60;
if (--ttl <= 0) { await requestSms(mobile); ttl = 60; } Try / catch
// AuthenticationFailureHandler: on '已过期', re-request SMS and retry.
Prevention
- Submit within the 60s window.
- Re-request the code when it expires.
- FIX line 57 removeAttribute to the SMS key.
- Raise TTL if users need more time.
When it happens
Trigger: More than 60s elapsed between GET /code/sms and POST /login/mobile; stale SMS code submitted.
Common situations: Long entry time; short TTL; stale entry lingers because the wrong key is removed.
Related errors
AI-assisted analysis of wuyouzhuguli/SpringAll@614d2578d9 (2026-08-14).
Data as JSON: /api/errors/8f8c3da7826e6f0f.
Report an issue: GitHub.