security - How to sanitize user created filenames for a networked application? -
i'm working on instant messaging app, users can receive files friends.
the names of files received set sender of file, , multiple files can sent possibility of subdirectories. example, 2 files sent might "1" , "sub/2" such downloaded results should "downloads/1" , "downloads/sub/2".
i'm worried security implications of this. right off top of head, 2 potentially dangerous filnames "../../../somethingnasty" or "~/somethingnasty" unix-like users. other potential issues cross mind filenames characters unsupported on target filesystem, seems harder , may better ignore?
i'm considering stripping received filenames ".." , "~" type of blacklist approach individually think of problem cases hardly seems recipe security. what's recommended way sanitize filenames ensure nothing sinister happens?
if makes difference, app running on c++ qt framework.
it's wiser replace ".." xxx , ~ yyy. way convert invalid path valid path. i.e. if user wants upload "../../../somethingnasty" - no problems, let him upload file , store in xxx/xxx/xxx/somethingnasty.
or better, can encode nonalphanumeric characters (except slashes) %xy xy hexidecimal code of character. way have %2e%2e/%2e%2e/%2e%2e/somethingnasty
Comments
Post a Comment