Added test and code to prevent cookie sniffing