csrf defence
(cherry picked from commit 95b99af)
(cherry picked from commit 93c048b)
csrf defence fix
(cherry picked from commit f528e1f)