Skip to content

fix: expand token regex to support newer cfut_ format tokens#129

Open
Toothless5143 wants to merge 3 commits intocaddy-dns:masterfrom
Toothless5143:master
Open

fix: expand token regex to support newer cfut_ format tokens#129
Toothless5143 wants to merge 3 commits intocaddy-dns:masterfrom
Toothless5143:master

Conversation

@Toothless5143
Copy link
Copy Markdown

Problem

Cloudflare recently changed their API token format. New tokens now use a
cfut_ prefix and are 53 characters long, exceeding the previous hard limit
of 50 characters in the regex validator:

var cloudflareTokenRegexp = regexp.MustCompile(`^[A-Za-z0-9_-]{35,50}$`)

This causes Caddy to reject perfectly valid tokens with:

API token 'cfut_xxx' appears invalid; ensure it's correctly entered
and not wrapped in braces nor quotes

Users are forced to either patch the binary themselves or paste the token
directly into the Caddyfile (which is a security risk).

Fix

Expanded the upper bound of cloudflareTokenRegexp from 50 to 70 characters
to accommodate current and future Cloudflare token formats while keeping the
character set validation intact.

Changes

  • cloudflare.go — updated regex upper bound from 50 to 70
  • cloudflare_test.go — added cfut_ prefixed token to TestValidToken

Testing

Verified working locally with a real cfut_ prefixed token of 53 characters
on Caddy v2.11.2.

Cloudflare's newer API tokens use the cfut_ prefix and are 53 characters long, exceeding the previous 50 character limit in the regex validator. Expanding the upper bound to 100 to accommodate current and future token formats.
Cloudflare's newer API tokens use the cfut_ prefix and are 53 characters long, exceeding the previous 50 character limit. Expanding upper bound to 70 to accommodate current and future token formats.
Cloudflare now issues tokens with cfut_ prefix that are 53 characters,
exceeding the previous 50 character limit. Expanding upper bound to 70.

Added cfut_ prefixed token to TestValidToken.
@lekoOwO
Copy link
Copy Markdown

lekoOwO commented Mar 22, 2026

mine starts with cfat_

@Toothless5143
Copy link
Copy Markdown
Author

mine starts with cfat_

Cloudflare seems to use different prefixes depending on the token type. The fix to expand the upper bound to 70 characters should cover both formats since the character set remains the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants