diff options
Diffstat (limited to 'meta/recipes-devtools/python/python/security_issue_2254_fix.patch')
| -rw-r--r-- | meta/recipes-devtools/python/python/security_issue_2254_fix.patch | 184 |
1 files changed, 0 insertions, 184 deletions
diff --git a/meta/recipes-devtools/python/python/security_issue_2254_fix.patch b/meta/recipes-devtools/python/python/security_issue_2254_fix.patch deleted file mode 100644 index f0328585d5..0000000000 --- a/meta/recipes-devtools/python/python/security_issue_2254_fix.patch +++ /dev/null | |||
| @@ -1,184 +0,0 @@ | |||
| 1 | Upstream-Status: Backport | ||
| 2 | http://svn.python.org/view?view=revision&revision=71303 | ||
| 3 | |||
| 4 | Issue #2254: Fix CGIHTTPServer information disclosure. Relative paths are | ||
| 5 | now collapsed within the url properly before looking in cgi_directories. | ||
| 6 | Signed-Off-By: Nitin A Kamble <nitin.a.kamble@intel.com> | ||
| 7 | 2011/07/19 | ||
| 8 | |||
| 9 | Index: Python-2.6.6/Lib/CGIHTTPServer.py | ||
| 10 | =================================================================== | ||
| 11 | --- Python-2.6.6.orig/Lib/CGIHTTPServer.py | ||
| 12 | +++ Python-2.6.6/Lib/CGIHTTPServer.py | ||
| 13 | @@ -70,27 +70,20 @@ class CGIHTTPRequestHandler(SimpleHTTPSe | ||
| 14 | return SimpleHTTPServer.SimpleHTTPRequestHandler.send_head(self) | ||
| 15 | |||
| 16 | def is_cgi(self): | ||
| 17 | - """Test whether self.path corresponds to a CGI script, | ||
| 18 | - and return a boolean. | ||
| 19 | + """Test whether self.path corresponds to a CGI script. | ||
| 20 | |||
| 21 | - This function sets self.cgi_info to a tuple (dir, rest) | ||
| 22 | - when it returns True, where dir is the directory part before | ||
| 23 | - the CGI script name. Note that rest begins with a | ||
| 24 | - slash if it is not empty. | ||
| 25 | - | ||
| 26 | - The default implementation tests whether the path | ||
| 27 | - begins with one of the strings in the list | ||
| 28 | - self.cgi_directories (and the next character is a '/' | ||
| 29 | - or the end of the string). | ||
| 30 | + Returns True and updates the cgi_info attribute to the tuple | ||
| 31 | + (dir, rest) if self.path requires running a CGI script. | ||
| 32 | + Returns False otherwise. | ||
| 33 | + | ||
| 34 | + The default implementation tests whether the normalized url | ||
| 35 | + path begins with one of the strings in self.cgi_directories | ||
| 36 | + (and the next character is a '/' or the end of the string). | ||
| 37 | """ | ||
| 38 | - | ||
| 39 | - path = self.path | ||
| 40 | - | ||
| 41 | - for x in self.cgi_directories: | ||
| 42 | - i = len(x) | ||
| 43 | - if path[:i] == x and (not path[i:] or path[i] == '/'): | ||
| 44 | - self.cgi_info = path[:i], path[i+1:] | ||
| 45 | - return True | ||
| 46 | + splitpath = _url_collapse_path_split(self.path) | ||
| 47 | + if splitpath[0] in self.cgi_directories: | ||
| 48 | + self.cgi_info = splitpath | ||
| 49 | + return True | ||
| 50 | return False | ||
| 51 | |||
| 52 | cgi_directories = ['/cgi-bin', '/htbin'] | ||
| 53 | @@ -299,6 +292,46 @@ class CGIHTTPRequestHandler(SimpleHTTPSe | ||
| 54 | self.log_message("CGI script exited OK") | ||
| 55 | |||
| 56 | |||
| 57 | +# TODO(gregory.p.smith): Move this into an appropriate library. | ||
| 58 | +def _url_collapse_path_split(path): | ||
| 59 | + """ | ||
| 60 | + Given a URL path, remove extra '/'s and '.' path elements and collapse | ||
| 61 | + any '..' references. | ||
| 62 | + | ||
| 63 | + Implements something akin to RFC-2396 5.2 step 6 to parse relative paths. | ||
| 64 | + | ||
| 65 | + Returns: A tuple of (head, tail) where tail is everything after the final / | ||
| 66 | + and head is everything before it. Head will always start with a '/' and, | ||
| 67 | + if it contains anything else, never have a trailing '/'. | ||
| 68 | + | ||
| 69 | + Raises: IndexError if too many '..' occur within the path. | ||
| 70 | + """ | ||
| 71 | + # Similar to os.path.split(os.path.normpath(path)) but specific to URL | ||
| 72 | + # path semantics rather than local operating system semantics. | ||
| 73 | + path_parts = [] | ||
| 74 | + for part in path.split('/'): | ||
| 75 | + if part == '.': | ||
| 76 | + path_parts.append('') | ||
| 77 | + else: | ||
| 78 | + path_parts.append(part) | ||
| 79 | + # Filter out blank non trailing parts before consuming the '..'. | ||
| 80 | + path_parts = [part for part in path_parts[:-1] if part] + path_parts[-1:] | ||
| 81 | + if path_parts: | ||
| 82 | + tail_part = path_parts.pop() | ||
| 83 | + else: | ||
| 84 | + tail_part = '' | ||
| 85 | + head_parts = [] | ||
| 86 | + for part in path_parts: | ||
| 87 | + if part == '..': | ||
| 88 | + head_parts.pop() | ||
| 89 | + else: | ||
| 90 | + head_parts.append(part) | ||
| 91 | + if tail_part and tail_part == '..': | ||
| 92 | + head_parts.pop() | ||
| 93 | + tail_part = '' | ||
| 94 | + return ('/' + '/'.join(head_parts), tail_part) | ||
| 95 | + | ||
| 96 | + | ||
| 97 | nobody = None | ||
| 98 | |||
| 99 | def nobody_uid(): | ||
| 100 | Index: Python-2.6.6/Lib/test/test_httpservers.py | ||
| 101 | =================================================================== | ||
| 102 | --- Python-2.6.6.orig/Lib/test/test_httpservers.py | ||
| 103 | +++ Python-2.6.6/Lib/test/test_httpservers.py | ||
| 104 | @@ -7,6 +7,7 @@ Josip Dzolonga, and Michael Otteneder fo | ||
| 105 | from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer | ||
| 106 | from SimpleHTTPServer import SimpleHTTPRequestHandler | ||
| 107 | from CGIHTTPServer import CGIHTTPRequestHandler | ||
| 108 | +import CGIHTTPServer | ||
| 109 | |||
| 110 | import os | ||
| 111 | import sys | ||
| 112 | @@ -324,6 +325,45 @@ class CGIHTTPServerTestCase(BaseTestCase | ||
| 113 | finally: | ||
| 114 | BaseTestCase.tearDown(self) | ||
| 115 | |||
| 116 | + def test_url_collapse_path_split(self): | ||
| 117 | + test_vectors = { | ||
| 118 | + '': ('/', ''), | ||
| 119 | + '..': IndexError, | ||
| 120 | + '/.//..': IndexError, | ||
| 121 | + '/': ('/', ''), | ||
| 122 | + '//': ('/', ''), | ||
| 123 | + '/\\': ('/', '\\'), | ||
| 124 | + '/.//': ('/', ''), | ||
| 125 | + 'cgi-bin/file1.py': ('/cgi-bin', 'file1.py'), | ||
| 126 | + '/cgi-bin/file1.py': ('/cgi-bin', 'file1.py'), | ||
| 127 | + 'a': ('/', 'a'), | ||
| 128 | + '/a': ('/', 'a'), | ||
| 129 | + '//a': ('/', 'a'), | ||
| 130 | + './a': ('/', 'a'), | ||
| 131 | + './C:/': ('/C:', ''), | ||
| 132 | + '/a/b': ('/a', 'b'), | ||
| 133 | + '/a/b/': ('/a/b', ''), | ||
| 134 | + '/a/b/c/..': ('/a/b', ''), | ||
| 135 | + '/a/b/c/../d': ('/a/b', 'd'), | ||
| 136 | + '/a/b/c/../d/e/../f': ('/a/b/d', 'f'), | ||
| 137 | + '/a/b/c/../d/e/../../f': ('/a/b', 'f'), | ||
| 138 | + '/a/b/c/../d/e/.././././..//f': ('/a/b', 'f'), | ||
| 139 | + '../a/b/c/../d/e/.././././..//f': IndexError, | ||
| 140 | + '/a/b/c/../d/e/../../../f': ('/a', 'f'), | ||
| 141 | + '/a/b/c/../d/e/../../../../f': ('/', 'f'), | ||
| 142 | + '/a/b/c/../d/e/../../../../../f': IndexError, | ||
| 143 | + '/a/b/c/../d/e/../../../../f/..': ('/', ''), | ||
| 144 | + } | ||
| 145 | + for path, expected in test_vectors.iteritems(): | ||
| 146 | + if isinstance(expected, type) and issubclass(expected, Exception): | ||
| 147 | + self.assertRaises(expected, | ||
| 148 | + CGIHTTPServer._url_collapse_path_split, path) | ||
| 149 | + else: | ||
| 150 | + actual = CGIHTTPServer._url_collapse_path_split(path) | ||
| 151 | + self.assertEquals(expected, actual, | ||
| 152 | + msg='path = %r\nGot: %r\nWanted: %r' % ( | ||
| 153 | + path, actual, expected)) | ||
| 154 | + | ||
| 155 | def test_headers_and_content(self): | ||
| 156 | res = self.request('/cgi-bin/file1.py') | ||
| 157 | self.assertEquals(('Hello World\n', 'text/html', 200), \ | ||
| 158 | @@ -348,6 +388,12 @@ class CGIHTTPServerTestCase(BaseTestCase | ||
| 159 | self.assertEquals(('Hello World\n', 'text/html', 200), \ | ||
| 160 | (res.read(), res.getheader('Content-type'), res.status)) | ||
| 161 | |||
| 162 | + def test_no_leading_slash(self): | ||
| 163 | + # http://bugs.python.org/issue2254 | ||
| 164 | + res = self.request('cgi-bin/file1.py') | ||
| 165 | + self.assertEquals(('Hello World\n', 'text/html', 200), | ||
| 166 | + (res.read(), res.getheader('Content-type'), res.status)) | ||
| 167 | + | ||
| 168 | |||
| 169 | def test_main(verbose=None): | ||
| 170 | cwd = os.getcwd() | ||
| 171 | Index: Python-2.6.6/Misc/NEWS | ||
| 172 | =================================================================== | ||
| 173 | --- Python-2.6.6.orig/Misc/NEWS | ||
| 174 | +++ Python-2.6.6/Misc/NEWS | ||
| 175 | @@ -137,6 +137,9 @@ C-API | ||
| 176 | Library | ||
| 177 | ------- | ||
| 178 | |||
| 179 | +- Issue #2254: Fix CGIHTTPServer information disclosure. Relative paths are | ||
| 180 | + now collapsed within the url properly before looking in cgi_directories. | ||
| 181 | + | ||
| 182 | - Issue #8447: Make distutils.sysconfig follow symlinks in the path to | ||
| 183 | the interpreter executable. This fixes a failure of test_httpservers | ||
| 184 | on OS X. | ||
