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/visiGene/vgLoadJax/vgLoadJax.c src/hg/visiGene/vgLoadJax/vgLoadJax.c index 73fedd0..31196db 100644 --- src/hg/visiGene/vgLoadJax/vgLoadJax.c +++ src/hg/visiGene/vgLoadJax/vgLoadJax.c @@ -50,31 +50,33 @@ { verbose(2, "%s\n", s); return sqlGetResult(conn, s); } char *sqlQuickStringVerbose(struct sqlConnection *conn, char *s) /* Get result, printing out query if verbosity is high enough. */ { verbose(2, "%s\n", s); return sqlQuickString(conn, s); } struct slName *jaxSpecList(struct sqlConnection *conn) /* Get list of specimen id's. */ { -return sqlQuickList(conn, NOSQLINJ "select _Specimen_key from GXD_Specimen"); +char query[1024]; +sqlSafef(query, sizeof query, "select _Specimen_key from GXD_Specimen"); +return sqlQuickList(conn, query); } void dumpRow(char **row, int size) /* Dump out row if verbosity >= 3. */ { int i; for (i=0; i<size; ++i) verbose(3, "%s\t", row[i]); verbose(3, "\n"); } char *colorFromLabel(char *label, char *gene) /* Return color from labeling method. This could be * something in either the GXD_Label or the GXD_VisualizationMethod * tables in the jackson database. */ @@ -170,31 +172,31 @@ struct sqlResult *sr; char **row; /* Figure out genotype. Create string that looks something like: * adh:cheap date,antp:+, * That is a comma separated list gene:allele. */ sqlDyStringPrintf(query, "select MRK_Marker.symbol,ALL_Allele.symbol " "from GXD_AlleleGenotype,MRK_Marker,ALL_Allele " "where GXD_AlleleGenotype._Genotype_key = %s " "and GXD_AlleleGenotype._Marker_key = MRK_Marker._Marker_key " "and GXD_AlleleGenotype._Allele_key = ALL_Allele._Allele_key " , genotypeKey); sr = sqlGetResultVerbose(conn, query->string); while ((row = sqlNextRow(sr)) != NULL) - dyStringPrintf(geno, "%s:%s,", row[0], row[1]); + sqlDyStringPrintf(geno, "%s:%s,", row[0], row[1]); sqlFreeResult(&sr); genotype = dyStringCannibalize(&geno); /* Figure out strain */ dyStringClear(query); sqlDyStringPrintf(query, "select PRB_Strain.strain from GXD_Genotype,PRB_Strain " "where GXD_Genotype._Genotype_key = %s " "and GXD_Genotype._Strain_key = PRB_Strain._Strain_key" , genotypeKey); strain = sqlQuickStringVerbose(conn, query->string); if (isUnknown(strain)) freez(&strain); dyStringFree(&query); @@ -892,31 +894,33 @@ dyStringFree(©right); dyStringFree(&caption); dyStringFree(&query); hashFree(&uniqImageHash); hashFree(&captionHash); } void submitToDir(struct sqlConnection *conn, struct sqlConnection *conn2, struct sqlConnection *connSp, char *outDir, char *inJax) /* Create directory full of visiGeneLoad .ra/.tab files from * jackson database connection. Creates a pair of files for * each submission set. Returns outDir. */ { struct dyString *query = dyStringNew(0); -struct slName *ref, *refList = sqlQuickList(conn, NOSQLINJ "select distinct(_Refs_key) from GXD_Assay"); +dyStringClear(query); +sqlDyStringPrintf(query, "select distinct(_Refs_key) from GXD_Assay"); +struct slName *ref, *refList = sqlQuickList(conn, query->string); int refCount = 0; makeDir(outDir); for (ref = refList; ref != NULL; ref = ref->next) { char path[PATH_LEN]; char *pub=NULL; boolean skip; /* Check that it isn't on our skip list - one that we * have already in the database from a higher resolution * source. */ dyStringClear(query); sqlDyStringPrintf(query, "select title from BIB_Refs where _Refs_key = %s",