简体   繁体   中英

How to create directories in a secure way in python

I'm faced with the following problem:

The users have some files that need syncing so I'm writing a script that copies the encrypted files from a user's directory to a temporary directory in the server before it gets distributed in the other 5 servers.

The initial copy is done by creating a folder with the user's name and putting the files there. The users are free to change usernames so if someone changes his username to something nasty the server(s) is/are owned

I have to use the usernames for folder names because the script that does the syncing is using the folder username for metadata of some sort.

So, is there any way to escape the usernames and make sure that everything is created under the master folder?

正如nrathaus建议的那样,您可以使用os.path.normpath来获取“规范化”路径并检查安全性问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM