对于python–如何在Flask中安全地获取具有代理的用户IP地址?感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解flask获取客户端ip,并且为您提供关于CMake不断从cygwinp
对于python – 如何在Flask中安全地获取具有代理的用户IP地址?感兴趣的读者,本文将提供您所需要的所有信息,我们将详细讲解flask 获取客户端ip,并且为您提供关于CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取、Core Python | 2 - Core Python: Getting Started | 2.5 - Modularity | 2.5.5 - The Python Execution Mod、Error: Can‘t find Python executable “python“, you can set the PYTHON env variable、ERROR: Command "python setup.py egg_info" python-nss的宝贵知识。
本文目录一览:- python – 如何在Flask中安全地获取具有代理的用户IP地址?(flask 获取客户端ip)
- CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取
- Core Python | 2 - Core Python: Getting Started | 2.5 - Modularity | 2.5.5 - The Python Execution Mod
- Error: Can‘t find Python executable “python“, you can set the PYTHON env variable
- ERROR: Command "python setup.py egg_info" python-nss
python – 如何在Flask中安全地获取具有代理的用户IP地址?(flask 获取客户端ip)
Flask建议获得X-Forwarded-Host,但随后他们立即表示存在安全风险.有没有一种安全的方法来获得客户端真正的IP?
解决方法
这里的问题不是ProxyFix本身会导致用户访问您的系统,而是ProxyFix将采用曾经最可靠的信息并用可能不可靠的信息替换它.
对于初学者,当您不使用ProxyFix时,很可能从TCP数据包中的源IP地址检索REMOTE_ADDR属性.虽然不是不可能,但the source IP address in TCP packets are tough to spoof.因此,如果您需要一种可靠的方法来检索用户的IP地址,REMOTE_ADDR是一种很好的方法.在大多数情况下,当你发出request.remote_addr时,你可以依靠它为你提供准确的东西.
当然,问题是在反向代理情况下,TCP连接不是来自最终用户;相反,最终用户与反向代理建立TCP连接,然后反向代理与您的Web应用程序建立第二个TCP连接.因此,应用中的request.remote_addr将具有反向代理的IP地址,而不是原始用户的IP地址.
潜在的解决方案
ProxyFix应该解决这个问题,这样你就可以使request.remote_addr拥有用户的IP地址而不是代理.它通过查看远程代理(如Apache和Nginx)添加到HTTP标头(X-Forwarded-For)并使用其在那里找到的用户IP地址的典型HTTP标头来实现此目的.请注意,Cloudflare使用不同的HTTP标头,因此ProxyFix可能无法帮助您;您需要编写自己的中间件实现来获取request.remote_addr以使用原始客户端的IP地址.但是,在本答复的其余部分中,我将继续将该修复称为“ProxyFix”.
然而,该解决方案存在问题.问题是虽然TCP标头最可靠,但HTTP标头不是;如果用户可以绕过您的反向代理并将数据直接发送到服务器,他们可以在HTTP标头中放置他们想要的任何内容.例如,他们可以使HTTP头中的IP地址成为其他人的IP地址!如果使用IP地址进行身份验证,则用户可以欺骗该身份验证机制.如果将IP地址存储在数据库中,然后将其在应用程序中以HTML格式显示给另一个用户,则用户可能会将sql或Javascript注入到标头中,从而可能导致sql注入或XSS漏洞.
所以,总结一下; ProxyFix采用一种已知的最安全的解决方案,从TCP数据包中检索用户的IP地址,并使用解析易受欺骗的HTTP标头的非常安全的解决方案将其切换.
因此,在反向代理情况下仅使用ProxyFix的建议意味着:如果您接受来自非代理的位置的连接,请不要使用此方法.这通常意味着让反向代理(如Nginx或Apache)处理所有传入流量,并让您的应用程序在防火墙后面实际使用ProxyFix.
您还应阅读this post,其中解释了过去如何破坏ProxyFix(although is now fixed).这也将解释ProxyFix如何工作,并为您提供有关如何设置num_proxies argument的想法.
更好的解决方案
假设您的用户位于A点,他们将请求发送到Cloudflare(B),最终将请求发送到您的最终应用程序(C点). Cloudflare will send the IP address of A in the CF-Connecting-IP header
.
如上所述,如果用户找到指向C的IP地址,他们可以直接向C点发送特制的HTTP请求,其中包括他们想要的任何头信息. ProxyFix将使用其逻辑来确定HTTP头中的IP地址,如果您依赖该值,那么这当然是有问题的.
因此,您可能希望查看使用类似mod_cloudflare的内容,它允许您直接在Apache mod中执行这些代理修复,但仅限于HTTP连接来自Cloudflare IP地址(由TCP IP源定义).您也可以只接受来自Cloudflare的连接.有关此内容的更多信息,请参阅How do I restore original visitor IP to my server logs,并帮助其他服务器(如Nginx)执行此操作.
这应该给你一个开始.但是,请记住,您仍然不是“安全”:您只关闭了一个可能的攻击向量,并且该攻击向量假定攻击者知道您的实际应用程序的IP地址.在这种情况下,恶意用户可能会尝试使用欺骗性的Cloudflare IP地址进行TCP攻击,although this would be extremely difficult.更有可能的是,如果他们想要造成严重破坏,他们只会DDOS您的源服务器,因为他们绕过了Cloudflare.因此,在保护您的应用程序时还需要考虑更多的事情.希望这有助于您了解如何使一个部分更安全.
CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取
如何解决CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取
我有一个看起来像这样的 CMake 脚本:
find_program(PYTHON_COMMAND NAMES python3 python)
问题是它检测到安装在 Cygwin 安装中的 python。 输出总是:
-- PYTHON_PATH:C:/cygwin64/bin/python3
我希望它取自:
c:\\python36-64\\python
在windows PATH变量中,Cygwin bin在路径的最后一个,windows安装在第一个
但它只检测到 Cygwin python,
怎么改?
Core Python | 2 - Core Python: Getting Started | 2.5 - Modularity | 2.5.5 - The Python Execution Mod
It's important to understand the Python execution model and precisely when function deFinitions and other important events occur when a module is imported or executed. Here, we show execution of our Python module as it's imported in a graphical debugging environment. We step through the top‑level statements in the module. What's important to realize here is that the def used for the fetch_words function isn't merely a declaration. It's actually a statement, which when executed in sequence with the other top‑level model scope code, causes the code within the function to be bound to the name of the function. When modules are imported or run, all of the top‑level statements are run, and this is the means by which the function within the module namespace are defined. We are sometimes asked about the difference between Python modules, Python scripts, and Python programs. Any .py file constitutes a Python module. But as we've seen, modules can be written for convenient import, convenient execution, or using the if dunder name = dunder main idiom, both. We strongly recommend making even simple scripts importable since it eases development and testing so much if you can access your code from within the REPL. Likewise, even modules, which are only ever meant to be imported in production settings, benefit from having executable test code. For this reason, nearly all modules we create have this form of defining one or more importable functions with a postscript to facilitate execution. Whether you consider a module to be a Python script or Python program is a matter of context and usage. It's certainly wrong to consider Python to be merely a scripting tool, in the vein of Windows batch files or UNIX Shell scripts, as many large and complex applications are built exclusively with python.
- def不仅仅是一个declaration声明,更是一条statement语句。它将其中的python代码于函数名绑定在一起
- 一个py文件就是一个模块,这个模块包含类或函数。你写python,要尽量将代码包装成函数和类,方便各种import
- 一个py文件也可看作是一个脚本,在系统命令行中运行
- python不仅仅是脚本语言,很多大型程序都是用python构建的
Error: Can‘t find Python executable “python“, you can set the PYTHON env variable
在启动vue项目的时候,安装node.js组件node-sass过程中报错了,错误提示如下
Error
: Can’t find Python executable “python”, you can set the PYTHON env variable
由错误提示可知:Node.js 在安装模块组件node-sass的时候,node.js缺少Visual Studio2015 Build Tools相关的组件和python的环境,如果安装了vs2015组件的小伙伴们就不用安装Visual Studio2015 Build Tools相应的组件,只用安装python2.7即可解决缺少的python组件的问题。
欲安装python2.7,请至python官网:www.python.org 下载,然后配置好python的环境变量即可。
不过博主我并不推荐上述的解决方案,因为对于程序员来说,效率第一,上述的问题一个命令就可以轻松解决你所遇到的麻烦,前面说了那么多,无非就是想告诉在看本篇博客的同仁们放下浮躁的心,遇到问题首先不是急着去解决问题,而是分析为什么会这样,然后才能水到聚成的去找到解决问题的方法。
运行下面这个命令即可解决你们遇到的Error问题
npm install --global --production windows-build-tools
注:上面讲述了一堆就是为了讲述此命令是干嘛的,上面已经描述很详细了,就不再赘述了,该操作与上述的一堆操作无异,效果却是一样的。
然后运气不好的小伙伴可能接着会遇到一个坑,那就是执行了:npm install --global --production windows-build-tools
这个命令的人细心点会发现执行到一半就卡住了,这个卡住了没有红字重点提示,而且下方还有英文在等待中,粗心的小伙伴可能以为是命令执行完了,组件安装好了,其实不然,我这边已经解决了,就无法复现了,具体点就是中文的提示,提示我们由于有类似组件在运行或者下载导致无法继续下载安装组件了。稳妥点的解决办法是,将电脑重启,将底层正在运行的模块干掉,待电脑重启后再执行npm install --global --production windows-build-tools
这条命令即可,博主我就是这样解决的,稳稳的幸福就会浮现在你面前如下图所示,你的可能和我不一样,因为我已经跑成功过一次了,没有你的那么多细节的log打印。
然后就是在你的项目下shift+鼠标右击你的项目运行npm run dev即可启动vue项目了。
ERROR: Command "python setup.py egg_info" python-nss
[root@localhost ~]# pip install python-nss
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won''t be maintained after that date. A future version of pip will drop support for Python 2.7.
Looking in indexes: http://pypi.douban.com/simple
Collecting python-nss
Downloading http://pypi.doubanio.com/packages/6b/29/629098e34951c358b1f04f13a70b3590eb0cf2df817d945bd05c4169d71b/python-nss-1.0.1.tar.bz2 (222kB)
|████████████████████████████████| 225kB 31kB/s
ERROR: Complete output from command python setup.py egg_info:
ERROR: Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-JGnrT5/python-nss/setup.py", line 409, in <module>
sys.exit(main(sys.argv))
File "/tmp/pip-install-JGnrT5/python-nss/setup.py", line 333, in main
nss_include_dir = find_include_dir([''nss3'', ''nss''], [''nss.h'', ''pk11pub.h''], include_roots=include_roots)
File "/tmp/pip-install-JGnrT5/python-nss/setup.py", line 94, in find_include_dir
raise ValueError("unable to locate include directory containing header files %s" % include_files)
ValueError: unable to locate include directory containing header files [''nss.h'', ''pk11pub.h'']
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-JGnrT5/python-nss/
查看错误日志缺少头文件
进入python-nss官网,写着To build python-nss you the C language header files and libraries for both NSPR and NSS will need to be installed. This is system and distribution specific, as such we cannot give you explicit instructions. On Linux typically these packages are called:
- nss-devel
- nspr-devel
yum install nss-devel -y
yum install nspr-devel -y
关于python – 如何在Flask中安全地获取具有代理的用户IP地址?和flask 获取客户端ip的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于CMake 不断从 cygwin python 中获取 Python,如何从 Windows 安装的 Python 中获取、Core Python | 2 - Core Python: Getting Started | 2.5 - Modularity | 2.5.5 - The Python Execution Mod、Error: Can‘t find Python executable “python“, you can set the PYTHON env variable、ERROR: Command "python setup.py egg_info" python-nss的相关知识,请在本站寻找。
本文标签: