fix: expand token regex to support cfut_ prefix tokens (53+ chars)#128
Open
EgorYolkin wants to merge 1 commit intocaddy-dns:masterfrom
Open
fix: expand token regex to support cfut_ prefix tokens (53+ chars)#128EgorYolkin wants to merge 1 commit intocaddy-dns:masterfrom
EgorYolkin wants to merge 1 commit intocaddy-dns:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Description
The token is validated using the regex pattern
^[A-Za-z0-9_-]{35,50}$in thevalidCloudflareToken()function (defined incloudflare.go).Cloudflare has started issuing API tokens in a new format with the prefix
cfut_(Cloudflare User Token). These tokens are longer than the previous format — my token is 53 characters long, which exceeds the current regex maximum of 50.The token is fully valid and works correctly with the Cloudflare API (verified via
curland other services that use the same token for DNS record management), but Caddy rejects it at the provisioning stage before making any API request.Steps to reproduce
cfut_format (e.g. 53 characters long).caddy-dns/cloudflaremodule:Actual behavior
Caddy fails to start with the following error:
The error is produced by the
validCloudflareToken()function duringProvision(), before any actual API call to Cloudflare is made. The token never reaches the Cloudflare API for real validation.Expected behavior
Caddy should accept the token and allow the Cloudflare API itself to determine whether it is valid or not. Alternatively, the regex should be updated to accommodate the new token format.
Root cause
The regex pattern
^[A-Za-z0-9_-]{35,50}$defined incloudflare.goenforces Cloudflare's token format requirements.This regex was written when Cloudflare tokens were 40 characters of
[A-Za-z0-9_-]. The newcfut_-prefixed tokens are 53 characters, which exceeds the{35,50}upper bound.Suggested fix
Option A (minimal)
Increase the upper bound of the regex to accommodate new token formats:
Option B (forward-compatible)
Remove the upper length bound entirely, keeping only a sane minimum and character class check:
Option C (most robust)
Remove client-side regex validation entirely and let the Cloudflare API itself validate the token.
This function exists only as a sanity check — if the token is malformed, Cloudflare will return HTTP 400/403 with a clear error message anyway. Client-side validation creates a maintenance burden because Cloudflare can change token formats at any time.
Environment
caddy-dns/cloudflare: latest (master)xcaddywithcaddy:builderimagecfut_prefix, 53 characters totalcurl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify"returns
"status": "active"Workaround
Currently there is no clean workaround other than using a legacy-format token (if still possible to generate) or forking the module to patch the regex.