Skip to content

fix: remove 8 hardcoded secrets from source code (issue #5124)#5128

Open
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin/1774554475-fix-hardcoded-secrets
Open

fix: remove 8 hardcoded secrets from source code (issue #5124)#5128
devin-ai-integration[bot] wants to merge 3 commits intomainfrom
devin/1774554475-fix-hardcoded-secrets

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

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

Summary

Addresses the 8 hardcoded secrets flagged as high severity in the Ratchet code quality scan (issue #5124).

Source code fixes (7 files):

  • create_flow.py: Replaced OPENAI_API_KEY=YOUR_API_KEY with empty placeholder OPENAI_API_KEY=\n
  • completion.py: Replaced hardcoded default_api_key strings ("ollama", "dummy") with os.getenv() calls that preserve the same fallback values (except "dummy""no-key-required")
  • multion_tool/example.py: Replaced os.environ["OPENAI_API_KEY"] = "Your Key" with a validation check + env var read
  • factory.py, vertex.py, genai_vertex_embedding.py: Replaced hardcoded "sk-..." / "your-api-key" in docstring examples with os.environ[...] references
  • invoke_crewai_automation_tool.py: Replaced "your_token" in docstring examples with os.environ["CREWAI_BEARER_TOKEN"]

Tests (1 new file):

  • Added test_hardcoded_secrets.py with regex-based source scanning tests to prevent regressions
  • Updated existing test_openai_compatible.py assertion for the new hosted_vllm default

Review & Testing Checklist for Human

  • hosted_vllm default_api_key changed from "dummy" to "no-key-required" — this is a behavioral change. Verify no downstream code or user workflows depend on the literal string "dummy" as the API key for vLLM.
  • multion_tool/example.py now raises ValueError if OPENAI_API_KEY is not set, instead of silently assigning a fake key. Confirm this fail-loud behavior is preferred.
  • os.getenv() in completion.py is evaluated at module import time, meaning the OLLAMA_DEFAULT_API_KEY / VLLM_DEFAULT_API_KEY env vars must be set before the module is first imported. Confirm this is acceptable vs. deferring the lookup to connection time.
  • TestProviderDefaultApiKeys tests are weak — since OPENAI_COMPATIBLE_PROVIDERS is built at import time, the patch.dict in test_ollama_default_api_key_from_env cannot actually verify env var override behavior. The assertions just check is not None. Consider whether stronger tests are needed.
  • Run uv run pytest lib/crewai/tests/security/test_hardcoded_secrets.py lib/crewai/tests/llms/openai_compatible/test_openai_compatible.py -vv locally to confirm tests pass.

Notes

  • Docstring-only changes (factory.py, vertex.py, genai_vertex_embedding.py, invoke_crewai_automation_tool.py) have no runtime impact — they just show better practices in examples. Note that os.environ[...] in these docstrings is illustrative, not executable code.
  • The .env.example file in stagehand_tool/ was not modified as it already uses clearly-labeled placeholders appropriate for example files.
  • tool.specs.json was auto-updated by CI to reflect the docstring changes in invoke_crewai_automation_tool.py.

Link to Devin session: https://app.devin.ai/sessions/cfaca751784b42ed850732c4aa13d704

- Replace hardcoded 'YOUR_API_KEY' in create_flow.py with empty placeholder
- Replace hardcoded os.environ assignments in multion_tool example with os.environ.get()
- Replace hardcoded default_api_key values in OpenAI-compatible providers with os.getenv() lookups
- Replace hardcoded API keys in docstring examples with os.environ[] references
- Replace hardcoded bearer tokens in invoke_crewai_automation_tool docstrings
- Add test suite for hardcoded secrets detection (test_hardcoded_secrets.py)
- Update existing test assertions for new default_api_key values

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

Prompt hidden (unlisted session)

@devin-ai-integration
Copy link
Copy Markdown
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

Co-Authored-By: João <joao@crewai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants