From 3eb96c9647ddb1f30b53c5bfce209c6db1612e5d Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Tue, 14 Feb 2023 12:39:09 +0300 Subject: [PATCH] fix(manager/terraform): Guard against empty `module` and `provider` fields (#20394) --- .../manager/terraform/extractors/others/modules.ts | 6 ++++++ .../manager/terraform/extractors/others/providers.ts | 10 ++++++++++ .../terraform/extractors/resources/helm-release.ts | 11 +++++++++++ 3 files changed, 27 insertions(+) diff --git a/lib/modules/manager/terraform/extractors/others/modules.ts b/lib/modules/manager/terraform/extractors/others/modules.ts index 114bc2c3f7..82835cd674 100644 --- a/lib/modules/manager/terraform/extractors/others/modules.ts +++ b/lib/modules/manager/terraform/extractors/others/modules.ts @@ -34,6 +34,12 @@ export class ModuleExtractor extends DependencyExtractor { return []; } + // istanbul ignore if + if (!is.plainObject(modules)) { + logger.debug({ modules }, 'Terraform: unexpected `modules` value'); + return []; + } + const dependencies = []; for (const moduleElement of Object.values(modules).flat()) { const dep = { diff --git a/lib/modules/manager/terraform/extractors/others/providers.ts b/lib/modules/manager/terraform/extractors/others/providers.ts index 53b17c2443..1133296617 100644 --- a/lib/modules/manager/terraform/extractors/others/providers.ts +++ b/lib/modules/manager/terraform/extractors/others/providers.ts @@ -1,4 +1,5 @@ import is from '@sindresorhus/is'; +import { logger } from '../../../../../logger'; import type { PackageDependency } from '../../../types'; import { TerraformProviderExtractor } from '../../base'; import type { TerraformDefinitionFile } from '../../hcl/types'; @@ -18,6 +19,15 @@ export class ProvidersExtractor extends TerraformProviderExtractor { return []; } + // istanbul ignore if + if (!is.plainObject(providerTypes)) { + logger.debug( + { providerTypes }, + 'Terraform: unexpected `providerTypes` value' + ); + return []; + } + const dependencies = []; for (const providerTypeName of Object.keys(providerTypes)) { for (const providerTypeElement of providerTypes[providerTypeName]) { diff --git a/lib/modules/manager/terraform/extractors/resources/helm-release.ts b/lib/modules/manager/terraform/extractors/resources/helm-release.ts index 753e912d32..87d6375a1b 100644 --- a/lib/modules/manager/terraform/extractors/resources/helm-release.ts +++ b/lib/modules/manager/terraform/extractors/resources/helm-release.ts @@ -1,4 +1,5 @@ import is from '@sindresorhus/is'; +import { logger } from '../../../../../logger'; import { DockerDatasource } from '../../../../datasource/docker'; import { HelmDatasource } from '../../../../datasource/helm'; import { isOCIRegistry } from '../../../helmv3/utils'; @@ -19,6 +20,16 @@ export class HelmReleaseExtractor extends DependencyExtractor { if (is.nullOrUndefined(helmReleases)) { return []; } + + // istanbul ignore if + if (!is.plainObject(helmReleases)) { + logger.debug( + { helmReleases }, + 'Terraform: unexpected `helmReleases` value' + ); + return []; + } + for (const helmRelease of Object.values(helmReleases).flat()) { const dep: PackageDependency = { currentValue: helmRelease.version,