Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project are documented in this file. The format is b

### Added

- **Wildcard domains in asset scope**: a scope line such as `*.example.com`, the way bug bounty programs write a domain and its subdomains, is accepted in company and task asset scope and stored as the `example.com` domain rule, which already covers its subdomains. A URL form (`https://*.example.com/`) works too. The wildcard is accepted only on a registrable domain: `*.api.example.com`, `*.co.uk` and `*.<IP>` are still rejected, because no rule covers only a subdomain's subdomains (#519).
- **Stream viewer direction filter** (follow-up to #380): the Traffic detail's Stream tab can show all messages, client-to-server messages or server-to-client messages. Pagination and refresh keep the selected direction, changing the filter resets the list, and opening another exchange resets the direction to all. Recording-limit warnings remain visible but are excluded from the displayed message counts.
- **Security response headers on every response**: `X-Content-Type-Options: nosniff`, a same-origin referrer policy, `X-Frame-Options: SAMEORIGIN` and a `frame-ancestors 'self'` CSP are now set by one wrapper around the whole handler tree, so the JSON API carries them too; previously only the console route did. Console documents additionally get `Permissions-Policy` and COOP/CORP. `Strict-Transport-Security` is sent only when the request is known to be HTTPS: directly over TLS, or via `X-Forwarded-Proto: https` from a peer in `ARTEX_TRUSTED_PROXIES`, so a direct client cannot claim HTTPS on its own. The README reverse-proxy recipe now starts with an 80 to 443 redirect.
- **Global company switcher**: the sidebar header carries a company picker (search, an explicit "all companies", the asset count). It persists per browser and narrows these views on the server: the findings list, grouped view, asset tree and stat cards (`GET /api/exploration/findings`, `/groups`, `/asset-tree`, `/stats` take `company`), the dashboard findings panels (same list endpoint), the task list (`GET /api/tasks?company=`), the traffic list (`GET /api/traffic?company=`, the hosts the company owns) and the asset tabs (`GET /api/assets?company_id=`, plain and DSL path; the company clause is ANDed outside the compiled DSL). A finding belongs to a company through its live assets. A finding with no live asset belongs to a company only when its task is scoped to that company (`task_scope` kind `company`); otherwise it shows under "all companies" only. An unknown or non-numeric company id returns nothing (#425).
Expand Down
38 changes: 25 additions & 13 deletions db/company_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ func ParseAutoScopeLine(line string) (ParsedScope, error) {
return ParseScopeInput(ScopeInput{Kind: "keyword", Value: raw})
}

func scopeHostname(raw string) (string, error) {
func scopeHostname(raw string) (host string, wildcard bool, err error) {
candidate := strings.TrimSpace(raw)
if candidate == "" {
return "", fmt.Errorf("hostname is empty")
return "", false, fmt.Errorf("hostname is empty")
}
if strings.HasPrefix(candidate, "//") {
candidate = "http:" + candidate
Expand All @@ -180,38 +180,42 @@ func scopeHostname(raw string) (string, error) {
if err == nil {
err = fmt.Errorf("missing hostname")
}
return "", err
return "", false, err
}
host := strings.TrimSuffix(strings.TrimSpace(parsed.Hostname()), ".")
host = strings.TrimSuffix(strings.TrimSpace(parsed.Hostname()), ".")
host, wildcard = strings.CutPrefix(host, "*.")
if host == "" {
return "", fmt.Errorf("hostname is empty")
return "", false, fmt.Errorf("hostname is empty")
}
if ip := net.ParseIP(host); ip != nil {
return ip.String(), nil
if wildcard {
return "", false, fmt.Errorf("a wildcard needs a domain, not an IP")
}
return ip.String(), false, nil
}
host, err = idna.Lookup.ToASCII(host)
if err != nil {
return "", err
return "", false, err
}
host = strings.ToLower(host)
if len(host) > 253 {
return "", fmt.Errorf("domain exceeds 253 characters")
return "", false, fmt.Errorf("domain exceeds 253 characters")
}
labels := strings.Split(host, ".")
if len(labels) < 2 {
return "", fmt.Errorf("domain needs at least two labels")
return "", false, fmt.Errorf("domain needs at least two labels")
}
for _, label := range labels {
if label == "" || len(label) > 63 || label[0] == '-' || label[len(label)-1] == '-' {
return "", fmt.Errorf("invalid domain label")
return "", false, fmt.Errorf("invalid domain label")
}
for _, r := range label {
if !((r >= 'a' && r <= 'z') || (r >= '0' && r <= '9') || r == '-') {
return "", fmt.Errorf("domain contains invalid characters")
return "", false, fmt.Errorf("domain contains invalid characters")
}
}
}
return host, nil
return host, wildcard, nil
}

// ParseScopeLine classifies and validates one scope line (root domain / IP /
Expand Down Expand Up @@ -245,10 +249,18 @@ func ParseScopeLine(line string) (ParsedScope, error) {
}
return r, nil
}
host, err := scopeHostname(raw)
host, wildcard, err := scopeHostname(raw)
if err != nil {
return r, fmt.Errorf("not recognizable as a valid domain/IP/CIDR: %s", raw)
}
// "*.example.com" is how bug bounty programs write a domain and its
// subdomains, which is what a domain rule on example.com covers (assets match
// on their registrable domain). A deeper wildcard has no such rule yet.
if wildcard {
if root, err := publicsuffix.EffectiveTLDPlusOne(host); err != nil || root != host {
return r, fmt.Errorf("a wildcard is only supported on a registrable domain such as *.example.com: %s", raw)
}
}
if ip := net.ParseIP(host); ip != nil {
r.Kind = "ip"
if ip.To4() != nil {
Expand Down
68 changes: 68 additions & 0 deletions db/company_scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ func TestParseScopeLine(t *testing.T) {
{"co.uk", "", true}, // bare public suffix
{"not a host", "", true},
{"1.2.3.1-1.2.3.9", "", true}, // ranges must be CIDR
{"*.example.com", "domain", false},
{"https://*.example.co.uk/path", "domain", false},
{"*.api.example.com", "", true}, // no rule covers only a subdomain's subdomains
{"*.co.uk", "", true},
{"*.com", "", true},
{"*.1.2.3.4", "", true},
{"api.*.example.com", "", true},
{"*example.com", "", true},
}
for _, c := range cases {
r, err := ParseScopeLine(c.in)
Expand Down Expand Up @@ -77,6 +85,11 @@ func TestParseAutoScopeLine(t *testing.T) {
{name: "overbroad cidr", input: "10.0.0.0/8", wantErr: true},
{name: "bare suffix", input: "co.uk", wantErr: true},
{name: "empty domain label", input: "foo..example.com", wantErr: true},
{name: "wildcard domain", input: "*.example.com", kind: "domain", normalized: "example.com"},
{name: "wildcard url", input: "https://*.Example.com:8443/", kind: "domain", normalized: "example.com"},
{name: "wildcard idn", input: "*.bücher.de", kind: "domain", normalized: "xn--bcher-kva.de"},
{name: "wildcard subdomain", input: "*.api.example.com", wantErr: true},
{name: "wildcard suffix", input: "*.co.uk", wantErr: true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
Expand Down Expand Up @@ -426,3 +439,58 @@ func TestCompanyScopeAttribution(t *testing.T) {
}
mustNil(ipOutID, "out-of-CIDR ip")
}

// A "*.example.com" line is stored as the example.com domain rule, so it
// attributes the subdomains just as a plain example.com line does.
func TestCompanyScopeWildcardAttribution(t *testing.T) {
d, err := Open(testDSN(t))
if err != nil {
SkipPGUnavailable(t, err)
}
as := d.Assets()
cs := d.Companies()

var startMax int64
if err := d.QueryRow(`SELECT COALESCE(MAX(id),0) FROM assets`).Scan(&startMax); err != nil {
d.Close()
t.Fatalf("startMax: %v", err)
}
var cid int64
t.Cleanup(func() {
defer d.Close()
if _, err := d.Exec(`DELETE FROM assets WHERE id > $1`, startMax); err != nil {
t.Errorf("cleanup assets: %v", err)
}
if cid != 0 {
if _, err := d.Exec(`DELETE FROM companies WHERE id = $1`, cid); err != nil {
t.Errorf("cleanup company %d: %v", cid, err)
}
}
})

uniq := fmt.Sprintf("%d%d", time.Now().UnixNano(), rand.Uint32())
root := fmt.Sprintf("wildcardtest%s.com", uniq)
cid, _, err = cs.UpsertCompany(fmt.Sprintf("WildcardCo %s", uniq), "")
if err != nil {
t.Fatalf("UpsertCompany: %v", err)
}
cs.AddScope(cid, []string{"*." + root}, "unit test")

var domain string
if err := d.QueryRow(`SELECT domain FROM company_scope WHERE company_id = $1 AND kind = 'domain'`, cid).Scan(&domain); err != nil {
t.Fatalf("read scope: %v", err)
}
if domain != root {
t.Fatalf("stored domain = %q, want %q", domain, root)
}

id, err := as.UpsertSubdomain(UpsertSubdomainReq{Domain: "api." + root})
if err != nil {
t.Fatalf("UpsertSubdomain: %v", err)
}
var got *int64
d.QueryRow(`SELECT company_id FROM assets WHERE id = $1`, id).Scan(&got)
if got == nil || *got != cid {
t.Fatalf("api.%s company_id = %v, want %d", root, got, cid)
}
}
16 changes: 10 additions & 6 deletions web/src/lib/company-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ function domainHostname(value: string): string | null {
if (value.startsWith("//")) candidate = `http:${value}`;
else if (!value.includes("://")) candidate = `http://${value}`;
const url = new URL(candidate);
return (
url.hostname
.replace(/^\[|\]$/g, "")
.replace(/\.$/, "")
.toLowerCase() || null
);
const hostname = url.hostname
.replace(/^\[|\]$/g, "")
.replace(/\.$/, "")
.toLowerCase();
// "*.example.com" scopes a domain and its subdomains; the server accepts it on a registrable domain.
if (hostname.startsWith("*.")) {
const domain = hostname.slice(2);
return ipVersion(domain) === null ? domain : null;
}
return hostname || null;
} catch {
return null;
}
Expand Down
Loading