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/pbTracks/pbTracks.c src/hg/protein/pbTracks/pbTracks.c index ae4252d..fb581e5 100644 --- src/hg/protein/pbTracks/pbTracks.c +++ src/hg/protein/pbTracks/pbTracks.c @@ -387,89 +387,89 @@ hgsid = cartOptionalString(cart, "hgsid"); if (hgsid != NULL) { safef(hgsidStr, sizeof(hgsidStr), "&hgsid=%s", hgsid); } else { strcpy(hgsidStr, ""); } proteinID = cartOptionalString(cart, "proteinID"); /* check proteinID to see if it is a valid SWISS-PROT/TrEMBL accession or display ID */ /* then assign the accession number to global variable proteinID */ -sqlSafefFrag(cond_str, sizeof(cond_str), "accession='%s'", proteinID); +sqlSafef(cond_str, sizeof(cond_str), "accession='%s'", proteinID); proteinAC = sqlGetField(protDbName, "spXref3", "accession", cond_str); if (proteinAC == NULL) { - sqlSafefFrag(cond_str, sizeof(cond_str), "displayID='%s'", proteinID); + sqlSafef(cond_str, sizeof(cond_str), "displayID='%s'", proteinID); proteinAC = sqlGetField(protDbName, "spXref3", "accession", cond_str); if (proteinAC == NULL) { hUserAbort("'%s' does not seem to be a valid UniProtKB protein ID.", proteinID); } else { protDisplayID = proteinID; proteinID = proteinAC; } } else { - sqlSafefFrag(cond_str, sizeof(cond_str), "accession='%s'", proteinID); + sqlSafef(cond_str, sizeof(cond_str), "accession='%s'", proteinID); protDisplayID = sqlGetField(protDbName, "spXref3", "displayID", cond_str); } if (spFindAcc(spConn, proteinID) == NULL) { - sqlSafefFrag(cond_str, sizeof(cond_str), "accession='%s'", proteinID); + sqlSafef(cond_str, sizeof(cond_str), "accession='%s'", proteinID); answer = sqlGetField(protDbName, "spXref3", "biodatabaseID", cond_str); if (sameWord(answer, "3")) { hUserAbort("The corresponding protein %s is no longer available from UniProtKB.", proteinID); } else { hUserAbort("%s seems not to be a valid protein ID.", proteinID); } } else { if (!sameWord(proteinID, spFindAcc(spConn, proteinID))) { hPrintf("%s seems to be an outdated protein ID.", proteinID); printf("<BR><BR>Please try "); hPrintf("<A HREF=\"../cgi-bin/pbGlobal?proteinID=%s\"> %s</A> instead.\n", spFindAcc(spConn, proteinID), spFindAcc(spConn, proteinID));fflush(stdout); hUserAbort(" "); } } if (kgVersion == KG_III) { - sqlSafefFrag(cond_str, sizeof(cond_str), "spID='%s'", proteinID); + sqlSafef(cond_str, sizeof(cond_str), "spID='%s'", proteinID); mrnaID = sqlGetField(database, "kgXref", "kgId", cond_str); } else { - sqlSafefFrag(cond_str, sizeof(cond_str), "proteinID='%s'", protDisplayID); + sqlSafef(cond_str, sizeof(cond_str), "proteinID='%s'", protDisplayID); mrnaID = sqlGetField(database, "knownGene", "name", cond_str); } -sqlSafefFrag(cond_str, sizeof(cond_str), "accession='%s'", proteinID); +sqlSafef(cond_str, sizeof(cond_str), "accession='%s'", proteinID); description = sqlGetField(protDbName, "spXref3", "description", cond_str); /* obtain previous genome position range selected by the Genome Browser user */ positionStr = cloneString(cartOptionalString(cart, "position")); if (positionStr != NULL) { chp = strstr(positionStr, ":"); *chp = '\0'; prevGBChrom = cloneString(positionStr); chp1 = chp + 1; chp9 = strstr(chp1, "-"); *chp9 = '\0'; prevGBStartPos = atoi(chp1); chp1 = chp9 + 1;