import type { CloudConfirmationPollData } from '@rocket.chat/core-typings'; import { serverFetch as fetch } from '@rocket.chat/server-fetch'; import { assertNotOfflineLicense } from './offlineLicense'; import { settings } from '../../settings'; import { SystemLogger } from '../logger/system'; export async function getConfirmationPoll(deviceCode: string): Promise { assertNotOfflineLicense(); try { const cloudUrl = settings.get('Cloud_Url'); const response = await fetch(`${cloudUrl}/api/v2/register/workspace/poll`, { params: { token: deviceCode }, // SECURITY: the URL is a default hardcoded value or an envvar/setting set by an admin. It's safe to disable this check. ignoreSsrfValidation: true, }); try { if (!response.ok) { throw new Error((await response.json()).error); } return await response.json(); } catch (err) { throw new Error(`Failed to retrieve registration confirmation poll data: ${response.statusText}`); } } catch (err: any) { SystemLogger.error({ msg: 'Failed to get confirmation poll from Rocket.Chat Cloud', url: '/api/v2/register/workspace/poll', err, }); throw err; } }