3eedbb7636648978b0371f2c54378e75fd1ac78c braney Fri Sep 11 12:20:14 2026 -0700 Skip a CGI or cookie pair with no =value in three more parsers, refs #38340 The loop that #38335 fixed in the query string parsers is copied in three more places, and each one still looks for the '=' across the whole rest of the string instead of inside the pair it is reading. A pair with no value therefore runs into the pair after it and takes its value, and the same pair at the end of the string has no '=' left to find and aborts. lib/cheapcgi.c parseCookies one bad cookie aborts every CGI for that browser, on every request, until the reader clears the cookie by hand hg/hgSession/backup.c a session backup silently leaves out a custom track hg/utils/refreshNamedSessionCustomTracks one bad session aborts the child, the parent exits non-zero, and every session after it goes unscanned, so the trash cleaner removes their custom track files All three are behind the hg.conf flag skipMalformedCgiPairs, off by default, and registered as a release gate in hgConfCatalog. The kent libraries do not read hg.conf, so hgConfig.c hands the setting to cheapcgi the way cfgSetLogCgiVars already hands it cgiSetMaxLogLen. The query string parsers do not read the flag; they were fixed unconditionally under #38335. refreshNamedSessionCustomTracks rebuilds the session contents as it walks, so it copies a malformed pair through untouched rather than stepping over it. A session carrying one comes back byte for byte the same. Adds lib/tests/cgiCookieTest and hg/hgSession/tests/backupParseTest. Both read every case with the flag off and on, so they pin the old behavior as well as the new one. The nightly tool has no seam for a unit test; its loop sits inside a function that runs its own query. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> diff --git src/inc/cheapcgi.h src/inc/cheapcgi.h index 8c49a65ff8d..455e7396211 100644 --- src/inc/cheapcgi.h +++ src/inc/cheapcgi.h @@ -695,24 +695,29 @@ /* Free up list of cgiParsedVars */ char *cgiScriptDirUrl(); /* Return the cgi-bin directory path on this webserver. * This is not the local directory but the <path> part after the server * in external URLs to this webserver. * e.g. if CGI is called via http://localhost/subdir/cgi-bin/cgiTest * the returned string is /subdir/. Must be free'd. */ void cgiChangeVar(char *varName, char *value); /* An entry point to change the value of a something passed to us on the URL. */ void cgiSetMaxLogLen(int l); /* set the size of variable values that are dumped to stderr. Default is 0, which means no logging */ +void cgiSkipMalformedPairs(boolean on); +/* Tell the cookie parser to step over a malformed pair instead of losing the + * pair after it or aborting. hg.conf skipMalformedCgiPairs turns this on; + * hgConfig.c pushes it in, since these libraries do not read hg.conf. */ + boolean isValidJsonpCallback(char *s); /* Return TRUE if s is safe to use as a JSONP callback name: non-empty, not * too long, and every dot-separated segment is a C symbol (letters, digits, * underscore, not starting with a digit). This rejects anything with * parentheses, spaces, operators, or other characters that would let an * attacker turn a same-origin JSONP response into arbitrary script. */ #endif /* CHEAPCGI_H */