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/protein/lib/doSam.c src/hg/protein/lib/doSam.c index 8b04fa7..7845dcb 100644 --- src/hg/protein/lib/doSam.c +++ src/hg/protein/lib/doSam.c @@ -2,31 +2,31 @@ /* Copyright (C) 2013 The Regents of the University of California * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */ #include "common.h" #include "hdb.h" #include "pbTracks.h" char *getSgdId(char *protId, char *database) /* Get SGD gene ID from a Swiss-Prot ID */ { struct sqlConnection *conn2 = hAllocConn(database); char condStr[256]; char *sgdId; -sqlSafefFrag(condStr, sizeof condStr, "proteinId='%s'", protId); +sqlSafef(condStr, sizeof condStr, "proteinId='%s'", protId); sgdId = sqlGetField(database, "sgdGene", "name", condStr); hFreeConn(&conn2); return(sgdId); } void doSamT02(char *proteinId, char *database) /* display the UCSC SAM-T02 Protein Structure Analysis and Prediction section */ { char *itemName = NULL; char query2[256]; struct sqlResult *sr2; char **row2; struct sqlConnection *conn, *conn2 = hAllocConn(database); char condStr[256]; char *chp; @@ -58,31 +58,31 @@ return; } itemName = proteinId; if (sameWord(database, "sacCer1")) { samHttpStr0 = strdup("http://www.soe.ucsc.edu/research/compbio/yeast-protein-predictions"); samHttpStr = strdup("../goldenPath/sacCer1/sam"); /* SAM analysis of SGD proteins uses SGD ID, not Swiss-Prot AC */ itemName = getSgdId(proteinId, database); } if (itemName == NULL) return; -sqlSafefFrag(condStr, sizeof condStr, "proteinId='%s'", itemName); +sqlSafef(condStr, sizeof condStr, "proteinId='%s'", itemName); samSubDir = sqlGetField(database, "samSubdir", "subdir", condStr); if (samSubDir == NULL) return; hPrintf("<B>UCSC "); hPrintf("<A HREF=\"http://www.soe.ucsc.edu/research/compbio/SAM_T02/sam-t02-faq.html\""); hPrintf(" TARGET=_blank>SAM-T02</A>\n"); hPrintf(" Protein Structure Analysis and Prediction on %s", proteinId); if (!sameWord(proteinId, itemName)) hPrintf(" (aka %s)", itemName); hPrintf("</B><BR>\n"); hPrintf(" <B>Multiple Alignment (sequence logo):</B> \n"); hPrintf("<A HREF=\"%s/%s/%s/%s.t2k.w0.5-logo.pdf\"", samHttpStr, samSubDir, itemName, itemName); hPrintf(" TARGET=_blank>%s</A> (pdf)<BR>\n", itemName); hPrintf("<B> Secondary Structure Predictions:</B> \n");