44ccfacbe3a3d4b300f80d48651c77837a4b571e galt Tue Apr 26 11:12:02 2022 -0700 SQL INJECTION Prevention Version 2 - this improves our methods by making subclauses of SQL that get passed around be both easy and correct to use. The way that was achieved was by getting rid of the obscure and not well used functions sqlSafefFrag and sqlDyStringPrintfFrag and replacing them with the plain versions of those functions, since these are not needed anymore. The new version checks for NOSQLINJ in unquoted %-s which is used to include SQL clauses, and will give an error the NOSQLINJ clause is not present, and this will automatically require the correct behavior by developers. sqlDyStringPrint is a very useful function, however because it was not enforced, users could use various other dyString functions and they operated without any awareness or checking for SQL correct use. Now those dyString functions are prohibited and it will produce an error if you try to use a dyString function on a SQL string, which is simply detected by the presence of the NOSQLINJ prefix. diff --git src/hg/hgTables/genomeSpace.c src/hg/hgTables/genomeSpace.c index 6448c0b..9495d8c 100644 --- src/hg/hgTables/genomeSpace.c +++ src/hg/hgTables/genomeSpace.c @@ -168,31 +168,31 @@ * Returns a url like [https://identity.genomespace.org/datamanager/files/users/<user>] */ { // DEFAULT DIRECTORY // old1 char *defaultDirectoryUrl = "https://identity.genomespace.org/datamanager/defaultdirectory"; // old2 char *defaultDirectoryUrl = "https://dmtest.genomespace.org:8444/datamanager/defaultdirectory"; // old3 char *defaultDirectoryUrl = "https://dm.genomespace.org/datamanager/v1.0/defaultdirectory"; // NOTE the defaultdirectory method got renamed to personaldirectory // old4 char *personalDirectoryUrl = "https://dm.genomespace.org/datamanager/v1.0/personaldirectory"; char *dmSvr = getGenomeSpaceConfig("dmServer"); char personalDirectoryUrl[1024]; safef(personalDirectoryUrl, sizeof personalDirectoryUrl, "%s/v1.0/personaldirectory", dmSvr); -struct dyString *reqExtra = newDyString(256); +struct dyString *reqExtra = dyStringNew(256); dyStringPrintf(reqExtra, "Cookie: gs-token=%s\r\n", gsToken); int sd = netOpenHttpExt(personalDirectoryUrl, "GET", reqExtra->string); if (sd < 0) errAbort("failed to open socket for [%s]", personalDirectoryUrl); struct dyString *dy = netSlurpFile(sd); close(sd); char *personalDirectory = NULL; if (strstr(dy->string, "HTTP/1.1 303 See Other")) { char *valStart = strstr(dy->string, "Location: "); if (valStart) @@ -294,59 +294,59 @@ "%s/v1.0/uploadurl/users/" "%s/" "%s" "?Content-Length=%lld" "&Content-MD5=%s" "&Content-Type=%s" , dmSvr , user , uploadFileName , (long long) contentLength , cgiEncode(base64Md5) , contentType ); -struct dyString *reqExtra = newDyString(256); +struct dyString *reqExtra = dyStringNew(256); dyStringPrintf(reqExtra, "Cookie: gs-token=%s\r\n", gsToken); int sd = netOpenHttpExt(uploadUrl, "GET", reqExtra->string); if (sd < 0) errAbort("failed to open socket for [%s]", uploadUrl); char *responseCode = NULL; char *s3UploadUrl = parseResponse(sd, &responseCode); if (sameString(responseCode, "404 Not Found")) errAbort("GenomeSpace: %s, if a path was used in the output name, it may indicate the path does not exist in GenomeSpace.", responseCode); if (!sameString(responseCode, "200 OK")) errAbort("GenomeSpace: %s", responseCode); dyStringFree(&reqExtra); return s3UploadUrl; } #define S3UPBUFSIZE 65536 char *gsS3Upload(char *s3UploadUrl, char *inputFileName, off_t contentLength, char *base64Md5, char *hexMd5, char *contentType, boolean progress, char *fileName) /* call s3 upload */ { // S3 UPLOAD to Amazon Storage -struct dyString *reqExtra = newDyString(256); +struct dyString *reqExtra = dyStringNew(256); dyStringPrintf(reqExtra, "Content-Length: %lld\r\n", (long long)contentLength); dyStringPrintf(reqExtra, "Content-MD5: %s\r\n", base64Md5); dyStringPrintf(reqExtra, "Content-Type: %s\r\n", contentType); int sd = netOpenHttpExt(s3UploadUrl, "PUT", reqExtra->string); if (sd < 0) errAbort("failed to open socket for [%s]", s3UploadUrl); unsigned char buffer[S3UPBUFSIZE]; int bufRead = 0; FILE *f = mustOpen(inputFileName,"rb"); off_t totalUploaded = 0; int lastPctUploaded = -1; // upload the file contents