在cgi-bin中运行python的安全注意事项

发布于 2024-09-18 13:57:32 字数 425 浏览 3 评论 0原文

我一直在编写在本地运行的 python 脚本。我现在想使用这些 python 脚本之一提供在线服务,并且通过我拥有的虚拟主机,我可以在 cgi-bin 中运行 python。

python 脚本从用户填写的 html 表单中获取输入,拥有凭据并与本地数据库连接,使用 python 库计算内容,并将结果作为 HTML 发送出去以进行显示。

我想知道的是我应该采取哪些安全预防措施。我担心的是:

  • 通过网络调用的脚本的正确文件权限是什么? 755?
  • 我正在接受用户输入。我如何保证它已被消毒?
  • 我在脚本中有数据库的用户/密码。如何防止脚本被下载和代码被看到?
  • 我可以安装该文件旁边的其他库吗?我是否还需要担心这些的安全性?我是否将他们的权限设置为700?第744章
  • 还有其他我不知道的漏洞吗?

I've been writing python scripts that run locally. I would now like to offer a service online using one of these python scripts and through the webhosting I have I can run python in the cgi-bin.

The python script takes input from an html form filled in by the user, has the credentials and connects with a local database, calculates stuff using python libraries and sends out the results as HTML to be displayed.

What I would like to know is what security precautions I should take. Here are my worries:

  • What are the right file permissions for scripts called via web? 755?
  • I am taking user input. How do I guarantee it is sanitized?
  • I have user/pass for the database in the script. How do I prevent the script from being downloaded and the code seen?
  • Can I install the other libraries next to the file? Do I have to worry about security of/in these as well? Do I set their permissions to 700? 744?
  • Any other vulnerability I am unaware of?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

浅浅 2024-09-25 13:57:32

查看 owasp.org - 您现在正在编写一个 Web 应用程序,并且您需要担心 Web 应用程序需要担心的一切。该列表太长且复杂,无法放在这里,但 owasp 是一个很好的起点。

check out owasp.org - you're now writing a web application, and you need to worry about everything web apps need to worry about. The list is too long and complicated to place here, but owasp is a good starting point.

骷髅 2024-09-25 13:57:32
  • 文件权限 - 755 是合理的。
  • 清理您的用户输入。这就是你保证它被消毒的方式。请参阅问题。
  • 不要让人们下载脚本的代码。您还可以将用户名/密码放在无法通过网络访问的某个目录中(例如可服务目录之外)。
  • 安装其他库的最佳位置是在 PYTHONPATH 中,但在 Apache 用于提供服务的路径之外。
  • 漏洞比比皆是。注意显示用户输入的内容,因为这会导致 XSS 问题。
  • File permissions - 755 is reasonable.
  • Sanitize your user input. That's how you guarantee it's sanitized. See this question.
  • Don't let people download the code for the script. You could also put the username/password in some directory that can't be accessed via the web (like outside the servable directories).
  • The best place to install other libraries is in your PYTHONPATH but outside the path Apache uses to serve things.
  • Vulnerabilities abound. Watch out for displaying things the user types, as that leads to XSS problems.
如梦 2024-09-25 13:57:32

通过网络调用的脚本的正确文件权限是什么?第755章

使用 mod_wsgi 以便您的脚本不会作为脚本运行,而是作为 WSGI 应用程序下的函数运行。

我正在接受用户输入。我如何保证它已被消毒?

使用 Django 这样的框架。

我在脚本中有数据库的用户/密码。如何防止脚本被下载和代码被看到?

使用 Django 这样的框架。

我可以安装该文件旁边的其他库吗?

是的。

我是否还需要担心这些的安全性?

是的。

我是否将他们的权限设置为 700?第744章

它们必须是可读的。就这样。但是,如果您使用 mod_wsgi,生活会更简单。如果您使用框架,那就更简单了。

还有我不知道的其他漏洞吗?

吨。请参阅 http://www.owasp.org 网站。

另外,请使用框架。请不要自己重新发明一切。人们已经解决了所有这些问题。

What are the right file permissions for scripts called via web? 755?

Use mod_wsgi so that your scripts are not run as scripts but as functions under a WSGI application.

I am taking user input. How do I guarantee it is sanitized?

Use a framework like Django.

I have user/pass for the database in the script. How do I prevent the script from being downloaded and the code seen?

Use a framework like Django.

Can I install the other libraries next to the file?

Yes.

Do I have to worry about security of/in these as well?

Yes.

Do I set their permissions to 700? 744?

They must be readable. That's all. However, if you use mod_wsgi, life is simpler. If you use a framework, simpler still.

Any other vulnerability I am unaware of?

Tons. Please see the http://www.owasp.org site.

Also, please use a framework. Please don't reinvent everything yourself. Folks have already solved all of these problems.

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