Skip to content

Make Redash FIPS Compliant by adding useforsecurity=False flag to md5 hashes #7049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions redash/models/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def profile_image_url(self):
if self._profile_image_url:
return self._profile_image_url

email_md5 = hashlib.md5(self.email.lower().encode()).hexdigest()
email_md5 = hashlib.md5(self.email.lower().encode(), usedforsecurity=False).hexdigest()
return "https://www.gravatar.com/avatar/{}?s=40&d=identicon".format(email_md5)

@property
Expand Down Expand Up @@ -233,7 +233,9 @@ def has_access(self, obj, access_type):
return AccessPermission.exists(obj, access_type, grantee=self)

def get_id(self):
identity = hashlib.md5("{},{}".format(self.email, self.password_hash).encode()).hexdigest()
identity = hashlib.md5(
"{},{}".format(self.email, self.password_hash).encode(), usedforsecurity=False
).hexdigest()
return "{0}-{1}".format(self.id, identity)

def get_actual_user(self):
Expand Down
8 changes: 6 additions & 2 deletions redash/query_runner/query_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def create_tables_from_query_ids(user, connection, query_ids, query_params, cach

for query in set(query_params):
results = get_query_results(user, query[0], False, query[1])
table_hash = hashlib.md5("query_{query}_{hash}".format(query=query[0], hash=query[1]).encode()).hexdigest()
table_hash = hashlib.md5(
"query_{query}_{hash}".format(query=query[0], hash=query[1]).encode(), usedforsecurity=False
).hexdigest()
table_name = "query_{query_id}_{param_hash}".format(query_id=query[0], param_hash=table_hash)
create_table(connection, table_name, results)

Expand Down Expand Up @@ -142,7 +144,9 @@ def create_table(connection, table_name, query_results):

def prepare_parameterized_query(query, query_params):
for params in query_params:
table_hash = hashlib.md5("query_{query}_{hash}".format(query=params[0], hash=params[1]).encode()).hexdigest()
table_hash = hashlib.md5(
"query_{query}_{hash}".format(query=params[0], hash=params[1]).encode(), usedforsecurity=False
).hexdigest()
key = "param_query_{query_id}_{{{param_string}}}".format(query_id=params[0], param_string=params[1])
value = "query_{query_id}_{param_hash}".format(query_id=params[0], param_hash=table_hash)
query = query.replace(key, value)
Expand Down
2 changes: 1 addition & 1 deletion redash/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def gen_query_hash(sql):
"""
sql = COMMENTS_REGEX.sub("", sql)
sql = "".join(sql.split())
return hashlib.md5(sql.encode("utf-8")).hexdigest()
return hashlib.md5(sql.encode("utf-8"), usedforsecurity=False).hexdigest()


def generate_token(length):
Expand Down
Loading