Conversation
CookieUtils.newCookie set Secure from com.iplanet.am.cookie.secure but left HttpOnly to addCookieToResponse, which applied it by reflection - a Servlet 2.5 leftover - so a cookie handed straight to response.addCookie, as every logout deletion is, went out without it. Both flags are now set on the cookie as it is created, from the same properties, and addCookieToResponse calls Cookie.setHttpOnly directly. The IdP discovery copy of CookieUtils follows suit. The remaining cookies built by hand go the same way: the LoginServlet and CDCServlet deletions are built with the name, path and domain the cookie was set with instead of re-adding the request's Cookie object, the AMTESTCOOKIE probe goes through CookieUtils, and the Oracle Access Manager and SiteMinder sample adapters mark their session cookie Secure on an HTTPS request and HttpOnly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The cookie cluster of the CodeQL medium triage:
java/insecure-cookie×19 andjava/sensitive-cookie-not-httponly×7.What the findings are about
OpenAM sets
SecureandHttpOnlyfrom configuration (com.iplanet.am.cookie.secure,com.sun.identity.cookie.httponly), which CodeQL cannot follow as such: it accepts a cookie as secure only when it flows fromsetSecure(true)orsetSecure(request.isSecure()), and as HttpOnly when it flows from asetHttpOnly(x)withxnot literallyfalse. Reading the sinks against that model turned up two real gaps rather than only a modelling mismatch:CookieUtils.newCookiesetSecurefrom the property but leftHttpOnlytoaddCookieToResponse, which applied it by reflection —Cookie.class.getMethod("setHttpOnly"), a Servlet 2.5 leftover that has been dead code since the move to Jakarta Servlet. 20 of the 26 sinks are cookies built bycreateCookie→newCookieand handed straight toresponse.addCookie(mostly the logout deletions), which therefore went out withoutHttpOnlyeven when it is configured.LoginServletandCDCServlet"reset" paths re-added the request's ownCookieobject with an empty value. A request cookie carries no path, domain or flags, so the deletion the browser received did not match the cookie that had been set with path/(and, for CDC, the auth-URL cookie domain).The change
CookieUtils.newCookiesets both flags on the cookie as it is created —if (isCookieSecure()) setSecure(true),if (isCookieHttpOnly()) setHttpOnly(true)— so every cookie the helper builds carries them whatever path adds it to the response.addCookieToResponsecallsCookie.setHttpOnlydirectly; the hand-builtSet-Cookieheader is kept for the SameSite case only, which the servletCookiecannot express. The IdP discovery war's copy ofCookieUtilsgets the same treatment (it used to write the header by hand for HttpOnly too).LoginServlet: the host-only deletion is built withAuthUtils.createCookie(name, "", null)+maxAge 0, the same way the per-domain deletions next to it already are; theAMTESTCOOKIEprobe goes throughCookieUtils(only the server reads it back).CDCServlet: the auth-URL cookie is cleared by name, path/and its configured domain instead of re-adding the request object.src/main/integrations, not part of the build but scanned underbuild-mode: none) set their session cookieSecureon an HTTPS request andHttpOnly; their agents read the cookie from the request header, not from script.No configuration semantics change: a deployment that sets neither property gets exactly the cookies it got before, minus nothing.
Verification
Every new test was watched failing first (
expected [true] but found [false]on the HttpOnly-from-creation and servlet-API assertions).openam-shared1242 tests (6 new),openam-idpdiscovery12 (4 new),openam-core2130,openam-federation-library177 — 0 failures;OpenFMandopenam-server-auth-uicompile. TheLoginServlet/CDCServletwiring has no unit test (no servlet harness in those modules), and the two adapters cannot be compiled without the vendor SDKs.Expected effect on the scan
All 19
insecure-cookieand 7sensitive-cookie-not-httponlyalerts should close: the cookies now flow from a literalsetSecure(true)/setHttpOnly(true)innewCookie. Anything left after this PR's scan is a sink that receives a cookie built outsidenewCookie, to be looked at individually.