Skip to content

fix(agent,tools,gateway,plugins): add usedforsecurity=False to non-security hashlib calls - #52783

Open
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/hashlib-usedforsecurity
Open

fix(agent,tools,gateway,plugins): add usedforsecurity=False to non-security hashlib calls#52783
AlexFucuson9 wants to merge 1 commit into
NousResearch:mainfrom
AlexFucuson9:fix/hashlib-usedforsecurity

Conversation

@AlexFucuson9

Copy link
Copy Markdown
Contributor

Summary

hashlib.md5() and hashlib.sha1() without usedforsecurity=False raise ValueError on FIPS-enabled systems (OpenSSL 3.0+ with FIPS provider).

All 16 call sites across 8 files use hashing for cache keys, content dedup, or upload integrity checks — none are security-sensitive (passwords, signatures).

Files changed

File Count Purpose
agent/context_compressor.py 1 content dedup hash
agent/codex_responses_adapter.py 1 seed digest
plugins/platforms/wecom/adapter.py 1 data integrity md5
tools/skills_sync.py 1 file content hash
tools/skills_hub.py 5 cache key generation
gateway/platforms/weixin.py 2 content key + file hash
gateway/platforms/yuanbao_media.py 2 data hash + http signature
gateway/platforms/qqbot/chunked_upload.py 3 upload integrity md5/sha1

Intentionally skipped

  • gateway/platforms/wecom/wecom_crypto.py:63 — crypto signature (sha1 for HMAC-like verification), security-sensitive use.

Test plan

  • python3 -m py_compile on all 8 changed files
  • Existing tests pass unchanged (no behavioral difference on non-FIPS systems)

…curity hashlib calls

hashlib.md5() and hashlib.sha1() without usedforsecurity=False raise
ValueError on FIPS-enabled systems (OpenSSL 3.0+ with FIPS provider).
All 16 call sites use hashing for cache keys, content dedup, or upload
integrity checks — none are security-sensitive (passwords, signatures).

Skip gateway/platforms/wecom/wecom_crypto.py — crypto signature use.
@alt-glitch alt-glitch added type/security Security vulnerability or hardening comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery tool/skills Skills system (list, view, manage) P3 Low — cosmetic, nice to have labels Jun 26, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Related to #51962 (same author, FIPS usedforsecurity=False hardening) — this PR is a superset: it covers all 5 files in #51962 plus agent/codex_responses_adapter.py, gateway/platforms/qqbot/chunked_upload.py, and gateway/platforms/yuanbao_media.py. Also related to the broader FIPS cluster (#51973 sha, #27368 bandit B324, #48472 skills_hub). Maintainers may prefer to consolidate onto one PR.

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

Verdict: Approved

Looks Good

  • Mechanical fix: adds usedforsecurity=False to hashlib calls across 8 files
  • Correctly marks non-security hash operations (content dedup, file upload checksums, etc.)
  • Prevents FIPS compliance issues on restricted environments
  • No behavioral changes — purely compliance safety
  • Touches agent, tools, CLI, gateway, and plugins uniformly

Reviewed by Hermes Agent

@AlexFucuson9

Copy link
Copy Markdown
Contributor Author

Note: This PR is a superset of #51962 (now closed). It covers all 5 files from that PR plus additional agent/codex_response_parser.py. This is the consolidated version for FIPS usedforsecurity=False hardening.

@AquaBearCo

Copy link
Copy Markdown

Caveat up front: I'm an integration guy, not a programmer, and don't normally contribute — so grain of salt.

I hit the same FIPS issue on Rocky Linux 9.8 and can confirm this PR fixes it there. One gap remains though: some hardened setups reject MD5/SHA-1 even with usedforsecurity=False (see python/cpython#128071 and python/cpython#118224).

With some AI assistance I built a follow-up commit on top of this PR: keep the legacy digest where the runtime allows it, fall back to SHA-256 only where it refuses. Internal values only — output shapes unchanged, so non-FIPS systems behave identically. Protocol-defined hashes (QQ Bot, WeCom, Weixin, Yuanbao) are untouched, and a test guards that boundary.

Changed:

File Purpose
agent/internal_hash.py (new) fallback helper
agent/context_compressor.py dedup hash
agent/codex_responses_adapter.py fallback fc_ ID
tools/skills_sync.py change-detection hash
tools/skills_hub.py cache keys (incl. one MD5 call this PR missed)
tests/agent/test_internal_hash.py (new) 19 tests, all passing

Tests simulate the strict runtime by patching hashlib.new, so no FIPS CI runner needed. Known limitation: on strict systems, old MD5 manifest hashes in ~/.hermes/skills won't match, so synced skills may look user-modified and get skipped — conservative, fixable later with algorithm-prefixed hashes if wanted.

Commit: AquaBearCo@0be9fa5

Feel free to cherry-pick — I'd rather extend your fix than open a competing PR. If the approach is wrong, happy to learn.

@alt-glitch alt-glitch added comp/plugins Plugin system and bundled plugins platform/qqbot QQ Bot adapter platform/wecom WeCom / WeChat Work adapter codex labels Jul 14, 2026

@teknium1 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for consolidating the FIPS hardening work. The current-main premise is real, but this needs a narrower and more complete salvage.

Problems

  • tools/skills_hub.py:2474 still computes the clawhub_search_catalog_v1 cache key with bare hashlib.md5; the PR updates four related cache keys but leaves this current sibling path able to fail.
  • The changed _cos_sign digest is part of a COS Authorization derivation: gateway/platforms/yuanbao_media.py:305-344 builds HMAC-SHA1 signatures around the sha1_of_http value. That is not equivalent to the cache/dedup uses elsewhere, and the remaining HMAC-SHA1 calls are unchanged.
  • No regression test exercises FIPS-style constructor behavior. Existing QQ Bot tests at tests/gateway/test_qqbot.py:725-745 validate output shape only.

Suggested changes

  • Cover the remaining Skills Hub cache-key call at tools/skills_hub.py:2474 and add constructor-keyword regression tests.
  • Keep COS protocol signing out of this non-security sweep unless its full compatibility behavior is separately verified.

Automated hermes-sweeper review.

@@ -308,7 +308,7 @@ def _cos_sign(
])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This SHA-1 digest feeds StringToSign in the COS Authorization flow; the same function uses HMAC-SHA1 immediately before and after it. Please keep protocol-signing code out of this non-security sweep unless the complete FIPS behavior of the authorization algorithm is verified.

Comment thread tools/skills_hub.py
@@ -2131,7 +2131,7 @@ def search(self, query: str, limit: int = 10) -> List[SkillMeta]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also cover the current ClawHub catalog cache key at tools/skills_hub.py:2474 (clawhub_search_catalog_v1), which remains a bare hashlib.md5 call outside this four-site batch.

@teknium1 teknium1 added sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 15, 2026
@alt-glitch alt-glitch removed the sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data label Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint comp/gateway Gateway runner, session dispatch, delivery comp/plugins Plugin system and bundled plugins P3 Low — cosmetic, nice to have platform/qqbot QQ Bot adapter platform/wecom WeCom / WeChat Work adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades tool/skills Skills system (list, view, manage) type/security Security vulnerability or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants