Skip to content

Commit

Permalink
chore: defined variable to pick sha1 as algorithm for SafeSessionMi…
Browse files Browse the repository at this point in the history
…ddleware.
  • Loading branch information
awais786 committed Oct 2, 2023
1 parent 64662b7 commit c5a4e72
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
3 changes: 3 additions & 0 deletions cms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,9 @@
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
DEFAULT_HASHING_ALGORITHM = 'sha1'

# default algorithm for SafeSessionMiddleware
SAFE_SESSIONS_MAC_ALGO = 'sha1'

#################### Python sandbox ############################################

CODE_JAIL = {
Expand Down
3 changes: 3 additions & 0 deletions lms/envs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,9 @@ def _make_mako_template_dirs(settings):
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
DEFAULT_HASHING_ALGORITHM = 'sha1'

# default algorithm for SafeSessionMiddleware
SAFE_SESSIONS_MAC_ALGO = 'sha1'

#################### Python sandbox ############################################

CODE_JAIL = {
Expand Down
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/safe_sessions/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def sign(self, user_id):
data_to_sign = self._compute_digest(user_id)

self.signature = signing.TimestampSigner(
salt=self.key_salt, algorithm=settings.DEFAULT_HASHING_ALGORITHM
salt=self.key_salt, algorithm=settings.SAFE_SESSIONS_MAC_ALGO
).sign_object(data_to_sign, serializer=signing.JSONSerializer, compress=False)

def verify(self, user_id):
Expand All @@ -280,7 +280,7 @@ def verify(self, user_id):
"""
try:
unsigned_data = signing.TimestampSigner(
salt=self.key_salt, algorithm=settings.DEFAULT_HASHING_ALGORITHM
salt=self.key_salt, algorithm=settings.SAFE_SESSIONS_MAC_ALGO
).unsign_object(self.signature, serializer=signing.JSONSerializer, max_age=settings.SESSION_COOKIE_AGE)

if unsigned_data == self._compute_digest(user_id):
Expand Down

0 comments on commit c5a4e72

Please sign in to comment.