From a0714b9cc83cdcd3cb94e9f24c273ca9ec7f98f5 Mon Sep 17 00:00:00 2001 From: yflory Date: Thu, 12 Jan 2023 15:54:16 +0100 Subject: [PATCH] Prevent type error with the new admin script --- lib/commands/admin-rpc.js | 4 +++- lib/env.js | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/commands/admin-rpc.js b/lib/commands/admin-rpc.js index a05b177a2..7200ce49b 100644 --- a/lib/commands/admin-rpc.js +++ b/lib/commands/admin-rpc.js @@ -779,12 +779,14 @@ var commands = { // addFirstAdmin is an anon_rpc command Admin.addFirstAdmin = function (Env, data, cb) { + if (!Env.installToken) { return void cb('EINVAL'); } var token = data.token; + if (!token || !data.edPublic) { return void cb('MISSING_ARGS'); } + if (token.length !== 64 || data.edPublic.length !== 44) { return void cb('INVALID_ARGS'); } if (token !== Env.installToken) { return void cb('FORBIDDEN'); } if (Array.isArray(Env.admins) && Env.admins.length) { return void cb('EEXISTS'); } var key = data.edPublic; - if (token.length !== 64 || data.edPublic.length !== 44) { return void cb('INVALID_ARGS'); } adminDecree(Env, null, function (err) { if (err) { return void cb(err); } diff --git a/lib/env.js b/lib/env.js index 8824c347f..f61d48f9c 100644 --- a/lib/env.js +++ b/lib/env.js @@ -167,6 +167,7 @@ module.exports.create = function (config) { limits: {}, admins: [], + installToken: undefined, WARN: function (e, output) { // TODO deprecate this if (!Env.Log) { return; } if (e && output) {