f759bf663debc22e6015c6c38c22f922bfbdf45b
braney
  Fri Aug 21 10:01:02 2026 -0700
lib, cgilib: sanitize description HTML where it comes in, refs #38126

A track hub's track description, a custom track's documentation, and an
assembly hub's genome description are all written by somebody else and were
stored and printed as they arrived.  Run each through htmlSanitize() at the
point it is read, so that everything downstream sees text we are willing to
print.  Sanitizing on the way in is the only practical place: printTrackHtml()
alone has more than a hundred callers, and hgTrackUi, hui.c, hgGene,
hgGtexTrackSettings and hgTables all print tdb->html directly.

The five places are trackHubAddOneDescription(), customTrack.c where it used
to call jsStripJavascript(), the htmlUrl fetch in customFactory.c,
hgPositionsHelpHtmlCart() and hAssemblyDescription().  In the last two, only
the branch that fetches over the network is touched.  The branch that reads a
local file is left as it is, because those are our own description.html files.

trackHubAddOneDescription() keeps its old shape.  The fetch moves into a
helper so that trackHubDescriptionRemovals() can hand hubCheck the list of
things the filter takes out.

diff --git src/hg/lib/hgFind.c src/hg/lib/hgFind.c
index 42c05ae7511..b47433c062b 100644
--- src/hg/lib/hgFind.c
+++ src/hg/lib/hgFind.c
@@ -10,30 +10,31 @@
 #include "dystring.h"
 #include "hash.h"
 #include "cheapcgi.h"
 #include "htmshell.h"
 #include "web.h"
 #include "jksql.h"
 #include "hdb.h"
 #include "hui.h"
 #include "psl.h"
 #include "genePred.h"
 #include "genePredReader.h"
 #include "bed.h"
 #include "cytoBand.h"
 #include "cart.h"
 #include "errCatch.h"
+#include "htmlSanitize.h"
 #include "hgFind.h"
 #include "hgFindSpec.h"
 #include "hgHgvs.h"
 #include "snp.h"
 #include "refLink.h"
 #include "kgAlias.h"
 #include "kgProtAlias.h"
 #include "findKGAlias.h"
 #include "findKGProtAlias.h"
 #include "tigrCmrGene.h"
 #include "minGeneInfo.h"
 #include "pipeline.h"
 #include "hgConfig.h"
 #include "trix.h"
 #include "trackHub.h"
@@ -4365,33 +4366,36 @@
     webNewSection("%s Genome Browser – %s assembly"
 		  "  <A HREF=\"%s?%s=%s&chromInfoPage=\">(sequences)</A>",
 		  trackHubSkipHubName(organism), 
 		  trackHubSkipHubName(database),
 		  hgTracksName(), cartSessionVarName(), cartSessionId(cart));
 
 if (htmlPath != NULL) 
     {
     if (fileExists(htmlPath))
 	readInGulp(htmlPath, &htmlString, &htmlStrLength);
     else if (   startsWith("http://" , htmlPath) ||
 		startsWith("https://", htmlPath) ||
 		startsWith("ftp://"  , htmlPath))
 	{
 	struct lineFile *lf = udcWrapShortLineFile(htmlPath, NULL, 256*1024);
-	htmlString =  lineFileReadAll(lf);
-	htmlStrLength = strlen(htmlString);
+	char *fetched = lineFileReadAll(lf);
 	lineFileClose(&lf);
+	/* This one came in over the network from a hub, so print only what we allow. */
+	htmlString = htmlSanitize(fetched);
+	freeMem(fetched);
+	htmlStrLength = (htmlString == NULL ? 0 : strlen(htmlString));
 	}
     }
 
 if (htmlStrLength > 0)
     {
     puts(htmlString);
     freeMem(htmlString);
     freeMem(htmlPath);
     }
 else
     {
     printf("<H2>%s</H2>\n", trackHubSkipHubName(organism));
     if (htmlPath == NULL || htmlPath[0] == 0)
 	printf("\n<!-- No dbDb.htmlPath for %s -->\n", database);
     else