Fix bad_cookies Error

Backport of f2a44528825ac07ca28c8bb7dc01b4375df8dc2c