Skip to content

Commit

Permalink
Don't parse cookies using pickle, due to security implications
Browse files Browse the repository at this point in the history
  • Loading branch information
lw committed Aug 29, 2018
1 parent 42c8044 commit 413f1f2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
10 changes: 5 additions & 5 deletions cms/server/contest/handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
from __future__ import print_function
from __future__ import unicode_literals

import json
import logging
import pickle
import socket
import struct
import traceback
Expand Down Expand Up @@ -224,7 +224,7 @@ def _get_current_user_from_cookie(self):

# Parse cookie.
try:
cookie = pickle.loads(self.get_secure_cookie("login"))
cookie = json.loads(self.get_secure_cookie("login"))
username = cookie[0]
password = cookie[1]
last_update = make_datetime(cookie[2])
Expand Down Expand Up @@ -257,9 +257,9 @@ def _get_current_user_from_cookie(self):

if self.refresh_cookie:
self.set_secure_cookie("login",
pickle.dumps((username,
password,
make_timestamp())),
json.dumps([username,
password,
make_timestamp()]),
expires_days=None)

return participation
Expand Down
7 changes: 3 additions & 4 deletions cms/server/contest/handlers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import json
import logging
import pickle

import tornado.web

Expand Down Expand Up @@ -117,9 +116,9 @@ def post(self):
logger.info("User logged in: user=%s remote_ip=%s.",
filtered_user, self.request.remote_ip)
self.set_secure_cookie("login",
pickle.dumps((user.username,
correct_password,
make_timestamp())),
json.dumps([user.username,
correct_password,
make_timestamp()]),
expires_days=None)
self.redirect(next_page)

Expand Down

0 comments on commit 413f1f2

Please sign in to comment.