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/lib/hPrint.c src/hg/lib/hPrint.c
index 9256da5..0e52fd3 100644
--- src/hg/lib/hPrint.c
+++ src/hg/lib/hPrint.c
@@ -1,192 +1,192 @@
 /* hPrint - turning html printing on and off, which is useful
  * when postscript and PDF images are being drawn  */
 
 /* Copyright (C) 2014 The Regents of the University of California 
  * See README in this or parent directory for licensing information. */
 
 #include "hPrint.h"
 #include "htmshell.h"
 
 
 static boolean suppressHtml = FALSE;
 /* If doing PostScript output we'll suppress most of HTML output. */
 
 boolean hPrintStatus()
 /* is html printing on or off ?
    return TRUE for print is on, FALSE for printing is off */
 {
 return ! suppressHtml;
 }
 
 void hPrintDisable()
 /* turn html printing off */
 {
 suppressHtml = TRUE;
 }
 
 void hPrintEnable()
 /* turn html printing on */
 {
 suppressHtml = FALSE;
 }
 
 void hvPrintf(char *format, va_list args)
 /* Suppressable variable args printf. Check for write error so we can
  * terminate if http connection breaks. */
 {
 if (suppressHtml)
     return;
 vprintf(format, args);
 if (ferror(stdout))
     noWarnAbort();
 }
 
 void hPrintf(char *format, ...)
 /* Printf that can be suppressed if not making html. */
 {
 va_list(args);
 va_start(args, format);
 hvPrintf(format, args);
 va_end(args);
 }
 
 void hPrintNonBreak(char *s)
 /* Print out string but replace spaces with   */
 {
 char c;
 
 if (suppressHtml)
     return;
 while ((c = *s++) != '\0')
     if (c == ' ')
 	fputs(" ", stdout);
     else
         putchar(c);
 }
 
 void hPrintEncodedNonBreak(char *s)
 /* Print with htmlEncode and non-break */
 {
 char *encoded = htmlEncode(s);
 hPrintNonBreak(encoded);
 freeMem(encoded);
 }
 
 void hPuts(char *string)
 /* Puts that can be suppressed if not making html. */
 {
 if (!suppressHtml)
     puts(string);
 }
 
 void hPutc(char c)
 /* putc that can be suppressed if not making html. */
 {
 if (!suppressHtml)
     fputc(c, stdout);
 }
 
 void hWrites(char *string)
 /* Write string with no '\n' if not suppressed. */
 {
 if (!suppressHtml)
     fputs(string, stdout);
 }
 
 void hButton(char *name, char *label)
 /* Write out button if not suppressed. */
 {
 if (!suppressHtml)
     cgiMakeButton(name, label);
 }
 
 void hButtonWithMsg(char *name, char *label, char *msg)
 /* Write out button with msg if not suppressed. */
 {
 if (!suppressHtml)
     cgiMakeButtonWithMsg(name, label, msg);
 }
 
 void hButtonWithOnClick(char *name, char *label, char *msg, char *onClick)
 /* Write out button with onclick javascript if not suppressed. */
 {
 if (!suppressHtml)
     cgiMakeButtonWithOnClick(name, label, msg, onClick);
 }
 
-void hOnClickButton(char *command, char *label)
+void hOnClickButton(char *id, char *command, char *label)
 /* Write out push button if not suppressed. */
 {
 if (!suppressHtml)
-    cgiMakeOnClickButton(command, label);
+    cgiMakeOnClickButton(id, command, label);
 }
 
 void hTextVar(char *varName, char *initialVal, int charSize)
 /* Write out text entry field if not suppressed. */
 {
 if (!suppressHtml)
     cgiMakeTextVar(varName, initialVal, charSize);
 }
 
 void hIntVar(char *varName, int initialVal, int maxDigits)
 /* Write out numerical entry field if not supressed. */
 {
 if (!suppressHtml)
     cgiMakeIntVar(varName, initialVal, maxDigits);
 }
 
 void hDoubleVar(char *varName, double initialVal, int maxDigits)
 /* Write out numerical entry field if not supressed. */
 {
 if (!suppressHtml)
     cgiMakeDoubleVar(varName, initialVal, maxDigits);
 }
 
 void hCheckBox(char *varName, boolean checked)
 /* Make check box if not suppressed. */
 {
 if (!suppressHtml)
     cgiMakeCheckBox(varName, checked);
 }
 
 void hCheckBoxJS(char *varName, boolean checked, char *javascript)
 /* Make check box if not suppressed, with javascript. */
 {
 if (!suppressHtml)
     cgiMakeCheckBoxJS(varName, checked, javascript);
 }
 
 void hDropListClassWithStyle(char *name, char *menu[], int menuSize, 
                                 char *checked, char *class, char *style)
 /* Make a drop-down list with names if not suppressed, 
  * using specified class and style */
 {
 if (!suppressHtml)
     cgiMakeDropListClassWithStyle(name, menu, menuSize, checked, class, style);
 }
 
 void hDropListClass(char *name, char *menu[], int menuSize, char *checked,
                         char *class)
 /* Make a drop-down list with names if not suppressed, using specified class. */
 {
 hDropListClassWithStyle(name, menu, menuSize, checked, class, NULL);
 }
 
 void hDropList(char *name, char *menu[], int menuSize, char *checked)
 /* Make a drop-down list with names if not suppressed. */
 {
 hDropListClass(name, menu, menuSize, checked, NULL);
 }
 
 void hPrintComment(char *format, ...)
 /* Function to print output as a comment so it is not seen in the HTML
  * output but only in the HTML source. */
 {
 va_list(args);
 va_start(args, format);
 hWrites("\n<!-- DEBUG: ");
 hvPrintf(format, args);
 hWrites(" -->\n");
 fflush(stdout); /* USED ONLY FOR DEBUGGING BECAUSE THIS IS SLOW - MATT */
 va_end(args);
 }