Repository navigation
Conversation
…458) initialize_git_in_container used a hardcoded `cat > .gitignore <<EOF` heredoc with a narrow shell/cache deny-list that did NOT include `.env`, `.mcp.json`, or any other credential pattern. It also overwrote any workspace-supplied `.gitignore` and skipped the legacy /home/developer/workspace path entirely. Agents with credentials injected via `inject_credentials` therefore leaked `.env` and `.mcp.json` on the "Initial commit from Trinity Agent" push. This is a P0 credential exfiltration path that fired on every first GitHub sync. Changes (src/backend/services/git_service.py): - New module constant `DEFAULT_GITIGNORE_DENYLIST`: credentials first (`.env`, `.env.*`, `!.env.example`, `.mcp.json`, `credentials.json`, `token.json`, `*.pem`, `*.key`, `*.p12`, `*.pfx`, `.aws/credentials`, `.config/gcloud/`) then existing shell/cache entries. - New helper `_build_gitignore_merge_command(git_dir)`: generates a bash script that appends missing deny-list entries to any existing `.gitignore` using exact-line `grep -qxF` checks. Idempotent. Inner script body + pattern payload are both base64-encoded so shell metacharacters in patterns (`!`, `*`, `/`) can't reach the shell. - Call site hoisted out of the `if git_dir == "/home/developer":` block so the legacy workspace path also gets the deny-list. - Merge failure now aborts init with a descriptive error — better than commiting credentials on a half-configured agent. Regression tests (tests/unit/test_github_init_gitignore.py, 14 tests): - AC #1: deny-list present when no `.gitignore` exists. - AC #2: pre-existing user rules preserved alongside deny-list. - AC #3: legacy /home/developer/workspace path also protected. - Idempotency, managed-header uniqueness, no-trailing-newline edge case, command-injection safety, ordering vs `git add .`, failure abort behavior. Closes #458 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
initialize_github_syncpreviously committed.envand.mcp.jsonto GitHub on every first sync, regardless of whether the workspace had a.gitignore..gitignoreshipped bygit_service.initialize_git_in_containercovered only shell/cache files and usedcat > .gitignore, clobbering any user-supplied rules. The legacy/home/developer/workspacepath skipped the.gitignorewrite entirely..gitignore, on both the standard and legacy paths.Changes
src/backend/services/git_service.pyDEFAULT_GITIGNORE_DENYLISTmodule constant: credentials first (.env,.env.*,!.env.example,.mcp.json,credentials.json,token.json,*.pem,*.key,*.p12,*.pfx,.aws/credentials,.config/gcloud/), then existing shell/cache entries (preserved for backwards compat)._build_gitignore_merge_command(git_dir)helper: generates a bash script that appends only missing entries to any existing.gitignore, usinggrep -qxFfor exact-line matching. Inner script body and pattern list are both base64-encoded so shell metacharacters in patterns (!,*,/) can't reach the shell.if git_dir == "/home/developer":block so the legacy/home/developer/workspacepath also gets the deny-list.git add .runs — better than committing credentials on a half-configured agent.tests/unit/test_github_init_gitignore.py(new, 14 tests).gitignore→ deny-list written; existing user rules preserved; legacy workspace path covered; idempotency across re-runs; no-trailing-newline edge case; merge runs beforegit add .; failure aborts init.docs/memory/feature-flows/github-repo-initialization.mdTest Plan
pytest tests/unit/test_github_init_gitignore.py -v→ 14/14 passpytest tests/unit/test_github_init_push.py tests/unit/test_github_pat_recreation.py tests/unit/test_git_pull_branch.py tests/test_github_pat_propagation_unit.py→ 31/31 pass (no regressions)inject_credentials→initialize_github_sync→ inspect initial commit tree — asserts.envand.mcp.jsonabsent. (Cannot run from this sandbox; suggest running before merge.)Acceptance Criteria (from #458)
.env,.env.*,.mcp.json,credentials.json,token.json,*.pem,*.keynever committed.gitignorepreserved (appended to, not overwritten)/home/developer/workspacebranch also writes the deny-list.gitignore→ user rules and deny-list both presentNotes
!.env.examplenegation ensures committable env templates still work.git_diris one of two hardcoded constants, and the outer command form isbash -c 'echo <base64> | base64 -d | bash'where the encoded segment is[A-Za-z0-9+/=]only.Closes #458
🤖 Generated with Claude Code