a8349f676d1dad81ee90c58605ecbd69453666b1 chmalee Mon Jul 27 15:14:21 2026 -0700 Fixed a bug in hubspace uploads where the unencoded parentDir was used by tusd for the upload location while the encoded path was set in the hubSpace table. Also validate and trim parentDir in the pre-create hook and in hgMyData.js, refs #34962 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> diff --git src/hg/hgHubConnect/hooks/hooklib.h src/hg/hgHubConnect/hooks/hooklib.h index 21592385dcd..cf66cc359ad 100644 --- src/hg/hgHubConnect/hooks/hooklib.h +++ src/hg/hgHubConnect/hooks/hooklib.h @@ -11,30 +11,39 @@ #define HTTP_NAME "HTTPResponse" #define HTTP_STATUS "StatusCode" #define HTTP_BODY "Body" #define HTTP_HEADER "Header" #define HTTP_CONTENT_TYPE "Content-Type" #define HTTP_CONTENT_TYPE_STR "application/json" char *prettyFileSize(long size); /* Return a string representing the size of a file */ char *encodePath(char *path); /* Return a string where each individual component of a '/' separated * string has been cgiEncoded, but not the '/' chars themselves */ +char *normalizeParentDir(char *parentDir); +/* Return parentDir with any surrounding whitespace trimmed off, or NULL if it was NULL. + * Every hook that builds a path from this metadata value must normalize it the same way */ + +boolean isValidParentDir(char *parentDir); +/* Return TRUE if every '/' separated component of parentDir holds only alphanumeric, + * period or underscore characters. NULL or empty means the top level of the user's + * directory, which is allowed */ + char *setUploadPath(char *userName, char *fileName, char *parentDir, boolean forceOverwrite); /* return the path, relative to hg.conf tusdDataDir, where we will store this upload * the full path would be /tusdDataDir/userNamePrefix/userName/parentDir/fileName */ void fillOutHttpResponseError(struct jsonElement *response); void fillOutHttpResponseSuccess(struct jsonElement *response); struct jsonElement *makeDefaultResponse(); /* Create the default response json with some fields pre-filled */ void rejectUpload(struct jsonElement *response, char *msg, ...); /* Set the keys for stopping an upload */ boolean isFileTypeRecognized(char *fileName);