ARTEX - AI autonomous penetration testing system (English translation; upstream: Autumn-27/ARTEX, AGPL-3.0)
Go aiai-agentsautonomous-agentsbug-bountydockergolanglinuxllmmcpnextjspenetration-testingpentestpostgresqlreareactred-teamsecuritysecurity-automationsqlitetypescript
fix(server): seed a goal URL that is followed by punctuation
Phantom-IN2efc2aca68ad
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 4a103f8..d7327ca 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -12,6 +12,7 @@ All notable changes to this project are documented in this file. The format is b### Fixed+- **A goal URL followed by punctuation is still seeded**: a goal such as `Assess http://juiceshop:3000.` no longer logs `could not parse a target host/IP` and skips the site. Trailing punctuation, including full-width `。` and a closing bracket that has no matching opener, is trimmed from the URL before it is parsed, so `http://[::1]` is left alone. The scheme the goal names is kept and a final period does not end up in the host.- **Task timeout triggers fire for every task**: `on_task_timeout` used the task id as a watermark, but tasks time out in deadline order. Once a newer task timed out first, an older task that timed out later was never fired for. Fired timeouts are now kept in a persisted set, like met goals; on first start the set is seeded with the tasks already timed out, so nothing replays.- **A named pipe in the task workspace no longer hangs the archive worker**: packing opened every non-directory entry, and opening a FIFO blocks until a writer appears, so the single archive worker stopped there and every later archive, restore and delete job waited behind it. A socket failed the archive instead, and a device was packed but refused on restore. The packer now skips every entry that is neither a directory nor a regular file, as it already did for symlinks.- **Task form does not keep test-account secrets on screen**: after a task is created the credential rows are cleared, and the password field is masked.diff --git a/server/parse_target_test.go b/server/parse_target_test.gonew file mode 100644index 0000000..2ee9c78--- /dev/null+++ b/server/parse_target_test.go@@ -0,0 +1,38 @@+package server++import "testing"++func TestParseTargetURLFollowedByPunctuation(t *testing.T) {+ cases := []struct {+ text string+ scheme string+ host string+ port int+ }{+ {"Assess http://juiceshop:3000, then report.", "http", "juiceshop", 3000},+ {"Assess http://juiceshop:3000.", "http", "juiceshop", 3000},+ {"Scope: http://juiceshop:3000; nothing else", "http", "juiceshop", 3000},+ {"The lab (http://juiceshop:3000) is ours", "http", "juiceshop", 3000},+ {"Test https://app.example.com:8080, only the API", "https", "app.example.com", 8080},+ {"Target is https://example.com.", "https", "example.com", 443},+ {"Start at https://example.com/login?next=/a, then pivot", "https", "example.com", 443},+ {"http://juiceshop:3000", "http", "juiceshop", 3000},+ {"Assess http://juiceshop.", "http", "juiceshop", 80},+ {"Assess http://10.0.0.5.", "http", "10.0.0.5", 80},+ {"Assess http://juiceshop:3000。", "http", "juiceshop", 3000},+ {"Assess “http://juiceshop:3000”", "http", "juiceshop", 3000},+ {"See https://en.wikipedia.org/wiki/Foo_(bar).", "https", "en.wikipedia.org", 443},+ {"(https://en.wikipedia.org/wiki/Foo_(bar))", "https", "en.wikipedia.org", 443},+ {"http://[::1]", "http", "::1", 80},+ {"http://[::1]:8080", "http", "::1", 8080},+ {"Assess http://[fd00::10].", "http", "fd00::10", 80},+ {"[http://[::1]:8080]", "http", "::1", 8080},+ }+ for _, c := range cases {+ scheme, host, port, ok := parseTarget(c.text)+ if !ok || scheme != c.scheme || host != c.host || port != c.port {+ t.Errorf("parseTarget(%q) = %q, %q, %d, %v; want %q, %q, %d, true",+ c.text, scheme, host, port, ok, c.scheme, c.host, c.port)+ }+ }+}diff --git a/server/server.go b/server/server.goindex b694e8d..e6cc2b4 100644--- a/server/server.go+++ b/server/server.go@@ -23,6 +23,7 @@ import ("sync""sync/atomic""time"+ "unicode/utf8""github.com/Autumn-27/artex/agent""github.com/Autumn-27/artex/archivestore"@@ -1945,11 +1946,33 @@ var (reDomain = regexp.MustCompile(`\b((?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})(?::(\d{1,5}))?`))+// trimURLTail drops sentence punctuation that free text puts after a URL+// ("Assess http://host:3000."). A closing bracket is dropped only when it has no+// opener in the URL, so "http://[::1]" keeps its "]".+func trimURLTail(s string) string {+ for s != "" {+ r, size := utf8.DecodeLastRuneInString(s)+ switch r {+ case '.', ',', ';', ':', '!', '?', '。', ',', '、', ';', ':', '!', '?', '”', '’':+ case ')', ']', '}', '>':+ open := string("([{<"[strings.IndexRune(")]}>", r)])+ if strings.Count(s, open) >= strings.Count(s, string(r)) {+ return s+ }+ default:+ return s+ }+ s = s[:len(s)-size]+ }+ return s+}+// parseTarget extracts a target (scheme, host, port) from free text, supporting// full URLs, IP[:port] and domain[:port]. ok=false when nothing parseable.func parseTarget(text string) (scheme, host string, port int, ok bool) {text = strings.TrimSpace(text)if m := reURL.FindString(text); m != "" {+ m = trimURLTail(m)if u, err := url.Parse(m); err == nil && u.Hostname() != "" {scheme = strings.ToLower(u.Scheme)host = strings.ToLower(u.Hostname())