Skip to content

Commit 3853586

Browse files
committed
Fix issue11442 - Add a charset parameter to the Content-type to avoid XSS attacks.
Patch by Tom N. (Backported from py3k codeline).
1 parent 6e0a8b8 commit 3853586

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Lib/SimpleHTTPServer.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import urllib
1717
import urlparse
1818
import cgi
19+
import sys
1920
import shutil
2021
import mimetypes
2122
try:
@@ -132,7 +133,8 @@ def list_directory(self, path):
132133
length = f.tell()
133134
f.seek(0)
134135
self.send_response(200)
135-
self.send_header("Content-type", "text/html")
136+
encoding = sys.getfilesystemencoding()
137+
self.send_header("Content-type", "text/html; charset=%s" % encoding)
136138
self.send_header("Content-Length", str(length))
137139
self.end_headers()
138140
return f

0 commit comments

Comments
 (0)