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/cgilib/transMapInfo.c src/hg/cgilib/transMapInfo.c index 43428eb..44858df 100644 --- src/hg/cgilib/transMapInfo.c +++ src/hg/cgilib/transMapInfo.c @@ -1,30 +1,28 @@ /* transMapInfo.c was originally generated by the autoSql program, which also * generated transMapInfo.h and transMapInfo.sql. This module links the database and * the RAM representation of objects. */ /* Copyright (C) 2014 The Regents of the University of California * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */ #include "common.h" #include "linefile.h" #include "dystring.h" #include "jksql.h" #include "transMapInfo.h" -char *transMapInfoCommaSepFieldNames = "mappedId,srcDb,srcId,mappingId,chainSubset"; - /* definitions for chainSubset column */ static char *values_chainSubset[] = {"unknown", "all", "syn", "rbest", NULL}; static struct hash *valhash_chainSubset = NULL; void transMapInfoStaticLoad(char **row, struct transMapInfo *ret) /* Load a row from transMapInfo table into ret. The contents of ret will * be replaced at the next call to this function. */ { ret->mappedId = row[0]; safecpy(ret->srcDb, sizeof(ret->srcDb), row[1]); ret->srcId = row[2]; ret->mappingId = row[3]; ret->chainSubset = sqlEnumParse(row[4], values_chainSubset, &valhash_chainSubset); } @@ -146,18 +144,18 @@ if (sep == ',') fputc('"',f); sqlEnumPrint(f, el->chainSubset, values_chainSubset); if (sep == ',') fputc('"',f); fputc(lastSep,f); } /* -------------------------------- End autoSql Generated Code -------------------------------- */ struct transMapInfo *transMapInfoQuery(struct sqlConnection *conn, char *table, char *mappedId) /* load a single transMapInfo object for an mapped id from a table, * or error if not found */ { return sqlQueryObjs(conn, (sqlLoadFunc)transMapInfoLoad, sqlQueryMust|sqlQuerySingle, - "SELECT %-s FROM %s WHERE mappedId = \"%s\"", - transMapInfoCommaSepFieldNames, table, mappedId); + "SELECT mappedId,srcDb,srcId,mappingId,chainSubset FROM %s WHERE mappedId = \"%s\"", + table, mappedId); }