a53b9958fa734f73aeffb9ddfe2fbad1ca65f90c galt Mon Jan 30 16:18:41 2017 -0800 Check-in of CSP2 Content-Security-Policy work. All C-language CGIs should now support CSP2 in browser to stop major forms of XSS javascript injection. Javascript on pages is gathered together, and then emitted in a single script block at the end with a nonce that tells the browser, this is js that we generated instead of being injected by a hacker. Both inline script from script blocks and inline js event handlers had to be pulled out and separated. You will not see js sprinkled through-out the page now. Older browsers that support CSP1 or that do not understand CSP at all will still work, just without protection. External js libraries loaded at runtime need to be added to the CSP policy header in src/lib/htmshell.c. diff --git src/hg/hgFileSearch/hgFileSearch.c src/hg/hgFileSearch/hgFileSearch.c index 48f91e1..fe0f8f4 100644 --- src/hg/hgFileSearch/hgFileSearch.c +++ src/hg/hgFileSearch/hgFileSearch.c @@ -221,128 +221,130 @@ printf("<input type='hidden' name='%s' id='currentTab' value='%s'>\n", FILE_SEARCH_CURRENT_TAB, currentTab); printf("<div id='tabs' style='display:none; %s'>\n" "<ul>\n" "<li><a href='#simpleTab'><B style='font-size:.9em;font-family: arial, Geneva, " "Helvetica, san-serif;'>Search</B></a></li>\n" "<li><a href='#filesTab'><B style='font-size:.9em;font-family: arial, Geneva, " "Helvetica, san-serif;'>Files</B></a></li>\n" "</ul>\n",cgiBrowser()==btIE?"width:1060px;":"max-width:inherit;"); // Files tab printf("<div id='simpleTab' style='max-width:inherit;'>\n"); printf("<table id='simpleTable' style='width:100%%; font-size:.9em;'><tr><td colspan='2'>"); printf("<input type='text' name='%s' id='simpleSearch' class='submitOnEnter' value='%s' " - "style='max-width:1000px; width:100%%;' onkeyup='findTracks.searchButtonsEnable(true);'>\n", + "style='max-width:1000px; width:100%%;'>\n", TRACK_SEARCH_SIMPLE,descSearch == NULL ? "" : descSearch); +jsOnEventById("keyup", "simpleSearch", "findTracks.searchButtonsEnable(true);"); printf("</td></tr><td style='max-height:4px;'></td></tr></table>"); printf("<input type='submit' name='%s' id='searchSubmit' value='search' style='font-size:.8em;'>\n", FILE_SEARCH); -printf("<input type='button' name='clear' value='clear' class='clear' style='font-size:.8em;' " - "onclick='findTracks.clear();'>\n"); +printf("<input type='button' name='clear' id='clear' value='clear' class='clear' style='font-size:.8em;'>\n"); +jsOnEventById("click","clear","findTracks.clear();"); printf("<input type='submit' name='submit' value='cancel' class='cancel' " "style='font-size:.8em;'>\n"); printf("</div>\n"); #endif///def USE_TABS // Files tab printf("<div id='filesTab' style='width:inherit;'>\n" "<table id='filesTable' cellSpacing=0 style='width:inherit; font-size:.9em;'>\n"); cols = 8; // Track Name contains printf("<tr><td colspan=3></td>"); printf("<td nowrap><b style='max-width:100px;'>Track Name:</b></td>"); printf("<td align='right'>contains</td>\n"); printf("<td colspan='%d'>", cols - 4); printf("<input type='text' name='%s' id='nameSearch' class='submitOnEnter' value='%s' " - "onkeyup='findTracks.searchButtonsEnable(true);' style='min-width:326px; font-size:.9em;'>", + "style='min-width:326px; font-size:.9em;'>", TRACK_SEARCH_ON_NAME, nameSearch == NULL ? "" : nameSearch); +jsOnEventById("keyup", "nameSearch", "findTracks.searchButtonsEnable(true);"); printf("</td></tr>\n"); // Description contains printf("<tr><td colspan=2></td><td align='right'>and </td>"); printf("<td><b style='max-width:100px;'>Description:</b></td>"); printf("<td align='right'>contains</td>\n"); printf("<td colspan='%d'>", cols - 4); printf("<input type='text' name='%s' id='descSearch' value='%s' class='submitOnEnter' " - "onkeyup='findTracks.searchButtonsEnable(true);' style='max-width:536px; " - "width:536px; font-size:.9em;'>", + "style='max-width:536px; width:536px; font-size:.9em;'>", TRACK_SEARCH_ON_DESCR, descSearch == NULL ? "" : descSearch); +jsOnEventById("keyup", "descSearch", "findTracks.searchButtonsEnable(true);"); printf("</td></tr>\n"); // Set up Group dropdown struct grp *grps = hLoadGrps(db); grps = groupsFilterForTdbList(&grps,tdbList); int numGroups = slCount(grps) + 1; // Add Any char **groups = needMem(sizeof(char *) * numGroups); char **labels = needMem(sizeof(char *) * numGroups); groups[0] = ANYLABEL; labels[0] = ANYLABEL; int ix=1; struct grp *grp = grps; for (; grp != NULL; grp = grp->next,ix++) { groups[ix] = cloneString(grp->name); labels[ix] = cloneString(grp->label); } printf("<tr><td colspan=2></td><td align='right'>and </td>\n"); printf("<td><b style='max-width:100px;'>Group:</b></td>"); printf("<td align='right'>is</td>\n"); printf("<td colspan='%d'>", cols - 4); char *groupSearch = cartOptionalString(cart, TRACK_SEARCH_ON_GROUP); -cgiMakeDropListFull(TRACK_SEARCH_ON_GROUP, labels, groups, numGroups, groupSearch, - "class='groupSearch' style='min-width:40%; font-size:.9em;'"); +cgiMakeDropListFullExt(TRACK_SEARCH_ON_GROUP, labels, groups, numGroups, groupSearch, + NULL, NULL, "min-width:40%; font-size:.9em;", "groupSearch"); printf("</td></tr>\n"); // Track Type is (drop down) printf("<tr><td colspan=2></td><td align='right'>and </td>\n"); printf("<td nowrap><b style='max-width:100px;'>Data Format:</b></td>"); printf("<td align='right'>is</td>\n"); printf("<td colspan='%d'>", cols - 4); char *dropDownHtml = fileFormatSelectHtml(FILE_SEARCH_ON_FILETYPE,fileTypeSearch, - "style='min-width:40%; font-size:.9em;'"); + NULL, NULL, "min-width:40%; font-size:.9em;"); if (dropDownHtml) { puts(dropDownHtml); freeMem(dropDownHtml); } printf("</td></tr>\n"); // mdb selects struct slPair *mdbSelects = NULL; if (metaDbExists) { struct slPair *mdbVars = mdbVarsSearchable(conn,FALSE,TRUE); // Not tables, just files mdbSelects = mdbSelectPairs(cart, mdbVars); char *output = mdbSelectsHtmlRows(conn,mdbSelects,mdbVars,cols,TRUE); // just for fileSearch if (output) { puts(output); freeMem(output); } slPairFreeList(&mdbVars); } printf("</table>\n"); printf("<input type='submit' name='%s' id='searchSubmit' value='search' style='font-size:.8em;'>\n", FILE_SEARCH); -printf("<input type='button' name='clear' value='clear' class='clear' style='font-size:.8em;' " - "onclick='findTracks.clear();'>\n"); +printf("<input type='button' name='clear' id='clear' value='clear' class='clear' style='font-size:.8em;'>\n"); +jsOnEventById("click", "clear", "findTracks.clear();"); printf("<input type='submit' name='submit' value='cancel' class='cancel' " "style='font-size:.8em;'>\n"); printf("</div>\n"); #ifdef USE_TABS printf("</div>\n"); // End tabs div #endif///def USE_TABS if (nameSearch != NULL && !strlen(nameSearch)) nameSearch = NULL; if (descSearch != NULL && !strlen(descSearch)) descSearch = NULL; if (groupSearch != NULL && sameString(groupSearch, ANYLABEL)) groupSearch = NULL; @@ -436,32 +438,32 @@ trackHash = trackHashMakeWithComposites(db,chrom,&tdbList,FALSE); cartWebStart(cart, db, "Search for " FILE_SEARCH_WHAT " in the %s %s Assembly", organism, hFreezeFromDb(db)); webIncludeResourceFile("HGStyle.css"); webIncludeResourceFile("jquery-ui.css"); webIncludeResourceFile("ui.dropdownchecklist.css"); jsIncludeFile("jquery.js", NULL); jsIncludeFile("jquery-ui.js", NULL); jsIncludeFile("ui.dropdownchecklist.js",NULL); jsIncludeFile("utils.js",NULL); // This line is needed to get the multi-selects initialized jsIncludeFile("ddcl.js",NULL); -printf("<script type='text/javascript'>$(document).ready(function() " - "{ findTracks.updateMdbHelp(0); });</script>\n"); +jsInline("$(document).ready(function() " + "{ findTracks.updateMdbHelp(0); });\n"); doFileSearch(db,organism,cart,tdbList); printf("<BR>\n"); webEnd(); } char *excludeVars[] = { "submit", "Submit", "g", "ajax", "clearCache", FILE_SEARCH,TRACK_SEARCH_ADD_ROW,TRACK_SEARCH_DEL_ROW}; int main(int argc, char *argv[]) /* Process command line. */ { long enteredMainTime = clock1000();