Reject peer-originated Remote relay membership

This commit is contained in:
ak47 committed 2026-11-04 14:43:22 -05:00
1 parent 393ff90f00
commit c158321b40
7 files changed
+62 -27

No files matched your search

+19
View File
@@ -359,3 +359,22 @@ func TestConnectionWorkflowOldStatusCannotDisconnectNewEpoch(t *testing.T) {
t.Fatal("old status controls disconnected a new connection", status)
}
}
func TestConnectionWorkflowPendingApprovalExpiry(t *testing.T) {
c, f := fixtureCoordinator(t, nil)
action := approve(t, c, f, 1, "controller")
w := workflowFixture(t, c, action, endpoint{host: "relay.invalid", port: 6837}, nil)
f.events <- sdk.SessionEvent{Sequence: 2, Kind: "remote.revoked", Action: action.Action, Epoch: action.Epoch, Reason: "expired"}
awaitDone(t, w.done)
if !w.form().Done {
t.Fatal("expired approval retained connection controls")
}
if err := c.connect(action, w.target, "synthetic-key"); err != errLease {
t.Fatal("expired approval connected", err)
}
select {
case call := <-f.calls:
t.Fatal("expired setup made a reader call", call.method)
default:
}
}
+1 -1
View File
@@ -40,7 +40,7 @@ func (s *session) accept(epoch uint64, m message) (bool, error) {
switch m.kind {
case "channel_joined":
v, ok := m.payload.(membership)
if !ok || s.state != "joining" || len(v.peers) > 1 {
if !ok || m.origin != 0 || s.state != "joining" || len(v.peers) > 1 {
return s.suspend(errPeer)
}
s.state = "waiting"
+8
View File
@@ -117,3 +117,11 @@ func TestSessionIgnoresUnsupportedEffects(t *testing.T) {
t.Fatal("closed session accepted output")
}
}
func TestSessionRejectsPeerOriginatedChannelJoin(t *testing.T) {
s, _ := newSession(controller, 1)
m := mustMessage(t, `{"type":"channel_joined","origin":7,"channel":"fixture","clients":[{"id":7,"connection_type":"slave"}]}`)
if accepted, err := s.accept(1, m); accepted || err != errPeer || s.state != "suspended" {
t.Fatal("peer supplied relay membership", accepted, err, s.state)
}
}
+3
View File
@@ -188,6 +188,9 @@ func connect(ctx context.Context, e endpoint, r role, key string) (*relayConn, m
}
continue
case "channel_joined":
if m.origin != 0 {
return nil, message{}, errPeer
}
v := m.payload.(membership)
if v.channel != key {
return nil, message{}, errProtocol
+1
View File
@@ -244,6 +244,7 @@ func TestJoinRejectsUnexpectedTraffic(t *testing.T) {
cert, roots := testCertificate(t, true)
for _, reply := range []string{
`{"type":"channel_joined","channel":"wrong-fixture"}`,
`{"type":"channel_joined","origin":7,"channel":"synthetic-fixture","clients":[{"id":7,"connection_type":"slave"}]}`,
`{"type":"error","message":"do not expose this text"}`,
`{"type":"speak","origin":7,"sequence":["before join"]}`,
`{"type":"ping","origin":7}`,