Backport jwise's security fixes to 0.9.9