Skip to content

fix(tools): read DB2_CONNECTION_STRING when connection_string is omitted - #9760

Open
Kiko0301 wants to merge 1 commit into
crewAIInc:mainfrom
Kiko0301:fix/db2-connection-string-env
Open

Kiko0301 wants to merge 1 commit into
crewAIInc:mainfrom
Kiko0301:fix/db2-connection-string-env

Conversation

@Kiko0301

Copy link
Copy Markdown
Contributor

Fixes #9759

Summary

DB2VectorSearchTool declares DB2_CONNECTION_STRING in env_vars and documents it in its README, but connection_string is a required pydantic field with no default and nothing in the tool reads the environment. Following the README (export DB2_CONNECTION_STRING=... and construct the tool without the argument) therefore fails with ValidationError: connection_string Field required, although the tool advertises the variable as supported.

Changes

  • lib/crewai-tools/src/crewai_tools/tools/db2_search_tool/db2_search_tool.py
    • Add a model_validator(mode="before") that fills connection_string from DB2_CONNECTION_STRING when the argument is missing or empty. An explicitly passed connection_string is left untouched, and a missing variable still leaves the field required.
  • lib/crewai-tools/tests/tools/test_db2_search_tool.py
    • Add TestConnectionStringFromEnv:
      • test_uses_env_var_when_connection_string_omitted constructs the tool from the documented environment variable only.
      • test_explicit_connection_string_wins_over_env_var pins precedence.

Verification

  • With the fix: pytest lib/crewai-tools/tests/tools/test_db2_search_tool.py -> 72 passed.
  • Against the base revision of db2_search_tool.py (new tests kept): test_uses_env_var_when_connection_string_omitted fails with ValidationError: connection_string Field required; the explicit-argument test still passes.
  • The change only adds a before-validator, so existing behavior for callers that pass connection_string is unchanged.

AI assistance

I used an AI coding agent to investigate, implement, and test this change, and reviewed its results. Per CONTRIBUTING.md, please apply the llm-generated label; external contributors cannot add it with my current permissions.

DB2VectorSearchTool lists DB2_CONNECTION_STRING in env_vars and its
README documents it, but connection_string is a required field and no
code reads the variable, so setting it and constructing the tool as
documented raises a pydantic ValidationError.

Fill connection_string from the environment in a before-validator; an
explicitly passed connection_string still wins.
@strix-security

strix-security Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Strix Security Review

✅ No open security findings.

PR summary: `DB2VectorSearchTool` now falls back to the `DB2_CONNECTION_STRING` environment variable when `connection_string` is not passed, matching what its `env_vars` declaration and README already advertised; explicit arguments still take precedence.

Review summary

The PR adds a before-validator to DB2VectorSearchTool so connection_string is filled from DB2_CONNECTION_STRING when omitted, plus two tests pinning the fallback and precedence. The change is confined to constructor-time keyword handling; the SQL path, identifier validation and parameter binding are untouched. Suspicion around the credential now entering a plain pydantic field was traced through tool serialization, repr, telemetry and error-return paths without a reachable sink that the env fallback widens, and the fallback does not let less-trusted configuration select the connection target. No security issues found in the changed code.

Ruled out (3)
  • Does populating the DB2 connection string (with UID/PWD) from the environment newly leak the password through pydantic repr, model dumps, traces or error messa…
    The field is a plain string exactly as before, and no reachable serialization, telemetry or error path carries it in a way the env fallback widens over an explicitly passed value.
  • Can the environment fallback let a less-trusted tool config choose the DB2 connection target or override an explicit one?
    An explicitly supplied non-empty value always wins, and the environment is deployment-controlled configuration rather than attacker input, so no trust boundary is crossed.
  • Does the new before-validator open the door to the config-driven module import and callable selection reachable on this class's construction path?
    The validator only rewrites the `connection_string` key and leaves `db2_package`, `db2_dbi_package` and `custom_embedding_fn` unconstrained exactly as before, with no new attacker-controlled kwargs path introduced by this change.

Review 1 on this PR · ce574f3 · requested Nov 25 05:05 UTC when the PR was opened


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

This branch has not been deployed

No deployments
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.

[BUG] DB2VectorSearchTool declares DB2_CONNECTION_STRING but never reads it

1 participant