mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-06 04:14:15 +00:00
Review of the scope filter: - netip.ParseAddr accepts any text after % as an IPv6 zone, commas included, so "fe80::1%eth0,10.0.0.0/8" was kept and the comma join added 10.0.0.0/8. Zoned addresses are now dropped, and every kept entry is passed on in canonical form (p.Masked().String(), a.String()), which never holds a comma or space. IPv4-mapped entries become the IPv4 range they map. - The cap was 1,024 entries; a company scope can be larger. It is now 8,192 entries and 120 KiB per list (the proxy gets each list as one environment string, limited to 128 KiB). - The runner logs dropped entries with the task ID and their values (up to 20), so an operator can see why an approved target is refused. - More names that make a shell or interpreter run extra code are refused: SHELLOPTS, BASHOPTS, PS4, IFS, PROMPT_COMMAND, GLIBC_TUNABLES, PYTHONSTARTUP, PYTHONHOME, NODE_OPTIONS, PERL5OPT, PERL5LIB, RUBYOPT, JAVA_TOOL_OPTIONS, GIT_SSH_COMMAND, GIT_CONFIG_PARAMETERS.
62 lines
2.8 KiB
Go
62 lines
2.8 KiB
Go
package sandbox
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestValidateEnvRefusesReservedNames(t *testing.T) {
|
|
for _, k := range []string{"PATH", "path", "HTTP_PROXY", "https_proxy", "All_Proxy", "no_proxy",
|
|
"LD_PRELOAD", "LD_LIBRARY_PATH", "ld_audit", "BASH_ENV", "env", "GCONV_PATH", "PythonPath",
|
|
"SHELLOPTS", "PS4", "NODE_OPTIONS", "PERL5OPT", "GIT_SSH_COMMAND", "GLIBC_TUNABLES"} {
|
|
if err := ValidateEnv(map[string]string{k: "x"}); !errors.Is(err, ErrBadRequest) {
|
|
t.Errorf("ValidateEnv(%s) = %v", k, err)
|
|
}
|
|
// The panel drops them instead of sending a request the runner refuses.
|
|
if got := FilterPanelEnv([]string{k + "=x", "KEEP=1"}); len(got) != 1 || got["KEEP"] != "1" {
|
|
t.Errorf("FilterPanelEnv kept %s: %v", k, got)
|
|
}
|
|
}
|
|
if err := ValidateEnv(map[string]string{"PYTHONUNBUFFERED": "1", "LANGUAGE": "en", "ENVIRONMENT": "x"}); err != nil {
|
|
t.Fatalf("ordinary names refused: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidateExecRequestFiltersScopeEntries(t *testing.T) {
|
|
req := ExecRequest{Argv: []string{"true"},
|
|
ScopeDomains: []string{"example.com", "a.example,evil.example", "*.example.org", "a.example evil", "",
|
|
"example.com:8443", "https://x", "api-*.example.com", "xn--bcher-kva.example", "bücher.example", "host_1.lab.", strings.Repeat("a", 254)},
|
|
ScopeCIDRs: []string{"203.0.113.0/24", "1.2.3.4/32,10.0.0.0/8", "10.0.0.0/33", " 10.0.0.1", "198.51.100.7", "2001:db8::/32",
|
|
"fe80::1%eth0,10.0.0.0/8", "::1%a,0.0.0.0/0", "fe80::1%eth0", "203.0.113.9/24", "::ffff:10.1.0.0/112", "::ffff:198.51.100.8"}}
|
|
if err := ValidateExecRequest(&req); err != nil {
|
|
t.Fatalf("invalid entries failed the request: %v", err)
|
|
}
|
|
// Invalid entries are dropped whole (never split at the comma); valid ones stay.
|
|
if got := strings.Join(req.ScopeDomains, " "); got != "example.com *.example.org xn--bcher-kva.example bücher.example host_1.lab." {
|
|
t.Errorf("domains = %q", got)
|
|
}
|
|
// An IPv6 zone may hold any text, commas included, so zoned addresses are
|
|
// dropped; entries are passed on in canonical form, mapped ones as IPv4.
|
|
if got := strings.Join(req.ScopeCIDRs, " "); got != "203.0.113.0/24 198.51.100.7 2001:db8::/32 203.0.113.0/24 10.1.0.0/16 198.51.100.8" {
|
|
t.Errorf("CIDRs = %q", got)
|
|
}
|
|
long := make([]string, MaxScopeBytes/200)
|
|
for i := range long {
|
|
long[i] = strings.Repeat("a", 240) + ".example"
|
|
}
|
|
if err := ValidateExecRequest(&ExecRequest{Argv: []string{"true"}, ScopeDomains: long}); !errors.Is(err, ErrBadRequest) {
|
|
t.Errorf("%d bytes of scope accepted: %v", joinedLen(long), err)
|
|
}
|
|
many := make([]string, MaxScopeEntries+1)
|
|
for i := range many {
|
|
many[i] = "a.example"
|
|
}
|
|
for _, req := range []ExecRequest{{ScopeDomains: many}, {ScopeCIDRs: many}} {
|
|
req.Argv = []string{"true"}
|
|
if err := ValidateExecRequest(&req); !errors.Is(err, ErrBadRequest) {
|
|
t.Errorf("%d scope entries accepted: %v", len(many), err)
|
|
}
|
|
}
|
|
}
|