{"record":{"id":"2359df7e642d7700","repo":"apereo/cas","slug":"cookie-name-is-undefined","errorCode":null,"errorMessage":"Cookie name is undefined","messagePattern":"Cookie name is undefined","errorType":"exception","errorClass":"InvalidCookieException","httpStatus":null,"severity":"error","filePath":"core/cas-server-core-cookie-api/src/main/java/org/apereo/cas/web/support/gen/CookieRetrievingCookieGenerator.java","lineNumber":107,"sourceCode":"        } else {\n            LOGGER.trace(\"Creating CAS cookie [{}]\", getCookieName());\n            cookie.setMaxAge(cookieGenerationContext.getMaxAge());\n        }\n        cookie.setSecure(cookieGenerationContext.isSecure());\n        cookie.setHttpOnly(cookieGenerationContext.isHttpOnly());\n        return addCookieHeaderToResponse(cookie, request, response);\n    }\n\n    @Override\n    public Cookie addCookie(final HttpServletRequest request, final HttpServletResponse response, final String cookieValue) {\n        return addCookie(request, response, false, cookieValue);\n    }\n\n    @Override\n    public @Nullable String retrieveCookieValue(final HttpServletRequest request) {\n        try {\n            if (StringUtils.isBlank(getCookieName())) {\n                throw new InvalidCookieException(\"Cookie name is undefined\");\n            }\n            var cookie = org.springframework.web.util.WebUtils.getCookie(request, Objects.requireNonNull(getCookieName()));\n            if (cookie == null) {\n                val cookieValue = request.getHeader(getCookieName());\n                if (StringUtils.isNotBlank(cookieValue)) {\n                    LOGGER.trace(\"Found cookie [{}] under header name [{}]\", cookieValue, getCookieName());\n                    cookie = createCookie(cookieValue);\n                }\n            }\n            if (cookie == null) {\n                val cookieValue = request.getParameter(getCookieName());\n                if (StringUtils.isNotBlank(cookieValue)) {\n                    LOGGER.trace(\"Found cookie [{}] under request parameter name [{}]\", cookieValue, getCookieName());\n                    cookie = createCookie(cookieValue);\n                }\n            }\n            return Optional.ofNullable(cookie)\n                .map(ck -> casCookieValueManager.obtainCookieValue(ck, request))","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/core/cas-server-core-cookie-api/src/main/java/org/apereo/cas/web/support/gen/CookieRetrievingCookieGenerator.java#L89-L125","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set the cookie name explicitly, e.g. cas.tgc.name=CASTGC (or the matching property for the cookie in question).","In custom code, always call setCookieName(...) before using the generator.","Check application properties/YAML for an empty value like 'name:' or 'name=' and supply a real name.","If a bean override removed the default, restore the default name or define it in your @Bean."],"exampleFix":"// before (custom bean)\nval gen = CookieRetrievingCookieGenerator(); gen.setCookieSecret(\"s3cret\")\n// after\ngen.setCookieSecret(\"s3cret\"); gen.setCookieName(\"CASTGC\")","handlingStrategy":"validation","validationCode":"assert StringUtils.isNotBlank(cookieGenerator.getCookieName()) : \"cookie name must be set\"","typeGuard":null,"tryCatchPattern":"try {\n  value = generator.retrieveCookieValue(request);\n} catch (InvalidCookieException e) {\n  LOGGER.warn(\"Cookie name undefined\", e);\n  value = null;\n}","preventionTips":["Set cookie names for all cookie beans in config, never rely on defaults silently","Add unit tests constructing cookie generators with full property binding","Fail fast at startup if required cookie name properties are blank"],"tags":["cookie","configuration","web"],"backgroundTag":"missing-config-value","analyzedSha":"e7288fc434b4f4505b8452e1a57e8fb3111bb863","analyzedAt":"2026-09-08T15:39:16.015Z","contentChangedAt":"2026-09-08T15:39:16.015Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}