XSS audit 609

This goes some way towards addressing the problems noted in #609. There are more, but I think most are in things we got from Blacklight, and which aren't really being used: I wouldn't want to make changes there until we know that we need that code, and it's actually being run.