wuyouzhuguli/SpringAll · warning · ValidateCodeException
验证码不能为空!
Error message
验证码不能为空!
What it means
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.
Source
Thrown at 60.Spring-Security-Logout/src/main/java/cc/mrbird/validate/code/ValidateCodeFilter.java:48
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
if (StringUtils.equalsIgnoreCase("/login", httpServletRequest.getRequestURI())
&& 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 {
ImageCode codeInSession = (ImageCode) sessionStrategy.getAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);
String codeInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), "imageCode");
if (StringUtils.isBlank(codeInRequest)) {
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(), codeInRequest)) {
throw new ValidateCodeException("验证码不正确!");
}
sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);
}
}
View on GitHub (pinned to 614d2578d9)
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.
Example fix
// before
formData.append("captcha", userTypedCode);
// after
formData.append("imageCode", userTypedCode); Defensive patterns
Strategy: validation
Validate before calling
// client-side: ensure imageCode present before submit
const code = form.get('imageCode');
if (!code || !code.trim()) { showError('请输入验证码'); return; } Try / catch
// AuthenticationFailureHandler surfaces the message; do not swallow.
Prevention
- Standardize the imageCode field name.
- Disable submit until filled.
- Confirm the filter only intercepts /login.
When it happens
Trigger: 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.
Common situations: Front-end field named differently; AJAX login missing the captcha; field disabled/hidden.
Related errors
AI-assisted analysis of wuyouzhuguli/SpringAll@614d2578d9 (2026-08-14).
Data as JSON: /api/errors/05e75125150a0de2.
Report an issue: GitHub.