apereo/cas · error · InvalidCookieException

Cookie name is undefined

Error message

Cookie name is undefined

What it means

CookieRetrievingCookieGenerator.retrieveCookieValue reads the CAS cookie from the request, but first validates that a cookie name is configured. If getCookieName() is blank (the generator was never given a name or it was set to an empty string), it throws InvalidCookieException('Cookie name is undefined') instead of searching for an unnamed cookie.

Solutions

  1. Set the cookie name explicitly, e.g. cas.tgc.name=CASTGC (or the matching property for the cookie in question).
  2. In custom code, always call setCookieName(...) before using the generator.
  3. Check application properties/YAML for an empty value like 'name:' or 'name=' and supply a real name.
  4. If a bean override removed the default, restore the default name or define it in your @Bean.

Example fix

// before (custom bean)
val gen = CookieRetrievingCookieGenerator(); gen.setCookieSecret("s3cret")
// after
gen.setCookieSecret("s3cret"); gen.setCookieName("CASTGC")
Defensive patterns

Strategy: validation

Validate before calling

assert StringUtils.isNotBlank(cookieGenerator.getCookieName()) : "cookie name must be set"

Try / catch

try {
  value = generator.retrieveCookieValue(request);
} catch (InvalidCookieException e) {
  LOGGER.warn("Cookie name undefined", e);
  value = null;
}

Prevention

When it happens

Trigger: Any call to retrieveCookieValue(request) on a cookie generator whose cookie name property (e.g. cas.tgc.name, cas.warning-cookie.name, or a custom bean's setCookieName) is null/empty.

Common situations: Custom cookie bean created without calling setCookieName; config property for the cookie name bound to an empty string (e.g. cas.tgc.name= with no value); bean constructed programmatically in a test or integration missing required setters; configuration binding change after upgrade leaving the property unset.

Understand the failure class

Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.

Related errors


AI-assisted analysis of apereo/cas@e7288fc434 (2026-09-08). Data as JSON: /api/errors/2359df7e642d7700. Report an issue: GitHub.

Appendix: source

Thrown at core/cas-server-core-cookie-api/src/main/java/org/apereo/cas/web/support/gen/CookieRetrievingCookieGenerator.java:107

        } else {
            LOGGER.trace("Creating CAS cookie [{}]", getCookieName());
            cookie.setMaxAge(cookieGenerationContext.getMaxAge());
        }
        cookie.setSecure(cookieGenerationContext.isSecure());
        cookie.setHttpOnly(cookieGenerationContext.isHttpOnly());
        return addCookieHeaderToResponse(cookie, request, response);
    }

    @Override
    public Cookie addCookie(final HttpServletRequest request, final HttpServletResponse response, final String cookieValue) {
        return addCookie(request, response, false, cookieValue);
    }

    @Override
    public @Nullable String retrieveCookieValue(final HttpServletRequest request) {
        try {
            if (StringUtils.isBlank(getCookieName())) {
                throw new InvalidCookieException("Cookie name is undefined");
            }
            var cookie = org.springframework.web.util.WebUtils.getCookie(request, Objects.requireNonNull(getCookieName()));
            if (cookie == null) {
                val cookieValue = request.getHeader(getCookieName());
                if (StringUtils.isNotBlank(cookieValue)) {
                    LOGGER.trace("Found cookie [{}] under header name [{}]", cookieValue, getCookieName());
                    cookie = createCookie(cookieValue);
                }
            }
            if (cookie == null) {
                val cookieValue = request.getParameter(getCookieName());
                if (StringUtils.isNotBlank(cookieValue)) {
                    LOGGER.trace("Found cookie [{}] under request parameter name [{}]", cookieValue, getCookieName());
                    cookie = createCookie(cookieValue);
                }
            }
            return Optional.ofNullable(cookie)
                .map(ck -> casCookieValueManager.obtainCookieValue(ck, request))

View on GitHub (pinned to e7288fc434)