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/hgc/bigBedClick.c src/hg/hgc/bigBedClick.c index 73de5ea..8d016a0 100644 --- src/hg/hgc/bigBedClick.c +++ src/hg/hgc/bigBedClick.c @@ -161,41 +161,42 @@ } // print link to location printf("<td><a href='%s&db=%s&position=%s%%3A%d-%d'>%s:%d (%c)</a></td>\n", hgTracksPathAndSettings(), database, chrom, pos+1, pos+23, chrom, pos+1, strand); printf("</tr>\n"); } hFreeConn(&conn); printf("<tr>\n"); if (coordCount!=0) printf("</table>\n"); if (collapsed) { - printf("<p><a id='crisprShowAllLink' href='#' onclick='crisprShowAll(); return false;'>" + printf("<p><a id='crisprShowAllLink' href='#'>" "Show all %d off-targets...</a>\n", coordCount); + jsOnEventById("click", "crisprShowAllLink", "crisprShowAll(); return false;"); // inline .js is bad style but why pollute our global .js files for such a rare // case? Maybe we should have a generic "collapsible" class, like bootstrap? - printf("<script>\n"); - printf("function crisprShowAll() {\n"); - printf(" $('#crisprShowAllLink').hide();\n"); - printf(" $('.crisprLinkHidden').show();\n"); - printf(" return false;\n"); - printf("}\n"); - printf("</script>\n"); + jsInline( + "function crisprShowAll() {\n" + " $('#crisprShowAllLink').hide();\n" + " $('.crisprLinkHidden').show();\n" + " return false;\n" + "}\n" + ); } } static void detailsTabPrintSpecial(char *name, char *val, struct slPair *extraFields) /* some extra fields require special printing code, they all start with '_' */ { if (sameWord(name, "_mismatchCounts")) extFieldMismatchCounts(val); else if (sameWord(name, "_crisprOfftargets")) extFieldCrisprOfftargets(val, extraFields); } static void seekAndPrintTable(char *url, off_t offset, struct slPair *extraFields) /* seek to 0 at url, get headers, then seek to offset, read tab-sep fields and output * (extraFields are needed for some special field handlers) */