security::csrf::validate (public)
security::csrf::validate [ -tokenname tokenname ] \
[ -allowempty allowempty ]Defined in packages/acs-tcl/tcl/security-procs.tcl
Validate a CSRF token and call security::csrf::fail the request if invalid.
- Switches:
- -tokenname (optional, defaults to
"__csrf_token")- -allowempty (optional, defaults to
"false")- Returns:
- nothing
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- create_workflow_with_instance
Source code: if {![info exists ::$tokenname] || ![ns_conn isconnected]} { # # If there is no global CSRF token, or we are not in a # connection thread, we accept everything. If there is # no CSRF token, we assume, that its generation is # deactivated, # return } set oldToken [ns_queryget $tokenname] # Temporary diagnostic for the anonymous registration POST. if {$tokenname eq "__csrf_token" && [ns_conn method] eq "POST" && [ns_conn url] eq "/demo/xxx/register/user-new"} { set diagnostic_binding [expr { [ad_conn untrusted_user_id] == 0 ? "peer" : "session" }] set diagnostic_present [expr {$oldToken ne ""}] set diagnostic_match "not-checked" if {$diagnostic_present} { set diagnostic_match [expr { $oldToken eq [token -tokenname $tokenname] }] } ns_log Notice "registration CSRF diagnostic" binding $diagnostic_binding token_present $diagnostic_present token_match $diagnostic_match } if {$oldToken eq ""} { # # There is no token in the query/form parameters, we # can't validate, since there is no token. # if {$allowempty} { return } fail } set token [token -tokenname $tokenname] if {$oldToken ne $token} { ::security::log session_id "CSRF old token <$oldToken> new token <$token> peeraddr [ad_conn peeraddr]" fail }Generic XQL file: packages/acs-tcl/tcl/security-procs.xql
PostgreSQL XQL file: packages/acs-tcl/tcl/security-procs-postgresql.xql
Oracle XQL file: packages/acs-tcl/tcl/security-procs-oracle.xql