998149024f8bde04e8b76638043cfeac3d158731 max Tue Sep 15 05:47:27 2026 -0700 Queue the cart cookie and the content policy instead of printing them, refs #38353 cartWriteHeaderAndCont() guards on cgiDidContentType(), which any cgiPrintContentType() anywhere sets. An early warn() during cartNew -- "Unable to load session file" reaches the early warning handler, which calls htmlStart -- prints the header before there is a cart, and from then on the Set-Cookie and Content-Security-Policy lines were silently skipped. Nothing changed on the wire, since before the guard they landed in the page body as text and were equally inert, but skipping them silently is not the behaviour to keep. cartWriteCookie() and cspWriteResponseHeader() now hand their lines to cgiAddHttpHeader(), so whichever call prints the content type prints them too and the order of the calls no longer matters. cartAndCookieWithHtml() queues the policy before the early handlers are pushed, so even a page written by that early warn carries one. The cookie cannot be queued that early -- there is no cart yet -- and is still lost on that path; the comment says so. cgiAddHttpHeader() now does what its own comment already promised and ignores a header added after the block was closed, rather than growing a list nothing will ever print. getCspPolicyString() is declared in htmshell.h so hCommon.c can queue the value on its own. diff --git src/inc/htmshell.h src/inc/htmshell.h index 482ba456720..09acee0c176 100644 --- src/inc/htmshell.h +++ src/inc/htmshell.h @@ -84,30 +84,35 @@ void cssDecode(char *s); /* For CSS values decode "\HH " */ void jsDecode(char *s); /* For JS string values decode "\xHH" */ void urlDecode(char *s); /* For URL paramter values decode "%HH" */ void htmlMemDeath(); /* Complain about lack of memory and abort. */ char *getNonce(); /* make nonce one-use-per-page */ +char *getCspPolicyString(); +/* Return the Content Security Policy, the value part of the header, freeMem when done. + * Carries the same nonce as the meta tag, since getNonce() is one-per-process, so a page + * may safely have both. */ + char *getCspMetaHeader(); /* return meta CSP header string */ void generateCspMetaHeader(FILE *f); /* Generate Meta CSP Header */ void generateCspResponseHeader(FILE *f); /* Generate the CSP as an http response header. Must be called before the * blank line that ends the http header block. */ void htmlStart(char *title); /* Write the start of a cgi-generated html file */ void htmStart(FILE *f, char *title); /* Write the start of a stand alone .html file. */