CE-1175 Fix various XSS vulnerabilities

Fix various XSS vulnerabilities through proper sanitization. See the individual commits
for descriptions of the issues and fixes.

/cc @owend