feat: Add proxy_install_only config to restrict proxy to download commands

Introduces proxy_install_only (default: false) which, when enabled,
skips the proxy for package manager commands that do not download
packages (e.g. npm ls, pip list), avoiding unnecessary MITM overhead.

- Add ProxyInstallOnly to Config and config template
- Add IsKnownDownloadCommand / MayDownloadPackages to ParsedCommand
- Add DownloadCommands to npm and pypi PM configs covering update,
  ci, audit, dlx, exec, x, download, run and equivalents per PM
- Extract shared runner.Execute used by both proxy flow and guard
- Proxy flow short-circuits to runner.Execute for non-download commands
  when proxy_install_only=true
This commit is contained in:
Sahilb315
2026-04-13 20:15:50 +05:30
parent 887984612c
commit da098a51a8
11 changed files with 387 additions and 69 deletions
+37 -12
View File
@@ -18,35 +18,42 @@ type pypiCommandParser interface {
}
type PypiPackageManagerConfig struct {
InstallCommands []string
CommandName string
InstallCommands []string
DownloadCommands []string
CommandName string
}
func DefaultPipPackageManagerConfig() PypiPackageManagerConfig {
return PypiPackageManagerConfig{
InstallCommands: []string{"install"},
CommandName: "pip",
InstallCommands: []string{"install"},
DownloadCommands: []string{"download"},
CommandName: "pip",
}
}
func DefaultPip3PackageManagerConfig() PypiPackageManagerConfig {
return PypiPackageManagerConfig{
InstallCommands: []string{"install"},
CommandName: "pip3",
InstallCommands: []string{"install"},
DownloadCommands: []string{"download"},
CommandName: "pip3",
}
}
func DefaultUvPackageManagerConfig() PypiPackageManagerConfig {
return PypiPackageManagerConfig{
InstallCommands: []string{"add", "install"},
CommandName: "uv",
// "download" covers both `uv pip download` and bare `uv download`.
// "run" covers `uv run` which auto-installs script dependencies.
DownloadCommands: []string{"download", "run"},
CommandName: "uv",
}
}
func DefaultPoetryPackageManagerConfig() PypiPackageManagerConfig {
return PypiPackageManagerConfig{
InstallCommands: []string{"add"},
CommandName: "poetry",
InstallCommands: []string{"add"},
DownloadCommands: []string{"update", "install"},
CommandName: "poetry",
}
}
@@ -123,7 +130,13 @@ func (p *pipCommandParser) ParseCommand(args []string) (*ParsedCommand, error) {
}
if installCmdIndex == -1 {
// No install command found, return as-is
// Check if this is a known download command
for _, arg := range args {
if slices.Contains(p.config.DownloadCommands, arg) {
return &ParsedCommand{Command: command, IsKnownDownloadCommand: true}, nil
}
}
return &ParsedCommand{Command: command}, nil
}
@@ -242,7 +255,13 @@ func (u *uvCommandParser) ParseCommand(args []string) (*ParsedCommand, error) {
}
if installCmdIndex == -1 {
// No install command found, return as-is
// Check if this is a known download command
for _, arg := range args {
if slices.Contains(u.config.DownloadCommands, arg) {
return &ParsedCommand{Command: command, IsKnownDownloadCommand: true}, nil
}
}
return &ParsedCommand{Command: command}, nil
}
@@ -340,7 +359,13 @@ func (p *poetryCommandParser) ParseCommand(args []string) (*ParsedCommand, error
}
if installCmdIndex == -1 {
// No install command found, return as-is
// Check if this is a known download command
for _, arg := range args {
if slices.Contains(p.config.DownloadCommands, arg) {
return &ParsedCommand{Command: command, IsKnownDownloadCommand: true}, nil
}
}
return &ParsedCommand{Command: command}, nil
}