Skip to content

Allow md5hash to function in fips environments #1267

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

trevor-scale
Copy link

@trevor-scale trevor-scale commented Apr 15, 2025

Many secure environments disable the hashlib.md5 function because it is insecure, this causes the line below to fail making dateparser unusable in these environments:

return hashlib.md5("".join(keys).encode("utf-8")).hexdigest()

This is remedied by replacing that line with return hashlib.new("md5", "".join(keys).encode("utf-8"), usedforsecurity=False).hexdigest() which appropriately bypasses the fips security check because dateparser is not using the md5 hash for security applications.

Corresponding issue: #1258

@ghmj2417
Copy link

I posted this in #1258 as well. Change usedforsecurity=True to usedforsecurity=False. The suggestion/example provided in issue 1258 was to use hashlib.new but it also included the full command which had usedforsecurity=True to test a failure when using FIPS compliant encryptions/hashes/etc. My apologies for not being clear.

@trevor-scale
Copy link
Author

I posted this in #1258 as well. Change usedforsecurity=True to usedforsecurity=False. The suggestion/example provided in issue 1258 was to use hashlib.new but it also included the full command which had usedforsecurity=True to test a failure when using FIPS compliant encryptions/hashes/etc. My apologies for not being clear.

Thanks for catching this wasn't looking closely when I copy-pasted haha. Will update now!

@trevor-scale
Copy link
Author

I posted this in #1258 as well. Change usedforsecurity=True to usedforsecurity=False. The suggestion/example provided in issue 1258 was to use hashlib.new but it also included the full command which had usedforsecurity=True to test a failure when using FIPS compliant encryptions/hashes/etc. My apologies for not being clear.

Thanks for catching this wasn't looking closely when I copy-pasted haha. Will update now!

@ghmj2417 are you able to approve and merge this, would love to get this added in!

@trevor-scale
Copy link
Author

@Gallaecio can you give this a review and lmk if any changes are needed when you have the chance?

Co-authored-by: Adrián Chaves <[email protected]>
Copy link

codecov bot commented Jun 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.47%. Comparing base (e9324ee) to head (010e49a).
Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1267   +/-   ##
=======================================
  Coverage   97.47%   97.47%           
=======================================
  Files         234      234           
  Lines        2775     2776    +1     
=======================================
+ Hits         2705     2706    +1     
  Misses         70       70           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Gallaecio
Copy link
Member

Please, install pre-commit, run pre-commit install, then pre-commit run --all-files, keep running that command until everything is green (I think in this case a single run should suffice, but seeing everything green is nice 🙂), and commit those changes.

@ghmj2417
Copy link

hashlib.new was to accommodate Python 3.8. If setup.py is going to require >= 3.9 then hashlib.md5 is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants