Skip to content

Update Cloudflare detectors for 2026+ prefixed credential formats#4830

Open
nkcmr wants to merge 1 commit intotrufflesecurity:mainfrom
nkcmr:nick/update-cf-credential-pats
Open

Update Cloudflare detectors for 2026+ prefixed credential formats#4830
nkcmr wants to merge 1 commit intotrufflesecurity:mainfrom
nkcmr:nick/update-cf-credential-pats

Conversation

@nkcmr
Copy link
Copy Markdown

@nkcmr nkcmr commented Mar 23, 2026

Context/Background

Cloudflare is rolling out new prefixed credential formats in 2026.
The new formats (cfk_, cfut_, cfat_) are self-identifying via
prefix and do not need keyword proximity matching. Per project
convention, new token formats are added via the Versioner interface
with a v1/v2 directory split.

Additionally, CA keys (Service Keys) are now deprecated.

Changes

  • cloudflareglobalapikey: split into v1/v2 with Versioner
    interface. v1 fixes legacy regex to [a-f0-9]{37,45} (lowercase
    hex only). v2 adds cfk_ prefixed format detection. v2 also
    handles the case where no email is found nearby (emits unverified
    result rather than silently dropping the token).
  • cloudflareapitoken: split into v1/v2 with Versioner
    interface. v2 adds cfut_/cfat_ prefixed format detection.
    cfat_ (account tokens) route verification through the
    account-scoped /accounts/:id/tokens/verify endpoint, extracting
    account IDs from surrounding data. cfut_ (user tokens) reuse the
    existing /user/tokens/verify endpoint via v1's exported helper.
  • cloudflarecakey: add deprecation notice with changelog link
    for Service Key authentication.
  • defaults.go: updated imports and registrations for all four
    versioned scanners.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

Note

Medium Risk
Medium risk because it changes secret-detection regexes and verification behavior (including new account-scoped verification requests), which can affect false positives/negatives and outbound verification traffic.

Overview
Updates Cloudflare detectors to support 2026+ self-identifying credential formats by splitting cloudflareapitoken and cloudflareglobalapikey into v1/v2 scanners implementing detectors.Versioner, and registering both versions in defaults.go.

Adds new v2 matchers for cfut_/cfat_ API tokens and cfk_ global API keys (no keyword proximity required); cfat_ verification now calls the account-scoped /accounts/:id/tokens/verify endpoint using account IDs found in surrounding data, and cfk_ detection now emits an unverified result even when no email is present.

Tightens the legacy cloudflareglobalapikey regex to lowercase-hex only and refactors verification logic in v1 detectors into exported helper functions; updates/introduces unit tests accordingly, and adds a deprecation note to cloudflarecakey comments.

Reviewed by Cursor Bugbot for commit 4329719. Bugbot is set up for automated code reviews on this repo. Configure here.

@nkcmr nkcmr requested a review from a team March 23, 2026 14:48
@nkcmr nkcmr requested a review from a team as a code owner March 23, 2026 14:48
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 23, 2026

CLA assistant check
All committers have signed the CLA.

@amanfcp
Copy link
Copy Markdown
Contributor

amanfcp commented Mar 30, 2026

Hey @nkcmr can you also attach some doc links which state the mentioned credential format changes?

@nkcmr nkcmr force-pushed the nick/update-cf-credential-pats branch from 95c4210 to e6d8c77 Compare April 8, 2026 11:35
@nkcmr
Copy link
Copy Markdown
Author

nkcmr commented Apr 8, 2026

@amanfcp Of course, here is the update to our developer docs that was just published: https://developers.cloudflare.com/fundamentals/api/get-started/token-formats/

Let me know if you meant that you want that in code comments or something. Wasn't sure.

@nkcmr nkcmr force-pushed the nick/update-cf-credential-pats branch from e6d8c77 to f32604a Compare April 8, 2026 12:59
@nkcmr nkcmr changed the title Update Cloudflare detector patterns for 2026+ credential formats Update Cloudflare detectors for 2026+ prefixed credential formats Apr 8, 2026
// 2026+ formats: cfut_ (user token) and cfat_ (account token), self-identifying.
keyV2Pat = regexp.MustCompile(`\b(cf[ua]t_[a-zA-Z0-9]{40}[a-f0-9]{8})\b`)
// Cloudflare account ID pattern for cfat_ token verification.
accountIDPat = regexp.MustCompile(`\b([a-f0-9]{32})\b`)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Broad account ID pattern may cause excessive verification requests

Medium Severity

The accountIDPat regex \b([a-f0-9]{32})\b matches any standalone 32-character hex string in the data chunk — including MD5 hashes, dashless UUIDs, and other hex values that aren't Cloudflare account IDs. When verify=true and a cfat_ token is found, a separate HTTP verification request is issued to Cloudflare's API for each candidate account ID. In data chunks rich in hex strings (e.g., files listing checksums), this could produce a large number of unnecessary outbound API calls, slowing down scanning and risking rate-limiting by Cloudflare.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit f32604a. Configure here.

 ## Context/Background

Cloudflare is rolling out new prefixed credential formats in 2026.
The new formats (`cfk_`, `cfut_`, `cfat_`) are self-identifying via
prefix and do not need keyword proximity matching. Per project
convention, new token formats are added via the `Versioner` interface
with a `v1`/`v2` directory split.

Additionally, CA keys (Service Keys) are now deprecated.

 ## Changes in this commit

- cloudflareglobalapikey: split into `v1`/`v2` with `Versioner`
  interface. v1 fixes legacy regex to `[a-f0-9]{37,45}` (lowercase
  hex). v2 adds `cfk_` prefixed format detection.
- cloudflareapitoken: split into `v1`/`v2` with `Versioner`
  interface. v2 adds `cfut_`/`cfat_` prefixed format detection.
  `cfat_` (account tokens) route verification through the
  account-scoped `/accounts/:id/tokens/verify` endpoint, extracting
  account IDs from surrounding data.
- cloudflarecakey: add deprecation notice with changelog link.
- defaults.go: updated imports and registrations for versioned
  scanners.
@nkcmr nkcmr force-pushed the nick/update-cf-credential-pats branch from f32604a to 4329719 Compare April 8, 2026 13:10
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 4329719. Configure here.

DetectorType: detector_typepb.DetectorType_CloudflareApiToken,
Raw: []byte(resMatch),
})
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Account ID pairing skipped when verify is false

Medium Severity

When verify is false, cfat_ tokens produce a single result without any RawV2 (account ID pairing), but when verify is true, the same token produces N results each with a distinct RawV2 containing the account ID. This is inconsistent with cloudflareglobalapikey/v2, which pairs keys with emails regardless of the verify flag. Because RawV2 is typically used for deduplication, this means cfat_ tokens scanned without verification lose their account-scoping context entirely.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4329719. Configure here.

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.

3 participants