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/hgTrackUi/hgTrackUi.c src/hg/hgTrackUi/hgTrackUi.c
index 5651716..0929350 100644
--- src/hg/hgTrackUi/hgTrackUi.c
+++ src/hg/hgTrackUi/hgTrackUi.c
@@ -600,42 +600,42 @@
if (version <= 127)
{
labels = snp125ColorSourceLabels;
arraySize = snp125ColorSourceArraySize;
}
else if (version <= 131)
{
labels = snp128ColorSourceLabels;
arraySize = snp128ColorSourceArraySize;
}
// It would be preferable for Javascript to handle changing the color selection
// menus when the color source selection changes, but for now we do a submit that
// returns to the current vertical position:
char autoSubmit[2048];
-safef(autoSubmit, sizeof(autoSubmit), "onchange=\""
+safef(autoSubmit, sizeof(autoSubmit), ""
"document."MAIN_FORM".action = '%s'; %s"
- "document."MAIN_FORM".submit();\"",
+ "document."MAIN_FORM".submit();",
cgiScriptName(), jsSetVerticalPosition(MAIN_FORM));
cgiContinueHiddenVar("g");
cgiContinueHiddenVar("c");
char cartVar[512];
safef(cartVar, sizeof(cartVar), "%s.colorSource", tdb->track);
enum snp125ColorSource colorSourceCart = snp125ColorSourceFromCart(cart, tdb);
char *colorSourceSelected = snp125ColorSourceToLabel(tdb, colorSourceCart);
-cgiMakeDropListFull(cartVar, labels, labels, arraySize, colorSourceSelected, autoSubmit);
+cgiMakeDropListFull(cartVar, labels, labels, arraySize, colorSourceSelected, "change", autoSubmit);
printf(" \n");
char javascript[2048];
safef(javascript, sizeof(javascript),
"document."MAIN_FORM".action='%s'; %s document."MAIN_FORM".submit();",
cgiScriptName(), jsSetVerticalPosition(MAIN_FORM));
cgiMakeOnClickSubmitButton(javascript, defaultButtonVar, JS_DEFAULTS_BUTTON_LABEL);
printf("
\n"
"The selected "Feature for Color Specification" above has the\n"
"selection of colors below for each attribute. Only the color\n"
"options for the feature selected above will be used to color items;\n"
"color options for other features will not be shown.\n");
if (version > 127 && colorSourceCart == snp125ColorSourceLocType)
colorSourceCart = SNP125_DEFAULT_COLOR_SOURCE;
switch (colorSourceCart)
@@ -2247,40 +2247,41 @@
printf("Color sequence matches by ");
char *colorText[3] = {"topic", "impact of journal", "year"};
char *colorVals[3] = {"topic", "impact", "year"};
safef(cgiVar,sizeof(cgiVar),"%s.%s",tdb->track,PUBS_COLORBY_TAG);
cgiDropDownWithTextValsAndExtra(cgiVar, colorText, colorVals, 3, colorBy, NULL);
puts("
Short (2-30 base) sequence:"); -puts(""); -printf("", \ - oligoMatchVar, 45, oligo); +char *javascript = +"function packTrack()\n" +"{\n" +"var box = jQuery('select[name$=oligoMatch]');\n" +"if (box.val()=='hide')\n" +" box.val('pack');\n" +"}\n"; +jsInline(javascript); +printf("", + oligoMatchVar, oligoMatchVar, 45, oligo); +jsOnEventById("input", oligoMatchVar, "packTrack();"); } void cutterUi(struct trackDb *tdb) /* UI for restriction enzyme track */ { char *enz = cartUsualString(cart, cutterVar, cutterDefault); puts("
Filter display by enzymes (separate with commas):
");
cgiMakeTextVar(cutterVar, enz, 100);
}
void genericWiggleUi(struct trackDb *tdb, int optionNum )
/* put up UI for any standard wiggle track (a.k.a. sample track)*/
{
char options[7][256];
@@ -2723,103 +2724,88 @@
#ifdef UNUSED
static boolean isInTrackList(struct trackDb *tdbList, struct trackDb *target)
/* Return TRUE if target is in tdbList. */
{
struct trackDb *tdb;
for (tdb = tdbList; tdb != NULL; tdb = tdb->next)
if (tdb == target)
return TRUE;
return FALSE;
}
#endif /* UNUSED */
void superTrackUi(struct trackDb *superTdb, struct trackDb *tdbList)
/* List tracks in this collection, with visibility controls and UI links */
{
-#define SUPERS_WITH_CHECKBOXES
-#ifdef SUPERS_WITH_CHECKBOXES
-#define PM_BUTTON_GLOBAL ""
-#define BUTTON_PLUS_SUPER() printf(PM_BUTTON_GLOBAL,"true", "plus_all", "add_sm.gif")
-#define BUTTON_MINUS_SUPER() printf(PM_BUTTON_GLOBAL,"false","minus_all","remove_sm.gif")
jsIncludeFile("hui.js",NULL);
-#endif///def SUPERS_WITH_CHECKBOXES
printf("\n
");
- BUTTON_PLUS_SUPER();
- BUTTON_MINUS_SUPER();
+ printf("![]() ![]() "); printf(" | ||
"); if (!tdbIsDownloadsOnly(tdb)) { + char id[256]; enum trackVisibility tv = hTvFromString(cartUsualString(cart, tdb->track,hStringFromTv(tdb->visibility))); // Don't use cheapCgi code... no name and no boolshad... just js - printf("", + printf("", tdb->track, (tv != tvHide?" CHECKED":"")); + safef(id, sizeof id, "%s", tdb->track); + safef(javascript, sizeof javascript, "superT.childChecked(this);"); + jsOnEventById("change", id, javascript); // TODO XSS Filter track as id? + + + safef(javascript, sizeof(javascript), "superT.selChanged(this)"); + struct slPair *event = slPairNew("change", cloneString(javascript)); hTvDropDownClassVisOnlyAndExtra(tdb->track, tv, tdb->canPack, (tv == tvHide ? "hiddenText":"normalText"), trackDbSetting(tdb, "onlyVisibility"), - "onchange='superT.selChanged(this);'"); + event); + printf(" | \n"); - printf("" + safef(id, sizeof id, "%s_link", tdb->track); + printf("" "%s ", (tdbIsDownloadsOnly(tdb)? hgFileUiName(): hgTrackUiName()), cartSessionVarName(), cartSessionId(cart), - chromosome, cgiEncode(tdb->track), tdb->shortLabel); + chromosome, cgiEncode(tdb->track), id, tdb->shortLabel); + safef(javascript, sizeof(javascript), "superT.submitAndLink(this);"); + jsOnEventById("click", id, javascript); // TODO XSS Filter track as id? } else { printf("Downloads", hgFileUiName(),cartSessionVarName(), cartSessionId(cart), cgiEncode(tdb->track)); printf(" | \n"); printf("%s ",tdb->shortLabel); } printf(" | \n"); - #else///ifndef SUPERS_WITH_CHECKBOXES - printf("
"); - if (tdbIsDownloadsOnly(tdb)) - printf("%s ",tdb->shortLabel); - else - printf("%s ", - (tdbIsDownloadsOnly(tdb)? hgFileUiName(): hgTrackUiName()), - cartSessionVarName(), cartSessionId(cart), - chromosome, cgiEncode(tdb->track), tdb->shortLabel); - printf(" | "); - if (tdbIsDownloadsOnly(tdb)) - { - printf("Downloads", - hgFileUiName(),cartSessionVarName(), cartSessionId(cart), cgiEncode(tdb->track)); - } - else - { - enum trackVisibility tv = - hTvFromString(cartUsualString(cart, tdb->track, hStringFromTv(tdb->visibility))); - hTvDropDownClassVisOnly(tdb->track, tv, tdb->canPack, - tv == tvHide ? "hiddenText" : "normalText", - trackDbSetting(tdb, "onlyVisibility")); - } - #endif///ndef SUPERS_WITH_CHECKBOXES printf(" | %s", tdb->longLabel); char *dataVersion = trackDbSetting(tdb, "dataVersion"); if (dataVersion) printf("  %s", dataVersion); printf(" |