保护在线静态内容
如何只允许通过 Python 代码进行身份验证的用户访问服务器上的某些文件?
例如,假设我有我想要保护的 /static/book.txt
。 当用户访问 /some/path/that/validates/him
时,Python 脚本认为他值得访问 /static/book.txt
并将他重定向到该路径。
如何阻止绕过脚本直接访问 /static/book.txt
的用户?
How would I only allow users authenticated via Python code to access certain files on the server?
For instance, say I have /static/book.txt
which I want to protect. When a user accesses /some/path/that/validates/him
, a Python script deems him worthy of accessing /static/book.txt
and redirects him to that path.
How would I stop users who bypass the script and directly access /static/book.txt
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Lighttpd 有 mod_secdownload 来实现此目的。 基本上,它不会直接提供静态内容,除非您为其生成短期静态 URL。
请注意,您可以在 S3 上对静态内容执行类似的操作。 这是一个非常有用的功能。
Lighttpd has mod_secdownload for this. Basically, it won't serve the static content directly unless you generate a short-lived static URL for it.
Note that you can do similar things on S3 for static content. It's a quite useful feature.
如果用户经过正确身份验证,您可能只想让 Python 脚本打开文件并将内容转储为其输出。 将要保护的文件放在网络服务器根目录之外的文件夹中。
You might want to just have your Python script open the file and dump the contents as its output if the user is properly authenticated. Put the files you want to protect in a folder that is outside of the webserver root.