fix: harden config loading and ssh addresses, stop resolver on API errors
- read netssh.yaml from the user config directory only, not from the working directory - refuse addresses from NetBox or the cache that are neither an IP address nor a hostname (ssh read "-oProxyCommand=…" as an option) - resolver chain stops at an API failure; only "no address" falls through to the next strategy - netssh --help and -h show netssh's help - start at most one background cache refresh per 5 minutes - validate the legacy netbox.url - page through all IP addresses of a host - CI: run format check, vet, and tests on pull requests and main - changelog for v0.0.25 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
6e80b733dc
commit
4287b7b650
19 files changed
+317
-30
No files matched your search
@@ -196,3 +196,27 @@ func TestLoad_InvalidShortcutRewrite(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A netssh.yaml in the working directory (e.g. of a cloned repository) must
|
||||
// not be loaded: it could inject ssh options such as ProxyCommand.
|
||||
func TestLoad_IgnoresConfigInWorkingDirectory(t *testing.T) {
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("NETSSH_NETBOX_URL", "")
|
||||
t.Chdir(writeConfig(t, "hosts:\n - name: evil\n address: 10.0.0.1\nssh:\n options:\n ProxyCommand: touch /tmp/pwned\n"))
|
||||
cfg, err := Load()
|
||||
if err != nil {
|
||||
t.Fatalf("Load: %v", err)
|
||||
}
|
||||
if len(cfg.Hosts) != 0 || len(cfg.SSH.Options) != 0 {
|
||||
t.Errorf("config from the working directory was loaded: %+v", cfg)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoad_RejectsInvalidLegacyNetBoxURL(t *testing.T) {
|
||||
for _, bad := range []string{"netbox.example.com", "ftp://netbox.example.com", "https://netbox.example.com/?x=1"} {
|
||||
t.Setenv("XDG_CONFIG_HOME", writeConfig(t, "netbox:\n url: \""+bad+"\"\n token: t\n"))
|
||||
if _, err := Load(); err == nil || !strings.Contains(err.Error(), "netbox.url") {
|
||||
t.Errorf("%s: got %v, want a netbox.url error", bad, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user