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/oneShot/testCart/cart.c src/hg/oneShot/testCart/cart.c index c6d1f56..b33c5f7 100644 --- src/hg/oneShot/testCart/cart.c +++ src/hg/oneShot/testCart/cart.c @@ -116,44 +116,44 @@ for (cv = cgiVarList(); cv != NULL; cv = cv->next) cartSetString(cart, cv->name, cv->val); if (exclude != NULL) { while (ex = *exclude++) cartExclude(cart, ex); } sqlDisconnect(&conn); return cart; } static void updateOne(struct sqlConnection *conn, char *table, struct cartDb *cdb, char *contents, int contentSize) /* Update cdb in database. */ { -struct dyString *dy = newDyString(4096); +struct dyString *dy = dyStringNew(4096); sqlDyStringPrintf(dy, "UPDATE %s SET contents='", table); sqlDyAppendEscaped(dy, contents); sqlDyStringPrintf(dy, "',lastUse=now(),useCount=%d ", cdb->useCount+1); sqlDyStringPrintf(dy, " where id=%u", cdb->id); sqlUpdate(conn, dy->string); dyStringFree(&dy); } static void saveState(struct cart *cart) /* Save out state to permanent storage in both user and session db. */ { struct sqlConnection *conn = sqlConnect("hgcentral"); -struct dyString *encoded = newDyString(4096); +struct dyString *encoded = dyStringNew(4096); struct hashEl *el, *elList = hashElListHash(cart->hash); boolean firstTime = TRUE; char *s = NULL; /* Make up encoded string holding all variables. */ for (el = elList; el != NULL; el = el->next) { if (!hashLookup(cart->exclude, el->name)) { if (firstTime) firstTime = FALSE; else dyStringAppendC(encoded, '&'); dyStringAppend(encoded, el->name); dyStringAppendC(encoded, '=');