Skip to content

Commit c619e66

Browse files
lookuptabledpebot
authored andcommitted
Manually add required padding before base64.b64decode. (GoogleCloudPlatform#595)
1 parent ba53d37 commit c619e66

File tree

1 file changed

+9
-1
lines changed
  • appengine/flexible/endpoints

1 file changed

+9
-1
lines changed

appengine/flexible/endpoints/main.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
app = Flask(__name__)
3131

3232

33+
def _base64_decode(encoded_str):
34+
# Add paddings manually if necessary.
35+
num_missed_paddings = 4 - len(encoded_str) % 4
36+
if num_missed_paddings != 4:
37+
encoded_str += b'=' * num_missed_paddings
38+
return base64.b64decode(encoded_str).decode('utf-8')
39+
40+
3341
@app.route('/echo', methods=['POST'])
3442
def echo():
3543
"""Simple echo service."""
@@ -42,7 +50,7 @@ def auth_info():
4250
encoded_info = request.headers.get('X-Endpoint-API-UserInfo', None)
4351

4452
if encoded_info:
45-
info_json = base64.b64decode(encoded_info).decode('utf-8')
53+
info_json = _base64_decode(encoded_info)
4654
user_info = json.loads(info_json)
4755
else:
4856
user_info = {'id': 'anonymous'}

0 commit comments

Comments
 (0)