mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-25 09:20:53 +08:00
fix(server): seed a goal URL that is followed by punctuation
parseTarget pulls the first URL out of the goal with https?://[^\s'"]+, which keeps any punctuation that follows it. "Assess http://juiceshop:3000." matches "http://juiceshop:3000.", url.Parse rejects the port, and the seed logs "could not parse a target host/IP" even though goalGateCheck accepted the same goal. A dotted host only survived through the domain fallback, which takes the scheme from the port, and a sentence-final period stayed in the host. Trim trailing punctuation before parsing the URL, including full-width punctuation from pasted text. A closing bracket is trimmed only when the URL has no matching opener, so a bracketed IPv6 host like http://[::1] still parses.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user