Skip to content

Commit fda21f1

Browse files
committed
fix(gateway): tolerate legacy paired metadata in ws upgrade checks
1 parent 22f2acf commit fda21f1

File tree

1 file changed

+28
-24
lines changed

1 file changed

+28
-24
lines changed

src/gateway/server/ws-connection/message-handler.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -711,43 +711,47 @@ export function attachGatewayWsMessageHandler(params: {
711711
return;
712712
}
713713
} else {
714+
const hasLegacyPairedMetadata =
715+
paired.roles === undefined && paired.scopes === undefined;
714716
const pairedRoles = Array.isArray(paired.roles)
715717
? paired.roles
716718
: paired.role
717719
? [paired.role]
718720
: [];
719-
const allowedRoles = new Set(pairedRoles);
720-
if (allowedRoles.size === 0) {
721-
logUpgradeAudit("role-upgrade", pairedRoles, paired.scopes);
722-
const ok = await requirePairing("role-upgrade");
723-
if (!ok) {
724-
return;
725-
}
726-
} else if (!allowedRoles.has(role)) {
727-
logUpgradeAudit("role-upgrade", pairedRoles, paired.scopes);
728-
const ok = await requirePairing("role-upgrade");
729-
if (!ok) {
730-
return;
731-
}
732-
}
733-
734-
const pairedScopes = Array.isArray(paired.scopes) ? paired.scopes : [];
735-
if (scopes.length > 0) {
736-
if (pairedScopes.length === 0) {
737-
logUpgradeAudit("scope-upgrade", pairedRoles, pairedScopes);
738-
const ok = await requirePairing("scope-upgrade");
721+
if (!hasLegacyPairedMetadata) {
722+
const allowedRoles = new Set(pairedRoles);
723+
if (allowedRoles.size === 0) {
724+
logUpgradeAudit("role-upgrade", pairedRoles, paired.scopes);
725+
const ok = await requirePairing("role-upgrade");
726+
if (!ok) {
727+
return;
728+
}
729+
} else if (!allowedRoles.has(role)) {
730+
logUpgradeAudit("role-upgrade", pairedRoles, paired.scopes);
731+
const ok = await requirePairing("role-upgrade");
739732
if (!ok) {
740733
return;
741734
}
742-
} else {
743-
const allowedScopes = new Set(pairedScopes);
744-
const missingScope = scopes.find((scope) => !allowedScopes.has(scope));
745-
if (missingScope) {
735+
}
736+
737+
const pairedScopes = Array.isArray(paired.scopes) ? paired.scopes : [];
738+
if (scopes.length > 0) {
739+
if (pairedScopes.length === 0) {
746740
logUpgradeAudit("scope-upgrade", pairedRoles, pairedScopes);
747741
const ok = await requirePairing("scope-upgrade");
748742
if (!ok) {
749743
return;
750744
}
745+
} else {
746+
const allowedScopes = new Set(pairedScopes);
747+
const missingScope = scopes.find((scope) => !allowedScopes.has(scope));
748+
if (missingScope) {
749+
logUpgradeAudit("scope-upgrade", pairedRoles, pairedScopes);
750+
const ok = await requirePairing("scope-upgrade");
751+
if (!ok) {
752+
return;
753+
}
754+
}
751755
}
752756
}
753757
}

0 commit comments

Comments
 (0)