Configure exposed credentials checks using Terraform
Last updated May 5, 2026 Deprecation notice
Exposed credentials check has been deprecated.
Switch from exposed credentials check to leaked credentials detection for improved security. To upgrade your current configuration, refer to the upgrade guide.
The following Terraform configuration example addresses a common use case of exposed credentials checks.
For more information, refer to the Terraform Cloudflare provider documentation ↗︎.
If you are using the Cloudflare API, refer to Configure exposed credentials checks via API.
Add a custom rule to check for exposed credentials
The following configuration creates a custom ruleset with a single rule that checks for exposed credentials.
You can only add exposed credential checks to rules in a custom ruleset (that is, a ruleset with kind = "custom").
Note
Terraform code snippets below refer to the v4 SDK only.
resource "cloudflare_ruleset" "account_firewall_custom_ruleset_exposed_creds" {
account_id = "<ACCOUNT_ID>"
name = "Custom ruleset checking for exposed credentials"
description = ""
kind = "custom"
phase = "http_request_firewall_custom"
rules {
ref = "check_for_exposed_creds_add_header"
description = "Add header when there is a rule match and exposed credentials are detected"
expression = "http.request.method == \"POST\" && http.request.uri == \"/login.php\""
action = "rewrite"
action_parameters {
headers {
name = "Exposed-Credential-Check"
operation = "set"
value = "1"
}
}
exposed_credential_check {
username_expression = "url_decode(http.request.body.form[\"username\"][0])"
password_expression = "url_decode(http.request.body.form[\"password\"][0])"
}
}
}
To create another rule, add a new rules object to the same cloudflare_ruleset resource.
The following configuration deploys the custom ruleset. It defines a dependency on the account_firewall_custom_ruleset_exposed_creds resource and obtains the ID of the created custom ruleset:
Note
Terraform code snippets below refer to the v4 SDK only.
resource "cloudflare_ruleset" "account_firewall_custom_entrypoint" {
account_id = "<ACCOUNT_ID>"
name = "Account-level entry point ruleset for the http_request_firewall_custom phase deploying a custom ruleset checking for exposed credentials"
description = ""
kind = "root"
phase = "http_request_firewall_custom"
depends_on = [cloudflare_ruleset.account_firewall_custom_ruleset_exposed_creds]
rules {
ref = "deploy_custom_ruleset_example_com"
description = "Deploy custom ruleset for example.com"
expression = "(cf.zone.name eq \"example.com\")"
action = "execute"
action_parameters {
id = cloudflare_ruleset.account_firewall_custom_ruleset_exposed_creds.id
}
}
}
More resources
For additional Terraform configuration examples, refer to WAF custom rules configuration using Terraform.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/waf/managed-rules/check-for-exposed-credentials/configure-terraform/#page","headline":"Configure exposed credentials checks using Terraform","description":"Configure exposed credentials checks using Terraform.","url":"https://developers.cloudflare.com/waf/managed-rules/check-for-exposed-credentials/configure-terraform/","inLanguage":"en","image":"https://developers.cloudflare.com/waf/managed-rules/check-for-exposed-credentials/configure-terraform/og.png?v=76fe4b7e035e9d74","dateModified":"2026-05-05","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["Terraform"]}
description: How exposed credentials checks detect compromised login attempts. title: How exposed credentials checks work image: https://developers.cloudflare.com/waf/managed-rules/check-for-exposed-credentials/how-checks-work/og.png?v=67b8f7a36c50cbd6
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/waf/llms.txt
Use this file to discover all available pages before exploring further.
Docs