Cross-Site Scripting (XSS) Vulnerability in SimpleHTTPServer in Python

python2.7 Updated 02 Oct 2025

Summary

27/06/2012
N/A
Yes i
Unrated
Not published

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 ↓

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

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 →

Share this vulnerability

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.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

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 →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback