{"record":{"id":"0a1f361f330ab810","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-subscription-0a1f36","errorCode":"error-invalid-subscription","errorMessage":"Invalid subscription","messagePattern":"Invalid subscription","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/lib/autotranslate/functions/saveSettings.ts","lineNumber":33,"sourceCode":"\tif (!(await hasPermissionAsync(userId, 'auto-translate'))) {\n\t\tthrow new Meteor.Error('error-action-not-allowed', 'Auto-Translate is not allowed', {\n\t\t\tmethod: 'autoTranslate.saveSettings',\n\t\t});\n\t}\n\n\tcheck(rid, String);\n\tcheck(field, String);\n\tcheck(value, String);\n\n\tif (['autoTranslate', 'autoTranslateLanguage'].indexOf(field) === -1) {\n\t\tthrow new Meteor.Error('error-invalid-settings', 'Invalid settings field', {\n\t\t\tmethod: 'saveAutoTranslateSettings',\n\t\t});\n\t}\n\n\tconst subscription = await Subscriptions.findOneByRoomIdAndUserId(rid, userId);\n\tif (!subscription) {\n\t\tthrow new Meteor.Error('error-invalid-subscription', 'Invalid subscription', {\n\t\t\tmethod: 'saveAutoTranslateSettings',\n\t\t});\n\t}\n\n\tlet shouldNotifySubscriptionChanged = false;\n\n\tswitch (field) {\n\t\tcase 'autoTranslate':\n\t\t\tconst room = await Rooms.findE2ERoomById(rid, { projection: { _id: 1 } });\n\t\t\tif (room && value === '1') {\n\t\t\t\tthrow new Meteor.Error('error-e2e-enabled', 'Enabling auto-translation in E2E encrypted rooms is not allowed', {\n\t\t\t\t\tmethod: 'saveAutoTranslateSettings',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst updateAutoTranslateResponse = await Subscriptions.updateAutoTranslateById(subscription._id, value === '1');\n\t\t\tif (updateAutoTranslateResponse.modifiedCount) {\n\t\t\t\tshouldNotifySubscriptionChanged = true;","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0/apps/meteor/server/lib/autotranslate/functions/saveSettings.ts#L15-L51","documentation":"saveAutoTranslateSettings requires an existing subscription document joining the calling user to the room (Subscriptions.findOneByRoomIdAndUserId). If the user never joined, left, or was removed from the room, the lookup returns nothing and error-invalid-subscription is thrown before any write. Note a banned user still has a subscription (status 'BANNED'), so this is not the banned-state error.","triggerScenarios":"Saving translate settings for a rid the user is not a member of (pasted rid, room left in another session, removed from a private channel while the client still renders its settings); racing with leaveRoom/removeUser.","commonSituations":"Stale room lists in long-lived sessions; automation acting on arbitrary room ids; subscription documents removed by moderation tooling.","solutions":["Verify membership first (the user's subscriptions / rooms list) and join the room if allowed","Refresh the client's subscription cache after join/leave actions","Only expose translate settings for rooms present in the user's subscriptions"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const subs = await GET '/api/v1/subscriptions.get';\nif (!subs.update.some((s) => s.rid === rid)) {\n  // user is not in this room - join first or skip saving translate settings\n}","typeGuard":null,"tryCatchPattern":"try {\n  await POST '/api/v1/autotranslate.saveSettings' { roomId: rid, field, value };\n} catch (e) {\n  if (e.error === 'error-invalid-subscription') {\n    // rid is not in the user's subscriptions - refresh and/or join the room\n  } else {\n    throw e;\n  }\n}","preventionTips":["Only render translate settings for rooms present in the user's subscriptions","Refresh the subscription cache after join/leave events","Treat pasted room ids as untrusted input in automation"],"tags":["rocket-chat","autotranslate","subscriptions","rooms"],"backgroundTag":"user-not-in-room","analyzedSha":"b2c16d5842cbe6b69b59bdf6fc5e5f1afcd1f0b0","analyzedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}