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/hgGenome/hgGenome.c src/hg/hgGenome/hgGenome.c index 633f2b2..fb4a0d0 100644 --- src/hg/hgGenome/hgGenome.c +++ src/hg/hgGenome/hgGenome.c @@ -85,31 +85,35 @@ } } slReverse(&list); return list; } struct genoGraph *getCompGraphs(struct sqlConnection *conn) /* Get graphs defined in database that are part of a composite. */ { struct genoGraph *list = NULL, *gg; struct sqlConnection *conn2 = hAllocConn(database); struct slName *compositeGGList = NULL, *comp; /* Get initial information from metaChromGraph table */ if (sqlTableExists(conn, "metaChromGraph")) - compositeGGList = sqlQuickList(conn, NOSQLINJ "select name from metaChromGraph where binaryFile='composite'"); + { + char query[1024]; + sqlSafef(query, sizeof query, "select name from metaChromGraph where binaryFile='composite'"); + compositeGGList = sqlQuickList(conn, query); + } /* Build a hash of genoGraphs out of composite trackDbs and fill in from cart. */ for (comp = compositeGGList; comp != NULL; comp = comp->next) { struct trackDb *tdb = hTrackDbForTrack(database, comp->name); if (tdb) { struct chromGraphSettings *cgs = chromGraphSettingsGet(comp->name, conn2, tdb, cart); AllocVar(gg); gg->name = cloneString(comp->name); gg->shortLabel = tdb->shortLabel; gg->longLabel = tdb->longLabel; gg->settings = cgs; gg->isSubGraph = FALSE; gg->isComposite = TRUE; @@ -122,31 +126,33 @@ return list; } struct genoGraph *getDbGraphs(struct sqlConnection *conn) /* Get graphs defined in database. Also use the composite settings if */ /* it's a subGraph. */ { struct genoGraph *list = NULL, *gg; struct sqlConnection *conn2 = hAllocConn(database); struct sqlResult *sr; char **row; /* Get initial information from metaChromGraph table */ if (sqlTableExists(conn, "metaChromGraph")) { - sr = sqlGetResult(conn, NOSQLINJ "select name,binaryFile from metaChromGraph where binaryFile!='composite'"); + char query[1024]; + sqlSafef(query, sizeof query, "select name,binaryFile from metaChromGraph where binaryFile!='composite'"); + sr = sqlGetResult(conn, query); while ((row = sqlNextRow(sr)) != NULL) { char *table = row[0], *binaryFile = row[1]; AllocVar(gg); gg->name = gg->shortLabel = gg->longLabel = cloneString(table); gg->binFileName = cloneString(binaryFile); slAddHead(&list, gg); } sqlFreeResult(&sr); } slReverse(&list); /* Where possible fill in additional info from trackDb. */ for (gg = list; gg != NULL; gg = gg->next) {