CRM-15247 - AJAX Fixups

Improve handling of untrusted inputs.