Index: openacs-4/packages/acs-api-browser/tcl/acs-api-documentation-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-api-browser/tcl/acs-api-documentation-procs.tcl,v diff -u -r1.27.8.23 -r1.27.8.24 --- openacs-4/packages/acs-api-browser/tcl/acs-api-documentation-procs.tcl 11 Sep 2014 08:01:04 -0000 1.27.8.23 +++ openacs-4/packages/acs-api-browser/tcl/acs-api-documentation-procs.tcl 14 Sep 2014 09:02:41 -0000 1.27.8.24 @@ -1285,7 +1285,6 @@ Returns list of xql files related to tcl script file @param path path and filename from $::acs::rootdir - } { set linkList [list] @@ -1310,6 +1309,35 @@ return $linkList } + + ad_proc -private sanitize_path { {-prefix packages} path } { + + Return a sanitized path. Cleans path from directory traversal + attacks and checks, if someone tries to access content outside + of the specified prefix. + + @return sanitized path + } { + + if {[regsub -all {[.][.]/} $path "" shortened_path]} { + set filename "$::acs::rootdir/$path" + ns_log notice [subst {INTRUDER ALERT:\n\nsomesone tried to snarf '$filename'! + file exists: [file exists $filename] user_id: [ad_conn user_id] peer: [ad_conn peeraddr] + }] + set path $shortened_path + } + + if {![string match "$prefix/*" $path]} { + set filename "$::acs::rootdir/$path" + ns_log notice [subst {INTRUDER ALERT:\n\nsomesone tried to snarf '$filename'! + file exists: [file exists $filename] user_id: [ad_conn user_id] peer: [ad_conn peeraddr] + }] + + set path $prefix/$path + } + + return $path + } } @@ -1343,7 +1371,6 @@ } - # # Local variables: # mode: tcl