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/hgSession/hgSession.c src/hg/hgSession/hgSession.c index 2610a77..8a6e0ca 100644 --- src/hg/hgSession/hgSession.c +++ src/hg/hgSession/hgSession.c @@ -261,42 +261,44 @@ void showExistingSessions(char *userName) /* Print out a table with buttons for sharing/unsharing/loading/deleting * previously saved sessions. */ { struct sqlConnection *conn = hConnectCentral(); struct sqlResult *sr = NULL; char **row = NULL; char query[512]; boolean foundAny = FALSE; char *encUserName = cgiEncodeFull(userName); boolean gotSettings = (sqlFieldIndex(conn, namedSessionTable, "settings") >= 0); /* DataTables configuration: only allow ordering on session name, creation date, and database. * https://datatables.net/reference/option/columnDefs */ -printf ("\n", jsDataTableStateSave(hgSessionPrefix), jsDataTableStateLoad(hgSessionPrefix, cart)); + , jsDataTableStateSave(hgSessionPrefix), jsDataTableStateLoad(hgSessionPrefix, cart)); +jsInline(javascript); printf("
session name (click to load) | created on | assembly | " "view/edit details | "
"delete this session | share with others? | "
"post in public listing? | "
"send to | ",
cartSidUrlString(cart));
printf(""); safef(buf, sizeof(buf), "%s%s", hgsDeletePrefix, encSessionName); char command[512]; safef(command, sizeof(command), confirmDeleteFormat, encSessionName); cgiMakeOnClickSubmitButton(command, buf, "delete"); printf(" | "); safef(buf, sizeof(buf), "%s%s", hgsSharePrefix, encSessionName); - cgiMakeCheckBoxJS(buf, shared>0, "onchange=\"console.log('new status' + this.checked); document.mainForm.submit();\""); + cgiMakeCheckBoxWithId(buf, shared>0, buf); + jsOnEventById("change",buf,"console.log('new status' + this.checked); document.mainForm.submit();"); printf(" | "); safef(buf, sizeof(buf), "%s%s", hgsGalleryPrefix, encSessionName); - cgiMakeCheckBoxFourWay(buf, inGallery, shared>0, NULL, NULL, - "onchange=\"document.mainForm.submit();\""); + cgiMakeCheckBoxFourWay(buf, inGallery, shared>0, buf, NULL, NULL); + jsOnEventById("change", buf, "document.mainForm.submit();"); link = getSessionEmailLink(encUserName, encSessionName); printf(" | %s | ", link); freez(&link); foundAny = TRUE; struct slName *sn = slNameNew(sessionName); slAddHead(&existingSessionNames, sn); } if (!foundAny) printf("
(none) | " "
Use settings from a local file: | \n"); -printf("\n", - hgsLoadLocalFileName); +printf(" | \n", hgsLoadLocalFileName, hgsLoadLocalFileName); +jsOnEventById("keypress", hgsLoadLocalFileName,"return noSubmitOnEnter(event);"); printf(" "); cgiMakeButton(hgsDoLoadLocal, "submit"); printf(" | |
Use settings from a URL (http://..., ftp://...):" " | \n"); printf("\n"); cgiMakeOnKeypressTextVar(hgsLoadUrlName, cartUsualString(cart, hgsLoadUrlName, ""), 20, jsPressOnEnter(hgsDoLoadUrl)); printf(" "); cgiMakeButton(hgsDoLoadUrl, "submit"); printf(" |
\n" "
\n"); sqlFreeResult(&sr); } else errAbort("doSessionDetail: got no results from query: