#1237

sandbox: most gh subcommands are not classified as network, so they run with network denied and never prompt

OpenFabioLeitaoopened 15d ago

Summary

ghUsesNetwork in internal/sandbox/analyzer.go treats only three gh invocations as network access: gh api, gh release download and gh repo clone. Every other gh subcommand that talks to GitHub (gh issue …, gh pr …, gh run …, gh repo view, gh search …, gh workflow …, gh release view/list) is classified as a local command. It therefore runs with the network denied and never reaches the permission flow that offers a network grant, unlike git push or curl.

Evidence

Same function on main (8288ae81) and on the v0.14.0 tag:

func ghUsesNetwork(words []string) bool {
	first := firstSubcommand(words, nil)
	if first == "api" {
		return true
	}
	second := secondSubcommand(words)
	return (first == "release" && second == "download") ||
		(first == "repo" && second == "clone")
}

The only test that pins this is internal/sandbox/analyzer_test.go (gh release download v1.0.0 → network: true). No test asserts that the other subcommands are local, so this looks like an incomplete allowlist rather than a decision.

Expected

Treat every gh subcommand as network access except an explicit local list (--help, --version, completion, config, alias, extension list, …), so the user gets the normal network prompt.

Notes

  • Linux, linux-bwrap backend, sandbox.network at its default (deny).
  • I found this by reading the classifier and have not yet reproduced the network failure end to end, because in my setup gh first fails earlier for a credentials reason (reported separately).
  • Related: #703 (network grants), #815 (credential deny list).

Activity

1
Vasanthdev200415d ago

Confirmed on main at 8288ae81. ghUsesNetwork returns true for api, release download and repo clone only. I ran the function on a few forms: gh pr list, gh issue view 5 and gh run watch all come back false, so they are planned as local commands and run with the network denied, with no prompt. Nothing leaks; the command just fails where git push would have asked.

Approved, labelled bug and issue-approved. Three things for the PR:

  • Invert it, as you propose. Every gh subcommand is network unless it is on a short local list, so a new or aliased subcommand lands on the prompting side by default.
  • Options that take a value shift the words. firstSubcommand and secondSubcommand skip a word that starts with - but not the value after it. gh release -R owner/repo download v1 comes back false today, because owner/repo is read as the second word. The inversion makes that particular case safe, but the local list is matched the same way, so please add cases with a value-taking option in front of and between the subcommand words.
  • There is a second list. unparseableNetworkPattern in internal/sandbox/risk.go has its own gh alternative with the same three forms, for commands the parser gives up on. Both have to read one rule, or gh pr list inside a Windows conditional keeps the old answer.

Tests on the classifier are enough here. No need to reproduce the network failure end to end.