Add safe cookie auth with modified code from Yawning Angel