@yu_robotics/remote-cli-router 1.6.221 → 1.6.223

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -83,6 +83,7 @@ class RouterServer {
83
83
  outputTransfers;
84
84
  outputsAvailable = false;
85
85
  outputSessions = new Map();
86
+ deviceEnrollments = new Set();
86
87
  constructor(config, store) {
87
88
  this.config = config;
88
89
  this.store = store;
@@ -162,6 +163,15 @@ class RouterServer {
162
163
  this.feishuLongConnHandler.onOutputFileAction = (openId, cardId, payload) => this.outputTransfers.click(openId, cardId, payload);
163
164
  this.feishuLongConnHandler.onFileMessage = input => this.fileTransfers.receive(input);
164
165
  this.feishuLongConnHandler.onResolveFile = (openId, sourceId) => this.fileTransfers.resolve(openId, sourceId);
166
+ this.feishuLongConnHandler.onDeviceEnrollmentBoundary = (deviceId, phase) => {
167
+ if (phase === 'end') {
168
+ this.deviceEnrollments.delete(deviceId);
169
+ return;
170
+ }
171
+ // Exclude credentialless registrations before the pending marker reaches disk.
172
+ this.deviceEnrollments.add(deviceId);
173
+ this.connectionHub.disconnectDevice(deviceId);
174
+ };
165
175
  this.feishuLongConnHandler.onApproveDeviceKey = async (openId, deviceId, publicKey) => {
166
176
  if ((await this.bindingManager.getDeviceBinding(deviceId))?.openId !== openId)
167
177
  throw new Error('Device ownership changed.');
@@ -757,7 +767,19 @@ class RouterServer {
757
767
  const requestedId = message.data.deviceId;
758
768
  let authenticatedOwner;
759
769
  try {
770
+ if (this.deviceEnrollments.has(requestedId)) {
771
+ ws.send(JSON.stringify({ type: 'error', data: { code: 'DEVICE_AUTH_REQUIRED', message: 'Device key enrollment is in progress. Retry after approval.' } }));
772
+ ws.close();
773
+ break;
774
+ }
760
775
  const enrolled = await this.deviceAuth.get(requestedId);
776
+ const binding = await this.bindingManager.getDeviceBinding(requestedId);
777
+ const requiresAuthentication = binding?.devices?.some(device => device.deviceId === requestedId && device.requiresDeviceAuth);
778
+ if (requiresAuthentication && !enrolled) {
779
+ ws.send(JSON.stringify({ type: 'error', data: { code: 'DEVICE_AUTH_REQUIRED', message: 'Device key enrollment is incomplete. Approve the device key and retry.' } }));
780
+ ws.close();
781
+ break;
782
+ }
761
783
  if (enrolled) {
762
784
  if (!message.data.deviceSignature && !enrolled.revoked) {
763
785
  if (this.stopping || socketClosed || !admission.active() || ws.readyState !== ws_1.WebSocket.OPEN)
@@ -780,6 +802,16 @@ class RouterServer {
780
802
  }
781
803
  if (this.stopping || socketClosed || !admission.active() || ws.readyState !== ws_1.WebSocket.OPEN)
782
804
  break;
805
+ if (!authenticatedOwner) {
806
+ const current = await this.bindingManager.getDeviceBinding(requestedId);
807
+ const pending = current?.devices?.some(device => device.deviceId === requestedId && device.requiresDeviceAuth);
808
+ const enrolledAfterLookup = await this.deviceAuth.get(requestedId);
809
+ if (this.deviceEnrollments.has(requestedId) || pending || enrolledAfterLookup) {
810
+ ws.send(JSON.stringify({ type: 'error', data: { code: 'DEVICE_AUTH_REQUIRED', message: 'Device authentication is required. Reconnect and retry.' } }));
811
+ ws.close();
812
+ break;
813
+ }
814
+ }
783
815
  }
784
816
  catch {
785
817
  ws.send(JSON.stringify({ type: 'error', data: { code: 'DEVICE_AUTH_REQUIRED', message: 'Device authentication is unavailable. Ask the Router administrator to check the authentication store.' } }));
@@ -789,6 +821,9 @@ class RouterServer {
789
821
  finally {
790
822
  authenticationPending = false;
791
823
  }
824
+ // Authentication lookups may outlive the socket or its admission lease.
825
+ if (this.stopping || socketClosed || !admission.active() || ws.readyState !== ws_1.WebSocket.OPEN)
826
+ break;
792
827
  if (challengeTimer)
793
828
  clearTimeout(challengeTimer);
794
829
  // Version check: missing protocolVersion defaults to 1 (current baseline)