MISC security fixes

Stuff that I've had for ages locally... and that should probably get in the next release.