Reputation: 12828
Are there any transparent library that I can use or something easy so I can prevent cross-site request forgery (CSRF) with Perl and Apache? How can I generate tokens for forms and validating them server-side?
Upvotes: 3
Views: 3649
Reputation: 7392
To protect from "Cross-site request forgery" from server side, it is best to:
Doing this is framework specific but simple.
Upvotes: -1
Reputation: 364687
Have a look at what CGI::Application::Plugin::ProtectCSRF does. This module is for the CGI::Application framework.
It shouldn't be too hard to modify the module for other frameworks. Basically, user forms get a hidden HTML field added with the generated token, and the session object gets the same token. When the form is submitted, the form-submitted token is compared to the token in the session object (which is on the server). If they don't match, a CSRF has likely occurred.
There is also a Catalyst plugin: Catalyst::Controller::RequestToken
These modules use attribute handlers so there is very little modification required to your existing app.
Upvotes: 10