[WIP] CSRF refactoring

Work in progress.

I have to go away for a moment.
I will add some commit later in the week.

First feedbacks are welcome