From 43630a12f65fb62ab8e92be224441af157d64edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kol=C3=A1rik?= Date: Thu, 8 Aug 2024 21:01:04 +0200 Subject: [PATCH] fix: relax domain validation rules to match the API (#248) --- src/command/dns-command.ts | 8 ++++---- src/command/http-command.ts | 12 ++++++------ src/command/mtr-command.ts | 8 ++++---- src/command/ping-command.ts | 8 ++++---- src/command/traceroute-command.ts | 8 ++++---- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/command/dns-command.ts b/src/command/dns-command.ts index 2367316..e3914da 100644 --- a/src/command/dns-command.ts +++ b/src/command/dns-command.ts @@ -59,12 +59,12 @@ const dnsOptionsSchema = Joi.object({ type: Joi.string().valid(...allowedTypes).optional().default('A'), }), ipVersion: Joi.when(Joi.ref('resolver'), { - is: Joi.string().domain(), - then: Joi.valid(...allowedIpVersions).default(4), + is: Joi.string().ip({ version: [ 'ipv4' ], cidr: 'forbidden' }).required(), + then: Joi.valid(4).default(4), otherwise: Joi.when(Joi.ref('resolver'), { - is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }), + is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }).required(), then: Joi.valid(6).default(6), - otherwise: Joi.valid(4).default(4), + otherwise: Joi.valid(...allowedIpVersions).default(4), }), }), }); diff --git a/src/command/http-command.ts b/src/command/http-command.ts index aa4a450..a5e2b2f 100644 --- a/src/command/http-command.ts +++ b/src/command/http-command.ts @@ -113,24 +113,24 @@ const allowedIpVersions = [ 4, 6 ]; export const httpOptionsSchema = Joi.object({ type: Joi.string().valid('http').insensitive().required(), inProgressUpdates: Joi.boolean().required(), - target: Joi.alternatives().try(Joi.string().ip(), Joi.string().domain()).required(), + target: Joi.string(), resolver: Joi.string().ip(), protocol: Joi.string().valid(...allowedHttpProtocols).insensitive().default('HTTPS'), port: Joi.number(), request: Joi.object({ method: Joi.string().valid(...allowedHttpMethods).insensitive().default('HEAD'), - host: Joi.string().domain(), + host: Joi.string(), path: Joi.string().optional().default('/'), query: Joi.string().allow('').optional().default(''), headers: Joi.object().default({}), }).required(), ipVersion: Joi.when(Joi.ref('target'), { - is: Joi.string().domain(), - then: Joi.valid(...allowedIpVersions).default(4), + is: Joi.string().ip({ version: [ 'ipv4' ], cidr: 'forbidden' }).required(), + then: Joi.valid(4).default(4), otherwise: Joi.when(Joi.ref('target'), { - is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }), + is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }).required(), then: Joi.valid(6).default(6), - otherwise: Joi.valid(4).default(4), + otherwise: Joi.valid(...allowedIpVersions).default(4), }), }), }); diff --git a/src/command/mtr-command.ts b/src/command/mtr-command.ts index c546e83..914f429 100644 --- a/src/command/mtr-command.ts +++ b/src/command/mtr-command.ts @@ -41,12 +41,12 @@ const mtrOptionsSchema = Joi.object({ packets: Joi.number().min(1).max(16).default(3), port: Joi.number(), ipVersion: Joi.when(Joi.ref('target'), { - is: Joi.string().domain(), - then: Joi.valid(...allowedIpVersions).default(4), + is: Joi.string().ip({ version: [ 'ipv4' ], cidr: 'forbidden' }).required(), + then: Joi.valid(4).default(4), otherwise: Joi.when(Joi.ref('target'), { - is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }), + is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }).required(), then: Joi.valid(6).default(6), - otherwise: Joi.valid(4).default(4), + otherwise: Joi.valid(...allowedIpVersions).default(4), }), }), }); diff --git a/src/command/ping-command.ts b/src/command/ping-command.ts index 8d43841..7b49a6c 100644 --- a/src/command/ping-command.ts +++ b/src/command/ping-command.ts @@ -25,12 +25,12 @@ const pingOptionsSchema = Joi.object({ target: Joi.string(), packets: Joi.number().min(1).max(16).default(3), ipVersion: Joi.when(Joi.ref('target'), { - is: Joi.string().domain(), - then: Joi.valid(...allowedIpVersions).default(4), + is: Joi.string().ip({ version: [ 'ipv4' ], cidr: 'forbidden' }).required(), + then: Joi.valid(4).default(4), otherwise: Joi.when(Joi.ref('target'), { - is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }), + is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }).required(), then: Joi.valid(6).default(6), - otherwise: Joi.valid(4).default(4), + otherwise: Joi.valid(...allowedIpVersions).default(4), }), }), }); diff --git a/src/command/traceroute-command.ts b/src/command/traceroute-command.ts index 7089ca0..c92447a 100644 --- a/src/command/traceroute-command.ts +++ b/src/command/traceroute-command.ts @@ -58,12 +58,12 @@ const traceOptionsSchema = Joi.object({ protocol: Joi.string(), port: Joi.number(), ipVersion: Joi.when(Joi.ref('target'), { - is: Joi.string().domain(), - then: Joi.valid(...allowedIpVersions).default(4), + is: Joi.string().ip({ version: [ 'ipv4' ], cidr: 'forbidden' }).required(), + then: Joi.valid(4).default(4), otherwise: Joi.when(Joi.ref('target'), { - is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }), + is: Joi.string().ip({ version: [ 'ipv6' ], cidr: 'forbidden' }).required(), then: Joi.valid(6).default(6), - otherwise: Joi.valid(4).default(4), + otherwise: Joi.valid(...allowedIpVersions).default(4), }), }), });