Skip to content

Redact API token in Provision error message#132

Open
leonbeckert wants to merge 1 commit intocaddy-dns:masterfrom
arana-ai:redact-token-in-error
Open

Redact API token in Provision error message#132
leonbeckert wants to merge 1 commit intocaddy-dns:masterfrom
arana-ai:redact-token-in-error

Conversation

@leonbeckert
Copy link
Copy Markdown

Summary

The fmt.Errorf in Provision() currently includes the raw API token when validation fails:

API token 'cfat_3Sak5Ms...<full bearer>...' appears invalid; ...

This leaks the bearer into container logs (via docker logs), which is a credential exposure risk in containerized deployments.

This PR adds a redactToken() helper that shows only the first 8 and last 4 characters, masking the middle with asterisks:

API token 'cfat_3Sa*************************71a9' appears invalid; ...

Changes

  • cloudflare.go: Add redactToken() helper, use it in the Provision error path
  • cloudflare_test.go: Add TestProvisionErrorRedactsToken (asserts full token does NOT appear in error) and TestRedactToken (6 table-driven cases covering empty, short, boundary, legacy, and cfat_ tokens)

Notes

  • No behavior change for valid tokens — they pass validation and the error never fires
  • Only affects the error message for invalid tokens
  • All existing tests continue to pass

The fmt.Errorf in Provision() currently includes the raw API token
when validation fails. This leaks the bearer into container logs
(via `docker logs`), which is a credential exposure risk.

Add a redactToken() helper that shows only the first 8 and last 4
characters, masking the middle with asterisks. Add tests for both
the redaction function itself and the Provision error path.
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.

1 participant