mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-27 10:20:54 +08:00
fix(traffic): match default-port WebSocket captures in traffic_search
A WebSocket over a default port is recorded as ws://host or wss://host, so host:80 and host:443 searches still missed it. Also match the ws and wss portless forms.
This commit is contained in:
+5
-3
@@ -2421,12 +2421,14 @@ func (t *Traffic) query(host, contains, bodyContains string, page, limit int) ([
|
||||
authority := net.JoinHostPort(hostName, port)
|
||||
prefixes := []string{"%://" + authority}
|
||||
// Clients leave a default port out of the Host header, so a capture
|
||||
// of https://host:443 is recorded as https://host.
|
||||
// of https://host:443 is recorded as https://host, and a WebSocket
|
||||
// over it as wss://host.
|
||||
bare := strings.TrimSuffix(authority, ":"+port)
|
||||
switch port {
|
||||
case "80":
|
||||
prefixes = append(prefixes, "http://"+strings.TrimSuffix(authority, ":80"))
|
||||
prefixes = append(prefixes, "http://"+bare, "ws://"+bare)
|
||||
case "443":
|
||||
prefixes = append(prefixes, "https://"+strings.TrimSuffix(authority, ":443"))
|
||||
prefixes = append(prefixes, "https://"+bare, "wss://"+bare)
|
||||
}
|
||||
var conds []string
|
||||
for _, p := range prefixes {
|
||||
|
||||
@@ -455,6 +455,11 @@ func TestQueryHostDefaultPort(t *testing.T) {
|
||||
v6 := newFlow("x", "GET", "/", nil, []byte("v6"))
|
||||
v6.Request.URL, _ = url.Parse("https://[2001:db8::1]/admin")
|
||||
tr.record(v6)
|
||||
ws := newFlow("x", "GET", "/", nil, nil)
|
||||
ws.Request.URL, _ = url.Parse("https://chat.example.com/socket")
|
||||
if _, err := tr.recordStreamStart(flowRequestView(ws.Request), responseView{}, "websocket", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, tc := range []struct {
|
||||
host string
|
||||
@@ -466,6 +471,7 @@ func TestQueryHostDefaultPort(t *testing.T) {
|
||||
{host: "http://shop.example.com:80/", want: "http://shop.example.com/plain"},
|
||||
{host: "shop.example.com:8443", want: "http://shop.example.com:8443/alt"},
|
||||
{host: "[2001:db8::1]:443", want: "https://[2001:db8::1]/admin"},
|
||||
{host: "chat.example.com:443", want: "wss://chat.example.com/socket"},
|
||||
} {
|
||||
rows, err := tr.query(tc.host, "", "", 0, 10)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user