security::csrf::new (public)

 security::csrf::new [ -tokenname tokenname ] [ -user_id user_id ]

Defined in packages/acs-tcl/tcl/security-procs.tcl

Create a security token to protect against CSRF (Cross-Site Request Forgery). The token is set (and cached) in a global per-thread variable and can be included in forms e.g. via the following command.

        <if @::__csrf_token@ defined>
            <input type="hidden" name="__csrf_token" value="@::__csrf_token;literal@">
        </if>

The token is automatically cleared together with other global variables at the end of the processing of every request.

The optional argument user_id is currently ignored, but it is there, since there are algorithms published to calculate the CSRF token based on a user_id. So far, i found no evidence that these should be used, but the argument is there as a reminder, such the interface does not have to be used, when we switch to such an algorithm.

Switches:
-tokenname (optional, defaults to "__csrf_token")
-user_id (optional)
Returns:
CSRF token
Author:
Gustaf Neumann

Partial Call Graph (max 5 caller/called nodes):
__ad_verify_signature __ad_verify_signature (private) security::csrf::new security::csrf::new __ad_verify_signature->security::csrf::new ad_sign ad_sign (public) ad_sign->security::csrf::new packages/acs-admin/www/users/password-reset.tcl packages/acs-admin/ www/users/password-reset.tcl packages/acs-admin/www/users/password-reset.tcl->security::csrf::new packages/acs-subsite/www/register/verify-password-setup.tcl packages/acs-subsite/ www/register/verify-password-setup.tcl packages/acs-subsite/www/register/verify-password-setup.tcl->security::csrf::new packages/acs-subsite/www/shared/richtext-format.tcl packages/acs-subsite/ www/shared/richtext-format.tcl packages/acs-subsite/www/shared/richtext-format.tcl->security::csrf::new ad_conn ad_conn (public) security::csrf::new->ad_conn security::csrf::token security::csrf::token (private) security::csrf::new->security::csrf::token

Testcases:
No testcase defined.
Source code:
        set globalTokenName ::$tokenname
        if {[info exists $globalTokenName] && [set $globalTokenName] ne ""} {
            return [set $globalTokenName]
        }

        set token [token -tokenname $tokenname]
if {$tokenname eq "__csrf_token"
    && [ns_conn isconnected]
    && [ns_conn method] eq "GET"
    && [ns_conn url] eq "/demo/xxx/register/user-new"} {
    set diagnostic_binding [expr {
        [ad_conn untrusted_user_id] == 0 ? "peer" : "session"
    }]
    ns_log Notice "registration CSRF diagnostic"  binding $diagnostic_binding  token_generated [expr {$token ne ""}]
}
        return [set $globalTokenName $token]
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

[ hide source ] | [ make this the default ]
Show another procedure: