Skip to content

fix: remove hardcoded private key placeholders from docstrings and add signing tests#4867

Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin/1773465726-fix-hardcoded-private-key-docstring
Open

fix: remove hardcoded private key placeholders from docstrings and add signing tests#4867
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin/1773465726-fix-hardcoded-private-key-docstring

Conversation

@devin-ai-integration
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot commented Mar 14, 2026

Summary

Addresses issue #4864 — security scanners flagging -----BEGIN PRIVATE KEY-----... in docstring examples as a hardcoded credential.

Docstring fix: Replaced PEM header placeholders in sign_agent_card and verify_agent_card_signature docstring examples with <PEM-encoded private key> / <PEM-encoded public key> so they no longer trigger secret-detection tools.

New tests: Added 40 tests for agent_card_signing.py, which previously had zero test coverage. All keys are dynamically generated via cryptography fixtures — no hardcoded secrets. Coverage includes:

  • _normalize_private_key (bytes / str / SecretStr inputs)
  • _serialize_agent_card (JSON validity, determinism, signature exclusion, sorted keys)
  • _base64url_encode (padding removal, URL safety, roundtrip)
  • sign_agent_card with RSA (RS256) and EC (ES256)
  • verify_agent_card_signature (valid, wrong key, tampered card, corrupted sig, algorithm mismatch)
  • get_key_id_from_signature (protected/unprotected header, precedence, invalid input)
  • Regression guard asserting no -----BEGIN PRIVATE KEY----- in module source

Review & Testing Checklist for Human

  • Confirm the original -----BEGIN PRIVATE KEY-----... at line 106 was indeed only a docstring placeholder and not an actual leaked credential (it was — just a truncated example string)
  • Verify no other files in the repo contain actual hardcoded private keys that the issue may have been referring to
  • Run uv run pytest lib/crewai/tests/a2a/utils/test_agent_card_signing.py -vv to confirm all 40 tests pass

Notes


Note

Low Risk
Primarily adds test coverage and tweaks docstring examples; runtime behavior is unchanged, so risk is low aside from potential CI/test dependency issues.

Overview
Updates agent_card_signing.py docstring examples to use non-PEM placeholders (e.g., <PEM-encoded private key>) to avoid secret scanners flagging the repository.

Adds a new test_agent_card_signing.py suite that generates RSA/EC keys at runtime and exercises _normalize_private_key, _serialize_agent_card, _base64url_encode, sign_agent_card, verify_agent_card_signature, and get_key_id_from_signature, including negative cases (tampering, wrong key, algorithm mismatch) and a regression check that no PEM headers appear in the module source.

Written by Cursor Bugbot for commit c768afd. This will update automatically on new commits. Configure here.

…d signing tests

- Replace '-----BEGIN PRIVATE KEY-----...' and '-----BEGIN PUBLIC KEY-----...'
  placeholders in docstring examples with '<PEM-encoded private key>' and
  '<PEM-encoded public key>' to avoid triggering security scanners.
- Add comprehensive test suite for agent_card_signing.py (40 tests) covering:
  - Key normalization (bytes, str, SecretStr)
  - AgentCard serialization (JSON validity, determinism, signature exclusion)
  - Base64url encoding (padding, URL safety, roundtrip)
  - RSA signing and verification
  - EC (ES256) signing and verification
  - Tampered card detection
  - Corrupted signature handling
  - Key ID extraction from protected/unprotected headers
  - Assertion that no hardcoded PEM key headers exist in source

Closes #4864

Co-Authored-By: João <joao@crewai.com>
@devin-ai-integration
Copy link
Contributor Author

Prompt hidden (unlisted session)

@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

"""The source file must not contain actual PEM key headers."""
import inspect

import crewai.a2a.utils.agent_card_signing as module
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.

[Security] private key checked into the repository

0 participants