security::safe_tmpfile_p (public)

 security::safe_tmpfile_p [ -must_exist ] tmpfile

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

Checks that a file is a safe tmpfile, that is, it belongs to the configured tmpdir. When the file exists, we also enforce additional criteria: - file must belong to the current system user - file must be readable and writable by the current system user

Switches:
-must_exist (optional, boolean)
make sure the file exists
Parameters:
tmpfile (required)
absolute path to a possibly existing tmpfile
Returns:
boolean

Partial Call Graph (max 5 caller/called nodes):
%3 test_safe_tmpfile_p safe_tmpfile_p (test acs-tcl) security::safe_tmpfile_p security::safe_tmpfile_p test_safe_tmpfile_p->security::safe_tmpfile_p ad_file ad_file (public) security::safe_tmpfile_p->ad_file ad_page_contract_filter_proc_tmpfile ad_page_contract_filter_proc_tmpfile (public) ad_page_contract_filter_proc_tmpfile->security::safe_tmpfile_p template::data::validate::file template::data::validate::file (public) template::data::validate::file->security::safe_tmpfile_p

Testcases:
safe_tmpfile_p
Source code:
    #
    # Ensure no ".." in the path
    #
    set tmpfile [ns_normalizepath $tmpfile]
    set tmpdir [string trimright [ns_config ns/parameters tmpdir] /]

    if {[ad_file dirname $tmpfile] ne $tmpdir} {
        #
        # File is not a direct child of the tmpfolder: not safe
        #
        return false
    }

    if {![ad_file exists $tmpfile]} {
        #
        # File does not exist yet: safe, unless we demand for the file
        # to exist.
        #
        return [expr {!$must_exist_p}]
    }

    if {![ad_file owned $tmpfile]} {
        #
        # File does not belong to us: not safe
        #
        return false
    }

    if {![ad_file readable $tmpfile]} {
        #
        # We cannot read the file: not safe
        #
        return false
    }

    if {![ad_file writable $tmpfile]} {
        #
        # We cannot write the file: not safe
        #
        return false
    }

    #
    # The file is safe
    #
    return true
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: