Cross-Site Scripting (XSS) Vulnerability in SimpleHTTPServer in Python
Summary
CVE-2011-4940: The list_directory function in Lib/SimpleHTTPServer.py in SimpleHTTPServer in Python before 2.5.6c1, 2.6.x before 2.6.7 rc2, and 2.7.x before 2.7.2 does not place a charset parameter in the Content-Type HTTP header, whic... Affects python2.7 versions < 2.7.2-8. Fixed in 2.7.2-8. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
SimpleHTTPServer is a module in Python that provides a basic HTTP server for serving files from a directory. It is commonly used for testing and debugging purposes. The vulnerability identified as CVE-2011-4940 affects versions of Python before 2.5.6c1, 2.6.x before 2.6.7 rc2, and 2.7.x before 2.7.2. This vulnerability arises due to the list_directory function in Lib/SimpleHTTPServer.py not including a charset parameter in the Content-Type HTTP header. This omission makes it easier for remote attackers to conduct cross-site scripting (XSS) attacks against Internet Explorer 7 when UTF-7 encoding is used.
Vulnerability Detail
The vulnerability allows remote attackers to exploit a cross-site scripting vulnerability in Internet Explorer 7. By leveraging the absence of the charset parameter in the Content-Type HTTP header, an attacker can inject malicious scripts into web pages served by the SimpleHTTPServer module. This can lead to the execution of arbitrary code or the theft of sensitive information from unsuspecting users.
How To Fix
Minimum fixed version
2.7.2-8
This is the first release that contains the fix.
sudo apt-get install --only-upgrade python2.7
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
As a workaround, users can manually modify the SimpleHTTPServer.py file to include the charset parameter in the Content-Type HTTP header. The following code snippet demonstrates the necessary modification:
# Add the following line after line 201 in SimpleHTTPServer.py
self.send_header('Content-Type', 'text/html; charset=utf-8')
Please note that modifying the Python standard library files is not recommended and should be done with caution.
Conclusion
The cross-site scripting vulnerability in SimpleHTTPServer in Python versions before 2.5.6c1, 2.6.x before 2.6.7 rc2, and 2.7.x before 2.7.2 can lead to serious security risks, including the execution of arbitrary code and the theft of sensitive information. It is crucial to upgrade to the latest version of Python or apply the necessary fix to ensure the security of your applications. For further support on vulnerability remediation, you can contact DevNack.com.
See every vulnerability recorded for python2.7 →
FAQ
The vulnerability allows remote attackers to conduct cross-site scripting attacks against Internet Explorer 7, potentially leading to the execution of arbitrary code or the theft of sensitive information.
Versions of Python before 2.5.6c1, 2.6.x before 2.6.7 rc2, and 2.7.x before 2.7.2 are affected by this vulnerability.
You can use the Vulert Playground (https://vulert.com/scanner) to check if your Python installation is affected by this vulnerability. Simply upload your package-lock.json file and the Vulert Playground will provide real-time monitoring and alerts for open-source vulnerabilities.
Yes, upgrading to Python version 2.7.2-8 or later includes the necessary fix for this vulnerability.
A workaround is available by manually modifying the SimpleHTTPServer.py file to include the charset parameter in the Content-Type HTTP header. However, modifying Python standard library files is not recommended and should be done with caution.
Related vulnerabilities
Recent vulnerabilities recorded for python2.7.