Skip to content

fix: redact credentials from URLs in logs, exceptions, and persisted state - #2196

Closed
jpshackelford wants to merge 1 commit into
mainfrom
openhands/fix-credential-exposure-in-logs
Closed

jpshackelford wants to merge 1 commit into
mainfrom
openhands/fix-credential-exposure-in-logs

Conversation

@jpshackelford

@jpshackelford jpshackelford commented Feb 24, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes #2152

This PR addresses a security issue where credentials embedded in plugin source URLs (e.g., https://oauth2:SECRET_TOKEN@gitlab.com/org/private-repo) were being exposed in:

  1. Application logs - Clone URLs and git commands were logged with credentials visible
  2. Exception messages - Error messages included full URLs with credentials
  3. Persisted conversation state - Plugin source URLs with credentials were stored in ResolvedPluginSource
  4. Installed extension metadata - Source URLs with credentials were stored in .installed.json

Changes

  • New utility function: redact_url_credentials(url) in git/utils.py that replaces credentials in URLs with **** (e.g., https://****@gitlab.com/org/repo)
  • Updated run_git_command(): Redacts credentials from error logs, debug logs, and GitCommandError exception messages/command fields
  • Updated cached_repo.py: Redacts credentials in clone log messages
  • Updated extensions/fetch.py: Redacts credentials in ExtensionFetchError exceptions and warning logs (this is the new location after refactoring)
  • Updated plugin/types.py: ResolvedPluginSource.from_plugin_source() now redacts credentials before persistence (credentials are only needed at fetch time)
  • Updated plugin/loader.py: Redacts credentials in plugin loading log messages
  • Updated local_conversation.py: Redacts credentials in plugin loaded debug messages
  • Updated extensions/installation/info.py: Redacts credentials in InstallationInfo.from_extension() before persisting to .installed.json
  • Public API export: redact_url_credentials is exported from openhands.sdk for cross-repo usage (related to Security: Credentials in plugin source URLs exposed via API responses OpenHands#12959)

Example

Before:

INFO - Cloning repository from https://oauth2:SECRET_TOKEN@gitlab.com/org/repo.git

After:

INFO - Cloning repository from https://****@gitlab.com/org/repo.git

Code Review Feedback Addressed

This update addresses all the issues identified in the code review by @enyst:

  • ✅ plugin/loader.py - now redacts spec.source in log messages
  • ✅ local_conversation.py - now redacts spec.source in debug log messages
  • ✅ extensions/installation/info.py - now redacts source in InstallationInfo.from_extension() before persistence

Rebased to Resolve Conflicts

The codebase was significantly refactored since the original PR (fetch logic moved from plugin/fetch.py to extensions/fetch.py). This update is rebased on latest main and applies redaction to the new code locations.

Checklist

  • If the PR is changing/adding functionality, are there tests to reflect this?
  • If there is an example, have you run the example to make sure that it works?
  • If there are instructions on how to run the code, have you followed the instructions and made sure that it works?
  • If the feature is significant enough to require documentation, is there a PR open on the OpenHands/docs repository with the same branch name?
  • Is the github CI passing?

This PR was updated by an AI agent (OpenHands) on behalf of @jpshackelford.


Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:8aacb37-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-8aacb37-python \
  ghcr.io/openhands/agent-server:8aacb37-python

All tags pushed for this build

ghcr.io/openhands/agent-server:8aacb37-golang-amd64
ghcr.io/openhands/agent-server:8aacb3791a56ae7e189538d09e95c5c1c03830af-golang-amd64
ghcr.io/openhands/agent-server:openhands-fix-credential-exposure-in-logs-golang-amd64
ghcr.io/openhands/agent-server:8aacb37-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:8aacb37-golang-arm64
ghcr.io/openhands/agent-server:8aacb3791a56ae7e189538d09e95c5c1c03830af-golang-arm64
ghcr.io/openhands/agent-server:openhands-fix-credential-exposure-in-logs-golang-arm64
ghcr.io/openhands/agent-server:8aacb37-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:8aacb37-java-amd64
ghcr.io/openhands/agent-server:8aacb3791a56ae7e189538d09e95c5c1c03830af-java-amd64
ghcr.io/openhands/agent-server:openhands-fix-credential-exposure-in-logs-java-amd64
ghcr.io/openhands/agent-server:8aacb37-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:8aacb37-java-arm64
ghcr.io/openhands/agent-server:8aacb3791a56ae7e189538d09e95c5c1c03830af-java-arm64
ghcr.io/openhands/agent-server:openhands-fix-credential-exposure-in-logs-java-arm64
ghcr.io/openhands/agent-server:8aacb37-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:8aacb37-python-amd64
ghcr.io/openhands/agent-server:8aacb3791a56ae7e189538d09e95c5c1c03830af-python-amd64
ghcr.io/openhands/agent-server:openhands-fix-credential-exposure-in-logs-python-amd64
ghcr.io/openhands/agent-server:8aacb37-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:8aacb37-python-arm64
ghcr.io/openhands/agent-server:8aacb3791a56ae7e189538d09e95c5c1c03830af-python-arm64
ghcr.io/openhands/agent-server:openhands-fix-credential-exposure-in-logs-python-arm64
ghcr.io/openhands/agent-server:8aacb37-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:8aacb37-golang
ghcr.io/openhands/agent-server:8aacb3791a56ae7e189538d09e95c5c1c03830af-golang
ghcr.io/openhands/agent-server:openhands-fix-credential-exposure-in-logs-golang
ghcr.io/openhands/agent-server:8aacb37-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:8aacb37-java
ghcr.io/openhands/agent-server:8aacb3791a56ae7e189538d09e95c5c1c03830af-java
ghcr.io/openhands/agent-server:openhands-fix-credential-exposure-in-logs-java
ghcr.io/openhands/agent-server:8aacb37-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:8aacb37-python
ghcr.io/openhands/agent-server:8aacb3791a56ae7e189538d09e95c5c1c03830af-python
ghcr.io/openhands/agent-server:openhands-fix-credential-exposure-in-logs-python
ghcr.io/openhands/agent-server:8aacb37-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., 8aacb37-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 8aacb37-python-amd64) are also available if needed

@github-actions

github-actions Bot commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

github-actions Bot commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk
   __init__.py39976%117–118, 136–137, 139–140, 147, 149–150
openhands-sdk/openhands/sdk/conversation/impl
   local_conversation.py4452295%300, 305, 436, 483, 520, 536, 601, 820–821, 824, 995, 997, 1001–1002, 1013–1014, 1039, 1234, 1238, 1308, 1315–1316
openhands-sdk/openhands/sdk/git
   cached_repo.py129496%391–392, 427–428
   utils.py1342779%125–127, 152–154, 242–243, 250–255, 260–261, 271–276, 286–288, 316, 426
openhands-sdk/openhands/sdk/plugin
   loader.py30293%109, 112
   types.py1091784%56, 59, 62, 92–100, 103–104, 107, 165, 301
TOTAL26568766471% 

@github-actions

github-actions Bot commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@jpshackelford
jpshackelford marked this pull request as ready for review March 10, 2026 01:58

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟢 Good taste - Clean security fix with pragmatic design.

Key Insight: Simple regex-based redaction applied consistently across logs, exceptions, and persisted state. The decision to redact credentials in ResolvedPluginSource is sound design - credentials are only needed at fetch time, and resolved plugins reference local cached paths for subsequent access.

What Works:

  • Focused redact_url_credentials() function does one thing well
  • Comprehensive test coverage testing real behavior (not mocks) ✓
  • Handles edge cases correctly (ports, special chars, SSH URLs unchanged)
  • Applied consistently: logs, error messages, exceptions, persistence

Design Decision (Good):
Redacting in ResolvedPluginSource.from_plugin_source() prevents credential leakage in conversation state without breaking functionality - resolved plugins use cached repo_path, so re-authentication not needed.

✅ Worth merging - Solves real security problem (#2152) with minimal complexity. No agent behavior changes, just safer logging and persistence.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

@enyst

This comment was marked as outdated.

@openhands-ai

This comment was marked as outdated.

@enyst

enyst commented Mar 15, 2026

Copy link
Copy Markdown
Member

@OpenHands Do a /codereview-roasted on this PR, and publish your review using gh API and event.

@openhands-ai

openhands-ai Bot commented Mar 15, 2026

Copy link
Copy Markdown

I'm on it! enyst can track my progress at all-hands.dev

@enyst enyst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🔴 Needs improvement - you added a redaction helper, but the security boundary is still full of holes.

Linus-Style Analysis

[CRITICAL ISSUES]

  • openhands-sdk/openhands/sdk/plugin/loader.py:75, openhands-sdk/openhands/sdk/plugin/installed.py:195,582, openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py:350 Security / real-world leak: the PR says credentials are redacted from logs, but these paths still log source / spec.source verbatim. So a completely successful plugin load or install can still dump the credentialed URL into logs. That's not a corner case; that's the normal path. The fix needs one redaction boundary that's used everywhere plugin sources are logged, not a few hand-picked call sites.
  • openhands-sdk/openhands/sdk/plugin/installed.py:103-118, openhands-sdk/openhands/sdk/plugin/installed.py:227-241 Persisted-state leak: InstalledPluginInfo.from_plugin() stores the original source unchanged, and InstalledPluginsMetadata.save_to_dir() writes it to disk. So authenticated plugin URLs still end up persisted in metadata. If the goal is "credentials do not live in persisted state", this path still fails it.

[TESTING GAPS]

  • tests/sdk/git/test_credential_redaction.py:1-186 Helper tests aren't enough: these tests mostly prove that a regex rewrites strings. They do not exercise the behavior that matters: actual log messages and persistence paths from run_git_command(), plugin install/load, conversation plugin loading, or installed metadata. Right now the tests all pass while the leak is still present in live call sites, which means the regression net is pointed at the wrong thing.

VERDICT:
❌ Needs rework: the helper itself is fine, but the security fix is incomplete, so this PR does not actually eliminate credential exposure.

KEY INSIGHT:
You added a scrubber, but you did not make it the single choke point, so raw URLs are still escaping through ordinary success-path code.

@openhands-ai

This comment was marked as duplicate.

@enyst

enyst commented Mar 15, 2026

Copy link
Copy Markdown
Member

I haven't verified if the agent is accurate or not, just FWIW, the second thing it says might be happening because we got in a PR installing plugins ... maybe between the time you first made this and now. Sorry! So now there might be another execution path indeed.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

9 similar comments
@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

…state

This addresses security issue #2152 by preventing credential leakage:

- Add redact_url_credentials() utility function to sanitize URLs with
  embedded credentials (e.g., https://oauth2:token@host/path becomes
  https://****@host/path)
- Update git/utils.py:run_git_command() to redact credentials from:
  - Error log messages
  - Debug log messages
  - GitCommandError exception messages and command fields
- Update git/cached_repo.py to redact credentials in clone log messages
- Update extensions/fetch.py to redact credentials in:
  - ExtensionFetchError exception messages
  - Warning log messages
- Update plugin/types.py:ResolvedPluginSource.from_plugin_source() to
  redact credentials before persistence (credentials only needed at
  fetch time)
- Update plugin/loader.py to redact credentials in plugin load log messages
- Update local_conversation.py to redact credentials in plugin load logs
- Update extensions/installation/info.py to redact credentials before
  persisting installed extension metadata
- Export redact_url_credentials from openhands.sdk public API for
  cross-repo usage (related: OpenHands/OpenHands#12959)
- Add comprehensive tests for credential redaction

Fixes #2152

Co-authored-by: John-Mason P. Shackelford <jpshackelford@users.noreply.github.com>
@jpshackelford
jpshackelford force-pushed the openhands/fix-credential-exposure-in-logs branch from 7d02066 to 8aacb37 Compare May 14, 2026 22:09

Copy link
Copy Markdown
Member Author

PR Updated 🔄

I've rebased this PR on latest main and addressed all the issues from the code review:

Changes in this update:

  1. Rebased on latest main - The codebase was significantly refactored since this PR was opened (fetch logic moved from plugin/fetch.py to extensions/fetch.py). All conflicts are now resolved.

  2. Fixed additional credential leak paths identified in the review:

    • plugin/loader.py - Added redact_url_credentials(spec.source) in log message
    • local_conversation.py - Added redact_url_credentials(spec.source) in debug log
    • extensions/installation/info.py - Added redaction in InstallationInfo.from_extension() before persisting to .installed.json
    • extensions/fetch.py - Applied redaction to the new location of fetch logic
  3. Comprehensive tests - 20 new tests covering:

    • Various URL formats (HTTPS with user:password, OAuth tokens, ports, special chars)
    • Git argument redaction
    • ResolvedPluginSource persistence redaction
    • Public API export verification

Ready for re-review! 🚀


This update was created by an AI agent (OpenHands) on behalf of @jpshackelford.

@jpshackelford
jpshackelford requested a review from enyst May 14, 2026 22:10
@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

This comment was created by an AI agent (OpenHands) on behalf of the user.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

This comment was generated by an AI agent (OpenHands) on behalf of the user.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: This PR seems to be currently waiting for review. @enyst, could you please take a look when you have a chance?

This comment was created by an AI agent (OpenHands) on behalf of the user.

@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

This comment was created by an AI agent (OpenHands) on behalf of the user.

1 similar comment
@all-hands-bot

Copy link
Copy Markdown
Collaborator

[Automatic Post]: It has been a while since there was any activity on this PR. @jpshackelford, are you still working on it? If so, please go ahead, if not then please request review, close it, or request that someone else follow up.

This comment was created by an AI agent (OpenHands) on behalf of the user.

Copy link
Copy Markdown
Member Author

Closing the loop — superseding this PR.

This PR took a per-call-site "scrubber" approach, which the review #2196 (review 3950231707) correctly flagged as architecturally incomplete (no single choke point, so raw URLs still escape via success-path and persisted-state code). The work has since been reworked and split into focused, reviewable pieces. Closing this to stop the stale-bot churn — nothing here is lost; every site is now either fixed on main or tracked:

Done / merged

In progress / tracked

Umbrella context: original SDK report #2152, OpenHands-side #12959. Re-open or rebase only if a site surfaces that none of #2154 / #3689 / #3751 / #3752 covers.

Posted by an AI agent (OpenHands) on behalf of @jpshackelford.

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: Credentials in plugin source URLs exposed in logs, exceptions, and persisted state

4 participants