From 345870dcc9332fe38bcf47d017af886ba01fdbbe Mon Sep 17 00:00:00 2001 From: Sucukdeluxe <259325684+Sucukdeluxe@users.noreply.github.com> Date: Thu, 15 Oct 2026 04:20:01 +0200 Subject: [PATCH] Verify Clouddrop log accounts through the bearer-authenticated token endpoint --- lib/clouddrop-log-api.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/clouddrop-log-api.js b/lib/clouddrop-log-api.js index ab9c5c7..9ecb7e9 100644 --- a/lib/clouddrop-log-api.js +++ b/lib/clouddrop-log-api.js @@ -51,8 +51,16 @@ class ClouddropLogApi { async identify(signal) { if (!/^cd_[a-f0-9]{32}$/.test(this.apiKey)) throw new CloudLogError('INVALID_KEY'); - const user = await this.call('/me', { signal }); - if (typeof user.id !== 'string' || !user.id) throw new CloudLogError('INVALID_RESPONSE'); + const authorization = await this.call('/upload-token', { signal }); + const token = authorization?.token; + if (typeof token !== 'string' || token.length > 2048 || !/^[A-Za-z0-9_-]+$/.test(token)) { + throw new CloudLogError('INVALID_RESPONSE'); + } + const [accountId, expires, signature, extra] = Buffer.from(token, 'base64url').toString('utf8').split(':'); + if (!/^[A-Za-z0-9_-]{1,100}$/.test(accountId || '') || !/^\d{13}$/.test(expires || '') + || Number(expires) <= Date.now() || !/^[a-f0-9]{64}$/.test(signature || '') || extra !== undefined) { + throw new CloudLogError('INVALID_RESPONSE'); + } const response = await this.request('https://api64.ipify.org?format=json', { signal, maxRedirections: 0, headersTimeout: 15000, bodyTimeout: 15000, headers: { Accept: 'application/json' } @@ -61,7 +69,7 @@ class ClouddropLogApi { let ip; try { ip = JSON.parse(text).ip; } catch {} if (response.statusCode !== 200 || !isIP(ip || '')) throw new CloudLogError('IP_UNAVAILABLE'); - return { accountId: user.id, ip, folderName: ip.replaceAll(':', '_') }; + return { accountId, ip, folderName: ip.replaceAll(':', '_') }; } async ensureFolder(name, signal) {