Merge pull request #425 from joanrodriguez/feat/company-switcher

feat(web): global company switcher in the sidebar
This commit is contained in:
BaaRai
2026-11-22 22:43:32 +01:00
committed by GitHub
24 changed files with 1006 additions and 85 deletions
+25 -11
View File
@@ -1273,17 +1273,19 @@ const (
// of -1 skip the response-size bounds. An empty Sort/Order defaults to
// newest-first by timestamp.
type PageQuery struct {
Host string // host substring
Method string // exact method (case-insensitive)
Query string // broad search box: metadata columns OR captured text
Body string // content box: captured request/response text only (full-text)
Path string // url_template substring — the vulnerability's path
Status string // exact code ("404") or class bucket ("4xx")
Rewritten string // all (default) | rewritten (or true) | original (or false)
RespMin int64 // minimum resp_len, or -1 when unset
RespMax int64 // maximum resp_len, or -1 when unset
Sort string // ts | status | resp_len (default ts)
Order string // asc | desc (default desc)
Host string // host substring
Hosts []string // exact host allowlist (company scope); empty = no filter
MatchNone bool // force an empty result (a company that owns no host yet)
Method string // exact method (case-insensitive)
Query string // broad search box: metadata columns OR captured text
Body string // content box: captured request/response text only (full-text)
Path string // url_template substring — the vulnerability's path
Status string // exact code ("404") or class bucket ("4xx")
Rewritten string // all (default) | rewritten (or true) | original (or false)
RespMin int64 // minimum resp_len, or -1 when unset
RespMax int64 // maximum resp_len, or -1 when unset
Sort string // ts | status | resp_len (default ts)
Order string // asc | desc (default desc)
}
// rewriteFilterSQL turns a rewritten filter token into a SQL condition over
@@ -1337,6 +1339,18 @@ func (t *Traffic) pageWhere(f PageQuery) (where string, args []any) {
if h := strings.TrimSpace(f.Host); h != "" {
add("host LIKE ?", "%"+h+"%")
}
if f.MatchNone {
add("1=0")
}
if len(f.Hosts) > 0 {
placeholders := make([]string, len(f.Hosts))
args2 := make([]any, len(f.Hosts))
for i, h := range f.Hosts {
placeholders[i] = "?"
args2[i] = h
}
add("host IN ("+strings.Join(placeholders, ",")+")", args2...)
}
if m := strings.TrimSpace(f.Method); m != "" {
add("method=?", strings.ToUpper(m))
}
+25
View File
@@ -616,3 +616,28 @@ VALUES(?,?,?,?,?,?,?,?,?,?,?)`, id, ts, host, "GET", "/p/"+id, "https://"+host+"
t.Fatalf("Search rewritten flags = %v", found)
}
}
// TestPageHostsAllowlist pins the company-scope filter: an exact host allowlist
// keeps only those hosts (the substring Host filter stays independent), and
// MatchNone forces an empty result for a company that owns no host.
func TestPageHostsAllowlist(t *testing.T) {
tr, _ := openTraffic(t)
tr.record(newFlow("api.example.com", "GET", "/a", nil, []byte("a")))
tr.record(newFlow("api.other.example", "GET", "/b", nil, []byte("b")))
tr.record(newFlow("shop.example.com", "GET", "/c", nil, []byte("c")))
rows, total, err := tr.Page(PageQuery{Hosts: []string{"api.example.com", "shop.example.com"}, RespMin: -1, RespMax: -1}, 0, 100)
if err != nil || total != 2 || len(rows) != 2 {
t.Fatalf("allowlist should keep 2 rows, got total=%d rows=%d err=%v", total, len(rows), err)
}
// Exact match: api.other.example is not api.example.com.
if rows, _, err := tr.Page(PageQuery{Hosts: []string{"api.example.com"}, RespMin: -1, RespMax: -1}, 0, 100); err != nil || len(rows) != 1 {
t.Fatalf("exact allowlist should keep 1 row, got %d err=%v", len(rows), err)
}
if _, total, err := tr.Page(PageQuery{MatchNone: true, RespMin: -1, RespMax: -1}, 0, 100); err != nil || total != 0 {
t.Fatalf("MatchNone should match nothing, got total=%d err=%v", total, err)
}
if _, total, err := tr.Page(PageQuery{RespMin: -1, RespMax: -1}, 0, 100); err != nil || total != 3 {
t.Fatalf("no filter should return all 3, got %d err=%v", total, err)
}
}