First, I have to ask ... what do you really mean by "AntiForgery"? What bothers you that you are faked? The rest of the following follows only some general information that appears in memory ...
One thing I would change is not to use Guid.NewGuid. There is debate about whether this is random or not, and therefore not suitable for security purposes. However, I think it would be very difficult to attack.
Look at the RNGCryptoServiceProvider for the GetBytes method for something that should be better for creating a random token. In addition to the best chance, another advantage of this is that you can make it no matter what size you want.
Do you do this via ssl? First, ssl is the number one line of defense for a person in medium attacks. It may not be safe enough (and others may discuss it) for every need, but if you are concerned about such things, this is the starting point, if nothing else. If not, how do you guarantee that you will receive a response from the right machine, not the person in the middle who answers first? Without SSL or equivalent, your token is just as easily stolen as anything you do.
Another thing to consider when adding is that your tokens can only be good for one trip, and you are creating a new one for the client on the next trip. The reuse attempt does not work.
I would not try to replace SSL with something else of my own trick, if that is what you are thinking about. If you are worried about replaying, a one-time marker is one way to stop it. If you are worried that the user submits the same form data twice, this is one thing. I would also consider your overall application design if this bothers you. Many repetition and similar scenarios can be defeated by the sound design of your business logic, for example, not trusting the client to send you confidential information, such as the price of the product in the shopping cart.
As a starting point, also check out the various Microsoft ASP.NET and IIS security guides (for example, the Google ASP.NET website or IIS website: microsoft.com). Many smart people have solved many problems already for us.
Jim l
source share