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/cart.c src/hg/lib/cart.c
index 7a9f655..3cd84a2 100644
--- src/hg/lib/cart.c
+++ src/hg/lib/cart.c
@@ -1369,31 +1369,31 @@
cgiMakeHiddenVar(sessionVar, cartSessionId(cart));
}
static void cartDumpItem(struct hashEl *hel,boolean asTable)
/* Dump one item in cart hash */
{
char *var = htmlEncode(hel->name);
char *val = htmlEncode((char *)(hel->val));
if (asTable)
{
printf("
%s | ", var);
int width=(strlen(val)+1)*8;
if (width<100)
width = 100;
cgiMakeTextVarWithExtraHtml(hel->name, val, width,
- "onchange='setCartVar(this.name,this.value);'");
+ "change", "setCartVar(this.name,this.value);");
printf(" |
\n");
}
else
printf("%s %s\n", var, val);
freeMem(var);
freeMem(val);
}
void cartDumpList(struct hashEl *elList,boolean asTable)
/* Dump list of cart variables optionally as a table with ajax update support. */
{
struct hashEl *el;
if (elList == NULL)
@@ -1641,35 +1641,37 @@
return cartAndCookieWithHtml(cookieName, exclude, oldVars, TRUE);
}
struct cart *cartAndCookieNoContent(char *cookieName, char **exclude,
struct hash *oldVars)
/* Load cart from cookie and session cgi variable. Don't write out
* content type or any HTML. */
{
return cartAndCookieWithHtml(cookieName, exclude, oldVars, FALSE);
}
static void cartErrorCatcher(void (*doMiddle)(struct cart *cart),
struct cart *cart)
/* Wrap error catcher around call to do middle. */
{
-int status = setjmp(htmlRecover);
pushAbortHandler(htmlAbort);
hDumpStackPushAbortHandler();
+int status = setjmp(htmlRecover);
if (status == 0)
+ {
doMiddle(cart);
+ }
hDumpStackPopAbortHandler();
popAbortHandler();
}
void cartEarlyWarningHandler(char *format, va_list args)
/* Write an error message so user can see it before page is really started. */
{
static boolean initted = FALSE;
va_list argscp;
va_copy(argscp, args);
if (!initted)
{
htmStart(stdout, "Early Error");
initted = TRUE;
}