Bt 87 security fixes

Fix security vulnerabilities defined in ticket #87.