9ad04e0a0b06ec3c4f09ef1b6c3ce6be79b61c68 braney Sun Aug 16 11:56:56 2026 -0700 cart: validate file names read back out of the cart Several cart variables hold the name of a file the server created for a user. Route them through one shared check, isServerUserFilePath(), which accepts the trash directory, the session-data directories and myVariantsDataDir, and apply it both where values enter the cart and where the file names are used. A few of these variables may instead hold a remote URL. Those get their own list and isServerUserFileOrUrl(), because the code that reads them chooses between a fetch and a local open by looking for a protocol. Consolidates two hand-rolled copies of the same test in blatShare.c and customFactory.c, and drops the weaker private copy in sessionData.c. Adds hg/utils/cartFileVarCatalog, a registry that scans the tree for a cart value reaching a file call and reconciles what it finds against the lists in cart.c, so a new one of these cannot be added without somebody noticing. Its --reconcile is quiet enough for the nightly cron the other catalogs use, and it is what turned up seven of the names now on those lists. refs #37623 diff --git src/hg/hgTracks/config.c src/hg/hgTracks/config.c index 2dacb531f32..03505c16f85 100644 --- src/hg/hgTracks/config.c +++ src/hg/hgTracks/config.c @@ -1,30 +1,31 @@ /* config - put up track and display configuration page. */ /* Copyright (C) 2014 The Regents of the University of California * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */ #include "common.h" #include "dystring.h" #include "cheapcgi.h" #include "htmshell.h" #include "hdb.h" #include "hCommon.h" #include "cart.h" #include "web.h" #include "customTrack.h" #include "hgTracks.h" +#include "trashDir.h" #include "hgConfig.h" #include "jsHelper.h" #include "imageV2.h" #include "search.h" #include "hubConnect.h" #include "fileUi.h" #include "trackHub.h" #include "versionInfo.h" static void themeDropDown(struct cart* cart) /* Create drop down for UI themes. * specfied in hg.conf like this * browser.theme.modern=background.png,HGStyle * */ { @@ -981,31 +982,33 @@ } */ hPrintf("<TR><TD>"); cgiMakeRadioButton("virtModeType", "customUrl", sameWord("customUrl", virtModeType)); hPrintf("</TD><TD>"); hPrintf("Enter custom regions as BED, or a URL to them:<br>"); multiRegionsBedUrl = cartUsualString(cart, "multiRegionsBedUrl", multiRegionsBedUrl); struct dyString *dyMultiRegionsBedInput = dyStringNew(256); if (strstr(multiRegionsBedUrl,"://")) { dyStringAppend(dyMultiRegionsBedInput, multiRegionsBedUrl); } else { - if (fileExists(multiRegionsBedUrl)) + /* Not a URL, so this is the trash file we wrote the pasted BED to. Check it before + * reading, since the contents go straight back to the user in the text area below. */ + if (isServerUserFilePath(multiRegionsBedUrl) && fileExists(multiRegionsBedUrl)) { struct lineFile *lf = lineFileMayOpen(multiRegionsBedUrl, TRUE); char *line; int lineSize; while (lineFileNext(lf, &line, &lineSize)) { dyStringPrintf(dyMultiRegionsBedInput, "%s\n", line); } lineFileClose(&lf); } } hPrintf("<TEXTAREA NAME='multiRegionsBedInput' ID='multiRegionsBedInput' rows='4' cols='58' style='white-space: pre;'>%s</TEXTAREA>", dyMultiRegionsBedInput->string); // option to set viewing window to show all regions. This id also known to JS.