Artifacts Associated With Ticket 3118489fffffffff
Ticket change [22ad1c705b] (rid 130794) by andygoth on 2010-11-25 14:51:20:
- assignee initialized to: "vincentdarley"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Some file commands treat NUL (\0) as a string terminator. Others treat it as a normal character. This inconsistency makes it possible to spoof commands that filter based on filename, particularly extension. Example: proc access {name} { if {[file extension $name] eq ".secret"} { error denied } else { puts granted open $name } } % access file.secret denied % access file.secret\0 granted file5 Generally, it's the commands that talk to the operating system that treat NUL as the string terminator. (More likely it's the operating system itself that does this!) For example, [open] and [cd] do this: % cd . % cd .\0 % cd \0. couldn't change working directory to "NUL.": no such file or directory # (in the previous line, NUL is a real NUL character; to see it, use tkcon instead of xterm) % file exists . 1 % file exists .\0 1 % file exists \0. 0 - foundin initialized to: "obsolete: 8.6b1.1"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "andygoth"
- subsystem initialized to: "37. File System"
- title initialized to: "NUL in filenames"
- type initialized to: "Bug"
Ticket change [85ed674981] (rid 131408) by hobbs on 2010-11-26 00:18:47:
- icomment:
I have a hard time understanding why this would be important. Adding more "cleanliness" on top of the direct OS layers would be ill advised imo. I think these are indeed valid on unix. Why are you tossing nulls in? If you are taking user input, why not strip nuls?
- login: "hobbs"
- mimetype: "text/plain"
- username: "hobbs"
- icomment:
Ticket change [75200bf3f0] (rid 105340) by hobbs on 2010-11-26 00:18:48:
- priority changed to: "3 Low"
Ticket change [c6098be455] (rid 121693) by andygoth on 2010-11-26 01:19:45:
- icomment:
The problem is that "internal" commands are not consistent with "operating system" commands. Either make the internal commands, like [file split], strip NULs and subsequent characters; or make the operating system commands treat filenames with NULs as nonexistent. I prefer the latter approach, because Tcl can't always distinguish between filenames and other strings: filenames are manipulated not only by [file] but also [string] and variable interpolation and other methods. Also it might be acceptable to have embedded NULs in the names of files on a VFS, just not for the native filesystem. Yes, NULs come from user input. I found this while testing Wibble: http://wiki.tcl.tk/27378#pagetocdd31402f . The user can easily insert a NUL by typing %00 in the URL; this convinces the [string match] that the requested file doesn't match any of the forbidden patterns, but then [open] drops the NUL and [chan copy] happily sends the forbidden file to the user. I can't easily strip NUL from filenames in Wibble because the core can't tell what parts of the URI or POST will ultimately correspond to an on-disk file, what parts are names of objects that aren't disk files and can legitimately have NULs, and what parts are arbitrary binary data. What can I do? Here's a script to strip NUL and subsequent: proc stripnul {str} { if {[set index [string first \0 $str]] == -1} { return $str } else { string range $str 0 [expr {$index - 1}] } } Then I must use this every time I make any decisions on the basis of a filename that's assembled from user input. That's a pain and there's a lot of room for error. Or, fix the problem everywhere for everybody by making the native filesystem code treat files whose names have embedded NULs as nonexistent. That makes sense to me, because there *aren't* any files with NULs in their names! Very old versions of Tcl used to strip NUL everywhere, whether you liked it or not. ;^) - login: "andygoth"
- mimetype: "text/plain"
- username: "andygoth"
- icomment:
Ticket change [84c1bf8f24] (rid 117614) by andygoth on 2012-11-21 10:38:38:
- foundin changed to: "current: 8.6.0"
- icomment:
I just came across this article describing the problem in the more general case: http://blog.portswigger.net/2008/05/null-byte-attacks-are-alive-and-well.html It turns out Tcl isn't the only system affected.
- login: "andygoth"
- mimetype: "text/plain"
- username: "andygoth"
Ticket change [049d277f61] (rid 120031) by nijtmans on 2012-11-21 14:29:10:
- assignee changed to: "nijtmans"
- icomment:
The most easy solution is the one used by cygwin: Map all invalid characters to a character in the Unicode private area range U+F000 to U+F0FF See: <http://cygwin.com/cygwin-ug-net/using-specialnames.html#pathnames-specialchars> On UNIX it could mean mapping \0 to \uF000 (or EF 80 80 in UTF-8)) in internal/external filename translation. After 8.6.0 is released, I'll have a further look whether this is practical or not. So 8.6.1 is the earliest chance to get it in, if all works out well. No high prio.
- login: "nijtmans"
- mimetype: "text/plain"
- username: "nijtmans"
Ticket change [61ba5314a7] (rid 92293) by dkf on 2012-11-21 18:09:27:
- icomment:
Quite apart from the fact that protecting files by extension is stupid (yeah, its just an example ;-)) it's arguably the case that NUL should always be treated as the end of the filename on all platforms. I've never encountered an OS that allowed it, though there's the prospect of its denormalized form turning up on systems that use UTF-8 (oh, what a tangled web we weave!). Anyway, my point is that we should fix [file]'s subcommands to do the right thing; if someone is abusing them with non-filenames, that's their fault.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [ecf4868fda] (rid 136996) by jan.nijtmans on 2014-02-21 19:07:21:
- assignee changed to: "jan.nijtmans"
Ticket change [10782d8a98] (rid 137573) by jan.nijtmans on 2014-04-11 08:20:54:
- closer changed to: "nobody"
- comment changed to:
Some file commands treat NUL (\0) as a string terminator. Others treat it as a normal character. This inconsistency makes it possible to spoof commands that filter based on filename, particularly extension. Example: proc access {name} { if {[file extension $name] eq ".secret"} { error denied } else { puts granted open $name } } % access file.secret denied % access file.secret\0 granted file5 Generally, it's the commands that talk to the operating system that treat NUL as the string terminator. (More likely it's the operating system itself that does this!) For example, [open] and [cd] do this: % cd . % cd .\0 % cd \0. couldn't change working directory to "NUL.": no such file or directory # (in the previous line, NUL is a real NUL character; to see it, use tkcon instead of xterm) % file exists . 1 % file exists .\0 1 % file exists \0. 0 - icomment:
Fixed in trunk for Windows only [0f4597a73cae916f979f4bd22eeb9f8dc5cd467f|0f4597a73c] by translating some characters which are invalid for win32 filenames to other characters as described here: [http://cygwin.com/cygwin-ug-net/using-specialnames.html#pathnames-specialchars]. (The characters ':' and '?' are not handled, because ':' is valid as drive specifier and '?' is valid in the extended path prefix.) Code inspired by fossil: [http://www.fossil-scm.org/index.html/artifact/76559aefff?ln=245-252]
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- severity changed to: "Minor"
Ticket change [225f0ad2b1] (rid 137578) by jan.nijtmans on 2014-04-11 09:52:23:
- icomment:
Now fixed for UNIX too, in [b5dd510e85bb0711c9f00a94620d602ffd2a9350|b5dd510e85].
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [90407ee788] (rid 137579) by jan.nijtmans on 2014-04-11 09:54:21:
- closedate changed to: "2456758.91274458"
- closer changed to: "jan.nijtmans"
- login: "jan.nijtmans"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [6092cda88b] (rid 138092) by jan.nijtmans on 2014-05-13 12:25:22:
- closedate changed to: "2456791.01762502"
- icomment:
On Windows, it's even worse: The ':' character can be used to gain access to "file.secret". Try (using the given "access" proc): % access file.secret:abc.txt granted file2f6b9b0 % Ough! (It doesn't matter what's after the ':', but it must contain at least a '.')
- login: "jan.nijtmans"
- mimetype: "text/plain"
Ticket change [e7b93d07b0] (rid 138127) by jan.nijtmans on 2014-05-15 14:56:29:
- closedate changed to: "2456793.12255838"
- icomment: "Backported to core-8-5-branch: [874ce8daf2]"
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"