From dc02da4b942d6e23a5ca1061d76dcf58b4bd2c21 Mon Sep 17 00:00:00 2001 From: maksadbek Date: Tue, 3 Dec 2024 12:43:22 +0100 Subject: [PATCH] chore(repeater): validate proxy-domains and proxy-domains-bypass flags (#624) Co-authored-by: Or Rubin --- src/Commands/RunRepeater.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/Commands/RunRepeater.ts b/src/Commands/RunRepeater.ts index c929eddb..9e41e041 100644 --- a/src/Commands/RunRepeater.ts +++ b/src/Commands/RunRepeater.ts @@ -138,6 +138,10 @@ export class RunRepeater implements CommandModule { describe: 'Space-separated list of domains that should be routed through the proxy. This option is only applicable when using the --proxy option', coerce(arg: string[]): string[] { + if (arg[0] === undefined) { + return undefined; + } + // if values are passed from env variable, they are passed as a single string if (arg.length === 1) { if (arg[0].includes(' ')) { @@ -161,6 +165,10 @@ export class RunRepeater implements CommandModule { coerce(arg: string[]): string[] { // if values are passed from env variable, they are passed as a single string if (arg.length === 1) { + if (arg[0] === undefined) { + return undefined; + } + if (arg[0].includes(' ')) { return arg[0].trim().split(' '); } @@ -193,6 +201,26 @@ export class RunRepeater implements CommandModule { ); } + const proxyDomains = (args.proxyDomains as string[]) ?? []; + for (const domain of proxyDomains) { + if (domain.includes(',')) { + throw new Error( + `Option --proxy-domains has a wrong value.` + + `Please ensure that --proxy-domains option has space separated list of domain values` + ); + } + } + + const proxyDomainsBypass = (args.proxyDomainsBypass as string[]) ?? []; + for (const domain of proxyDomainsBypass) { + if (domain.includes(',')) { + throw new Error( + `Option --proxy-domain-bypass has wrong value.` + + `Please ensure that --proxy-domain-bypass option has space separated list of domain values` + ); + } + } + return true; }) .middleware((args: Arguments) => {