wuyouzhuguli/SpringAll · warning · ValidateCodeException
验证码不能为空!
Error message
验证码不能为空!
What it means
Thrown by SmsCodeFilter.validateCode (Logout project) when POST /login/mobile omits a blank/absent 'smsCode' parameter. First SMS-captcha gate. NOTE: line 46 of this filter also reads mobileInRequest from 'smsCode' (copy-paste bug), which does not change this particular blank-check.
Source
Thrown at 60.Spring-Security-Logout/src/main/java/cc/mrbird/validate/smscode/SmsCodeFilter.java:51
&& StringUtils.equalsIgnoreCase(httpServletRequest.getMethod(), "post")) {
try {
validateCode(new ServletWebRequest(httpServletRequest));
} catch (ValidateCodeException e) {
authenticationFailureHandler.onAuthenticationFailure(httpServletRequest, httpServletResponse, e);
return;
}
}
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
- Include a parameter named 'smsCode' in the POST /login/mobile body.
- Verify the front-end input name equals 'smsCode'.
- Collect the typed code from the user and append it.
- Confirm the filter only intercepts /login/mobile POST.
Example fix
// before
fetch('/login/mobile', { method:'POST', body:new URLSearchParams({mobile:'13800000000'}) });
// after
fetch('/login/mobile', { method:'POST', body:new URLSearchParams({mobile:'13800000000', smsCode:'123456'}) }); Defensive patterns
Strategy: validation
Validate before calling
// client-side: ensure smsCode present before submit
const code = form.get('smsCode');
if (!code || !code.trim()) { showError('请输入短信验证码'); return; } Try / catch
// SmsCodeFilter routes to AuthenticationFailureHandler; surface the message.
Prevention
- Standardize the smsCode field name.
- Disable submit until filled.
- Confirm the filter only intercepts /login/mobile.
When it happens
Trigger: A POST /login/mobile that omits smsCode, sends it empty, or names it differently. Filter runs only for '/login/mobile' POST.
Common situations: Missing smsCode field in the payload; field name mismatch; disabled input.
Related errors
AI-assisted analysis of wuyouzhuguli/SpringAll@614d2578d9 (2026-08-14).
Data as JSON: /api/errors/3e4032b23f2a814a.
Report an issue: GitHub.