Skip to content

Commit e192af5

Browse files
committed
manifests/07-downloads-deployment: Create index.html
Conservative, filesystem-based web servers should avoid dynamic directory listing, to avoid accidentally leaking a file that a user drops into the served filesystem [1,2]. It seems like an unlikely vector for the downloads container, where nobody outside of our script is likely to be dropping files. But it is easy enough to fix by filling in index.html files throughout, which preempt SimpleHTTPRequestHandler's directory listing [3,4]. [1]: https://bugzilla.redhat.com/show_bug.cgi?id=1859331 [2]: https://cwe.mitre.org/data/definitions/548.html [3]: https://docs.python.org/2.7/library/simplehttpserver.html#SimpleHTTPServer.SimpleHTTPRequestHandler.do_GET [4]: https://github.com/python/cpython/blob/e7c98f08e228e9f6e139d61e3e5d0a5018a38f0b/Lib/http/server.py#L757-L758
1 parent ecc5132 commit e192af5

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

manifests/07-downloads-deployment.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ spec:
6363
6464
signal.signal(signal.SIGTERM, lambda signum, frame: sys.exit(0))
6565
66+
def write_index(path, message):
67+
with open(path, 'wb') as f:
68+
f.write('\n'.join([
69+
'<!doctype html>',
70+
'<html lang="en">',
71+
'<head>',
72+
' <meta charset="utf-8">',
73+
'</head>',
74+
'<body>',
75+
' {}'.format(message),
76+
'</body>',
77+
'</html>',
78+
'',
79+
]).encode('utf-8'))
80+
6681
# Launch multiple listeners as threads
6782
class Thread(threading.Thread):
6883
def __init__(self, i, socket):
@@ -93,6 +108,7 @@ spec:
93108
os.mkdir(arch)
94109
for operating_system in ['linux']:
95110
os.mkdir(os.path.join(arch, operating_system))
111+
content = ['<a href="oc-license">license</a>']
96112
os.symlink('/usr/share/openshift/LICENSE', 'oc-license')
97113
98114
for arch, operating_system, path in [
@@ -112,6 +128,23 @@ spec:
112128
tar.add(path, basename)
113129
with zipfile.ZipFile('{}.zip'.format(archive_path_root), 'w') as zip:
114130
zip.write(path, basename)
131+
content.append('<a href="{0}">oc ({1} {2})</a> (<a href="{0}.tar">tar</a> <a href="{0}.zip">zip</a>)'.format(target_path, arch, operating_system))
132+
133+
for root, directories, filenames in os.walk(temp_dir):
134+
root_link = os.path.relpath(temp_dir, os.path.join(root, 'child')).replace(os.path.sep, '/')
135+
for directory in directories:
136+
write_index(
137+
path=os.path.join(root, directory, 'index.html'),
138+
message='<p>Directory listings are disabled. See <a href="">here</a> for available content.</p>'.format(root_link),
139+
)
140+
write_index(
141+
path=os.path.join(root, 'index.html'),
142+
message='\n'.join(
143+
['<ul>'] +
144+
[' <li>{}</li>'.format(entry) for entry in content] +
145+
['</ul>']
146+
),
147+
)
115148
116149
# Create socket
117150
# IPv6 should handle IPv4 passively so long as it is not bound to a

0 commit comments

Comments
 (0)