Tk Library Source Code

View Ticket
Login
Ticket UUID: 1110076
Title: 'jail' filenames
Type: RFE Version: None
Submitter: davidw Created on: 2005-01-26 17:44:36
Subsystem: fileutil Assigned To: andreas_kupries
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2005-02-09 12:52:57
Resolution: Closed By: andreas_kupries
    Closed on: 2005-02-09 05:52:57
Description:
One of the uses of commands such as stripPwd is as part
of a system to 'jail' filenames in a certain directory.

A 'jail' command that prevents URLs from escaping from
that directory would be useful.  It would work
something like this:

fileutil::jail /var/www/ $somefile

and returns an absolute pathname within /var/www

$somefile is turned into a nativename

if $somefile starts with /var/www, the filename is
returned.

otherwise, $somefile is appended to the 'jail', /var/www
User Comments: andreas_kupries added on 2005-02-09 12:52:57:
Logged In: YES 
user_id=75003

Implementation, documentation and tests committed to head.

andreas_kupries added on 2005-02-03 05:38:41:
Logged In: YES 
user_id=75003

Chat

14:27]<davidw>aku: to take out all the ../../ stuff
[14:27]akuOk.
[14:28]akuWe should mention that explicitly in the docs,
as security measure. You cannot escape using ..
[14:28]akuIt will block symlinks trying to escape as well,
right ?
[14:28]<davidw>it should

andreas_kupries added on 2005-02-03 05:26:12:
Logged In: YES 
user_id=75003

Ok, then. Why 'normalize' ?
I believe to know, would like a confirmation.

davidw added on 2005-02-03 05:11:32:
Logged In: YES 
user_id=240

Uhrm... I meant the next one down... 'normalize'.  Woops.

andreas_kupries added on 2005-02-02 13:44:38:
Logged In: YES 
user_id=75003

Why turning $somefile into a nativename ?

davidw added on 2005-01-27 01:07:13:
Logged In: YES 
user_id=240

One implementation of that is:

proc fileutil::jail {jail filename} {
    set sjail [file split [file nativename $jail]]
    if  { ! [string equal [file pathtype [file join $sjail]]
"absolute"] } {
error "$jail must be an absolute path"
    }
    set sfilename [file split [file nativename $filename]]

    if {[string match ${sjail}* $sfilename]} {
set path $sfilename
    } else {
set path [concat $sjail $sfilename]
    }
    return [eval file join $path]
}