Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在审查一个数据导出 Web 服务,该服务:
如果没有对输入文件名进行验证(例如文件是否存在),那么 Web 服务可能对有恶意的人有哪些潜在风险/漏洞?
说你的directory字符串常量是"/tmp/files"
directory
"/tmp/files"
攻击者可以提供"../../etc/passwd"
"../../etc/passwd"
>>> import os >>> os.path.abspath(directory + "../../etc/passwd") '/etc/passwd'
至少,您希望将输入剥离到基本名称
>>> os.path.join("/tmp/files", os.path.basename("../../etc/passwd") /tmp/files/passwd