Skip to content

Harden git clone argv and config file permissions#54

Merged
andrew merged 1 commit intomainfrom
security-hardening
Apr 13, 2026
Merged

Harden git clone argv and config file permissions#54
andrew merged 1 commit intomainfrom
security-hardening

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented Apr 13, 2026

Two security fixes from a code review, both test-driven.

git clone argument injection: repo.CloneURL comes from the forge API and was passed directly to exec.CommandContext(ctx, "git", "clone", url). A malicious or compromised self-hosted instance could return a CloneURL like --upload-pack=... which git would parse as an option rather than a URL. The fix extracts a gitCloneArgs helper that inserts -- before the URL to terminate option parsing. Applied to all three call sites in repo create --clone, repo fork --clone, and repo clone.

Config file permissions: os.WriteFile(path, data, 0600) only sets the mode when creating a new file. If ~/.config/forge/config already exists with looser permissions (manual creation, backup restore), writing a token via SetDomain would not tighten it. Now writeINI calls os.Chmod after the write on non-Windows platforms.

Both tests fail on main and pass after the fix.

@andrew andrew merged commit 454ab9d into main Apr 13, 2026
4 checks passed
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.

1 participant