webmcp
view framework/env/request/set_csrf_secret.lua @ 31:1cd9e69b85cb
add execute.load_chunk(args)
load_chunk loads the content of a lua file and returns the code.
It can construct the path name easily so you can put helper code in
seperate files for DRYness.
load_chunk loads the content of a lua file and returns the code.
It can construct the path name easily so you can put helper code in
seperate files for DRYness.
| author | Daniel Poelzleithner <poelzi@poelzi.org> | 
|---|---|
| date | Tue Oct 05 02:34:04 2010 +0200 (2010-10-05) | 
| parents | 9fdfb27f8e67 | 
| children | 32ec28229bb5 | 
 line source
     1 --[[--
     2 request.set_csrf_secret(
     3   secret                 -- secret random string
     4 )
     6 Sets a secret string to be used as protection against cross-site request forgery attempts. This string will be transmitted to each action via a hidden form field named "_webmcp_csrf_secret". If this function is called during an action, and there is no CGI GET/POST parameter "_webmcp_csrf_secret" already being set to the given secret, then an error will be thrown to prohibit execution of the action.
     8 --]]--
    10 function request.set_csrf_secret(secret)
    11   if
    12     request.get_action() and
    13     cgi.params._webmcp_csrf_secret ~= secret
    14   then
    15     error("Cross-Site Request Forgery attempt detected");
    16   end
    17   request._csrf_secret = secret
    18 end
