Skip to content

Commit

Permalink
Always emit Turnstile domains, even when empty
Browse files Browse the repository at this point in the history
When Turnstile is configured with an empty list of domains, no validation
is performed by Cloudflare - the widget can be used anywhere. The website
owner is responsible for validating the challenge was solved on the "right"
website.
This feature is gated behind an entitlement, and `domains = []` is used to
enable this. This is *not* a default value for domains, it must be picked
explicitly.

Fixes #655.
  • Loading branch information
punkeel committed Dec 21, 2023
1 parent c2fcbeb commit d9f0db1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/app/cf-terraforming/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,12 @@ func generateResources() func(cmd *cobra.Command, args []string) {

for i := 0; i < resourceCount; i++ {
jsonStructData[i].(map[string]interface{})["id"] = jsonStructData[i].(map[string]interface{})["sitekey"]

// We always want to emit a list of domains, even if it is empty.
// The empty list is used to enable the "Allow on any hostname" feature, it is *not* a default value.
if jsonStructData[i].(map[string]interface{})["domains"] == nil {
jsonStructData[i].(map[string]interface{})["domains"] = []string{}
}
}
case "cloudflare_url_normalization_settings":
jsonPayload, err := api.URLNormalizationSettings(context.Background(), &cloudflare.ResourceContainer{Identifier: zoneID, Level: cloudflare.ZoneRouteLevel})
Expand Down
2 changes: 2 additions & 0 deletions internal/app/cf-terraforming/cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ func writeAttrLine(key string, value interface{}, parentName string, body *hclwr
vals = append(vals, cty.StringVal(item))
}
body.SetAttributeValue(key, cty.ListVal(vals))
} else {
body.SetAttributeValue(key, cty.ListValEmpty(cty.String))
}
case string:
if parentName == "query" && key == "value" && value == "" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
resource "cloudflare_turnstile_widget" "terraform_managed_resource" {
account_id = "f037e56e89293a057740de681ac9abbe"
domains = []
mode = "non-interactive"
name = "example sitekey with no domains"
region = "world"
Expand Down

0 comments on commit d9f0db1

Please sign in to comment.