Skip to content

fix(p1-12): redact exception text in deprecated AUTOSEARCH_LEGACY_RESEARCH path#434

Merged
0xmariowu merged 9 commits intomainfrom
fix/p1-12-legacy-redact
Apr 26, 2026
Merged

fix(p1-12): redact exception text in deprecated AUTOSEARCH_LEGACY_RESEARCH path#434
0xmariowu merged 9 commits intomainfrom
fix/p1-12-legacy-redact

Conversation

@0xmariowu
Copy link
Copy Markdown
Owner

@0xmariowu 0xmariowu commented Apr 26, 2026

Summary

P1 fix for reports/autosearch-p0-fix-plan.md §12 — autosearch/mcp/server.py legacy research() tool path (gated on AUTOSEARCH_LEGACY_RESEARCH=1) emitted raw exception text in MCP responses. Same risk as the CLI top-level path (F013): secrets in exception messages leak to MCP clients.

Changes

  1. mcp/server.py legacy_research branch: wrap exception text via redact() before returning to MCP client.
  2. New test test_legacy_research_exception_redacted verifying secret patterns are stripped.

Plan

docs/exec-plans/active/autosearch-0426-p0-fix-plan-execution.md § F014 (S1-S2).

Commits

Test plan

  • pytest tests/unit/test_research_deprecation.py tests/unit/test_mcp_error_redaction.py — 7 passed
  • pytest tests/unit/ -m "not real_llm and not slow and not network" — 674 passed, 3 skipped
  • ruff clean

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Error messages returned by the research tool are now automatically sanitized to prevent potential exposure of sensitive information in error responses.
  • Tests

    • Enhanced test coverage to verify proper redaction and sanitization of error messages in the research tool, including legacy modes.

Copilot AI review requested due to automatic review settings April 26, 2026 11:46
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 26, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Error handling in the MCP research tool now redacts exception messages using the redact function. The implementation imports redact, and tests are refactored with a helper function and a new test case verifying that legacy research error responses redact secret-shaped exception strings.

Changes

Cohort / File(s) Summary
Error Message Redaction
autosearch/mcp/server.py
Updated exception handling in research tool to apply redact() to error messages instead of returning raw exception text; import modified to include redact function.
Test Updates and Verification
tests/unit/test_research_deprecation.py
Refactored tool invocation with _call_research helper; updated server creation to pass pipeline_factory directly; added _SecretFailingPipeline and new test case test_legacy_research_exception_redacted verifying error responses are redacted under legacy mode.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #175: Refactors the research tool's return type to use Pydantic ResearchResponse envelope, affecting the same tool implementation.
  • PR #233: Modifies the research() implementation's control flow and deprecation opt-in behavior, overlapping with the MCP server changes.

Suggested labels

tests, no-issue-link

Poem

🐰 Secrets hidden in exception's cry,
Now redacted ere the logs fly high!
Tests confirm the mystery stays sealed,
Legacy mode keeps secrets revealed—
A rabbit's work, both thorough and spry! 🔐

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: redacting exception text in the deprecated legacy research path.
Description check ✅ Passed The description covers key sections including What (summary), Why (P1 fix for secret leakage), Changes, Test plan with results, but lacks some template sections like Root Cause and Evidence checkboxes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread tests/unit/test_research_deprecation.py Fixed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a secrets-leak risk in the deprecated MCP research() legacy path (enabled via AUTOSEARCH_LEGACY_RESEARCH=1) by ensuring exception text is redacted before being returned to MCP clients.

Changes:

  • Redact exception strings returned from the legacy research() MCP tool error response.
  • Add a unit test to ensure secret-shaped tokens in legacy research() exceptions are replaced with [REDACTED].

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
autosearch/mcp/server.py Wraps legacy research() exception content with redact() before returning the MCP response.
tests/unit/test_research_deprecation.py Adds coverage asserting legacy research() error responses do not include secret-shaped substrings.

Comment thread tests/unit/test_research_deprecation.py Outdated
@0xmariowu 0xmariowu enabled auto-merge (squash) April 26, 2026 12:32
@0xmariowu 0xmariowu merged commit ef940c1 into main Apr 26, 2026
14 of 15 checks passed
@0xmariowu 0xmariowu deleted the fix/p1-12-legacy-redact branch April 26, 2026 13:14
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