e6ddf60465deb96e43be6738c5ca6a7a6168cac8 braney Sat Aug 22 15:08:59 2026 -0700 hg/lib: add an option to send the content policy as an http response header New cspWriteResponseHeader() in hg/lib/hCommon.c, gated on hg.conf's cspResponseHeader, which defaults off everywhere. The policy string itself is still built by the existing code in lib/htmshell.c, which now also knows how to format it as a response header. Both carry the same nonce, since getNonce() is one per process, so a page may safely have the header and the meta tag. Most pages pick it up from addHttpHeaders() in cart.c, the existing hook for extra response headers, which every cart based CGI already passes through. Six places build their own http header block and so call it directly: the two "too many requests" pages, the captcha and its error page, the hubApi help redirect, and the hgSearch redirect to hgTracks. Inline scripts on three of those pages now carry the nonce, and the policy allows the Cloudflare script the bot check loads, so the option works when it is turned on. The Cloudflare entry is the only part of this that takes effect with the option off. diff --git src/inc/htmshell.h src/inc/htmshell.h index 34d26763f9a..482ba456720 100644 --- src/inc/htmshell.h +++ src/inc/htmshell.h @@ -90,30 +90,34 @@ 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 *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. */ void printBodyTag(FILE *f); // print starting BODY tag, including any appropriate attributes (class, background and bgcolor). void htmStartWithHead(FILE *f, char *head, char *title); /* Write the start of a stand alone .html file, plus head info */ void htmStartDirDepth(FILE *f, char *title, int dirDepth); /* Write the start of a stand alone .html file. dirDepth is the number of levels * beneath apache root that caller's HTML will appear to the web client.