Skip to content

Commit 1000019

Browse files
committed
Ignore incorrect base 64 padding.
1 parent 0d1c629 commit 1000019

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

app/jekylledit/controllers/site.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def site_file(site_id, file_id):
138138

139139
# Update post
140140
elif request.method == 'PUT':
141-
filename = b64decode(file_id).decode()
141+
filename = decode_filename(file_id)
142142
if not repository.is_path_in(filename):
143143
abort(403)
144144
filemask = filename.rsplit('-', 1)[0] + '-{}.' \
@@ -164,7 +164,7 @@ def site_file(site_id, file_id):
164164
elif request.method == 'DELETE':
165165
if not Permission(('administrator', site_id)):
166166
abort(403)
167-
filename = b64decode(file_id).decode()
167+
filename = decode_filename(file_id)
168168
if not repository.is_path_in(filename):
169169
abort(403)
170170
filemask = filename.rsplit('-', 1)[0] + '-{}.' \
@@ -180,7 +180,7 @@ def site_file(site_id, file_id):
180180

181181
# Return post
182182
else:
183-
filename = b64decode(file_id).decode()
183+
filename = decode_filename(file_id)
184184
if not repository.is_path_in(filename):
185185
abort(403)
186186
filemask = filename.rsplit('-', 1)[0] + '-{}.' \
@@ -199,6 +199,10 @@ def site_file(site_id, file_id):
199199
})
200200

201201

202+
def decode_filename(file_id):
203+
return b64decode(file_id + '===').decode()
204+
205+
202206
# Response related drafts
203207
@app.route('/site/<site_id>/drafts', methods=['GET'])
204208
@cross_origin()

app/jekylledit/model/site.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ def remove_post(self, filename):
150150
def save_media(self, media):
151151
config = self.get_config()
152152
created = []
153-
for key, medio in media.items():
154-
if not '/' in key:
153+
for key, medium in media.items():
154+
if '/' not in key:
155155
filename = self.repository.path(config['media'] + '/' + key)
156156
else:
157157
filename = self.repository.path(key)
158158
with open(filename, 'wb+') as fm:
159-
fm.write(b64decode(medio['data']))
159+
fm.write(b64decode(medium['data']))
160160
created.append(filename)
161161
return created
162162

0 commit comments

Comments
 (0)