Skip to main content
MediumSupply chainOWASP A05:2021CWE-540

How to fix: Terraform provider lockfile exposed

The response is a .terraform.lock.hcl file: registry.terraform.io provider blocks with their recorded hashes.

Why it matters

The provider list is an inventory of the infrastructure itself. Seeing aws, cloudflare, vault, datadog and a database provider together tells an attacker which cloud the estate runs on, which secret store it uses, and which SaaS platforms hold an API token for this organisation, before any other reconnaissance. The pinned provider versions also indicate how recently the infrastructure code was touched.

Rated above the language lockfiles because of what it implies rather than what it contains: this file only exists inside a Terraform working directory, so its presence under a web root means infrastructure code was deployed alongside the application. The files beside it are the real exposure. terraform.tfvars and any .tfstate in the same directory routinely contain credentials and full resource inventories.

How to fix it

  1. 1Remove the Terraform working directory from the web-served path immediately.
  2. 2Check the same directory for terraform.tfvars, *.auto.tfvars and *.tfstate, and treat every value in them as compromised.
  3. 3Rotate any credential that could have been in those files.
  4. 4Move state to a remote backend with access control so it is never a file on an application host.

Code examples

Check what else is reachable in that directory

bash
for f in terraform.tfstate terraform.tfvars terraform.tfstate.backup .terraform.lock.hcl; do
  printf '%s ' "$f"
  curl -s -o /dev/null -w '%{http_code}\n' "https://example.com/$f"
done

Use a remote backend instead of local state

HCL
terraform {
  backend "s3" {
    bucket         = "example-tf-state"
    key            = "prod/terraform.tfstate"
    region         = "us-east-1"
    encrypt        = true
    dynamodb_table = "tf-state-lock"
  }
}

References

Detected automatically by VulnRadar. The check id is supply-chain-terraform-lock-exposed, stable across every scan so you can filter or diff on it.

See every supply chain check

Questions

How severe is Terraform provider lockfile exposed?
VulnRadar rates this medium severity in the supply chain category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id supply-chain-terraform-lock-exposed, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Terraform provider lockfile exposed map to?
It maps to CWE-540. In the OWASP Top 10 it falls under A05:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for terraform provider lockfile exposed

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: Terraform provider lockfile exposed | VulnRadar