保护在线静态内容

发布于 2024-07-10 14:55:48 字数 271 浏览 3 评论 0原文

如何只允许通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

命比纸薄 2024-07-17 14:55:48

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.

绿光 2024-07-17 14:55:48

如果用户经过正确身份验证,您可能只想让 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文