If you donβt care that the clients do not work in the browser, you can use XSRF tokens, a secret session associated with a session key in your backend or in a round-robin way using two separate paths, both through hidden form input and a cookie through secure channel. If you cannot protect the channel, you must make the tokens one-time. See http://www.cgisecurity.com/csrf-faq.html#protectapp
You cannot in the general case. A smart intelligent hacker can probably recycle any protocol you use and extract any secrets that you insert into the source code.
source share