Skip to content

fix(config): redact sensitive fields in /api/config response#865

Merged
appleboy merged 2 commits intomasterfrom
fix/redact-config-endpoint-secrets
Mar 10, 2026
Merged

fix(config): redact sensitive fields in /api/config response#865
appleboy merged 2 commits intomasterfrom
fix/redact-config-endpoint-secrets

Conversation

@appleboy
Copy link
Copy Markdown
Owner

Summary

  • Add SanitizedCopy() method on ConfYaml to return a copy with all sensitive fields (credentials, passwords, TLS keys, proxy URLs) replaced with [REDACTED]
  • Update configHandler to use cfg.SanitizedCopy() instead of exposing the raw config struct
  • Fix incorrect HTTP status from 201 Created to 200 OK for the GET endpoint

Redacted Fields

Struct Fields Reason
Core CertBase64, KeyBase64 TLS private key/cert
Core HTTPProxy May contain auth credentials
Android KeyPath, Credential FCM credentials
Huawei AppSecret HMS secret
iOS KeyPath, KeyBase64, Password, KeyID, TeamID APNS credentials
Queue.Redis Username, Password Redis auth
Stat.Redis Username, Password Redis auth

Test plan

  • TestSanitizedCopy — verifies all sensitive fields are redacted, non-sensitive fields preserved, original config unmodified
  • TestSanitizedCopyEmptyFields — verifies empty strings stay empty (not [REDACTED])
  • TestAPIConfigHandler — verifies response uses HTTP 200, contains [REDACTED], and does not contain raw secret values
  • Linter passes with 0 issues

🤖 Generated with Claude Code

- Add SanitizedCopy method to replace credentials and secrets with REDACTED
- Update configHandler to return sanitized config copy instead of raw config
- Fix HTTP status from 201 Created to 200 OK for GET endpoint
- Add tests for SanitizedCopy with populated and empty sensitive fields
- Add assertions verifying secrets are not exposed in handler response

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 10, 2026 13:57
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents leaking secrets via the unauthenticated GET /api/config endpoint by returning a redacted copy of the loaded configuration and correcting the endpoint’s HTTP status code.

Changes:

  • Add (*config.ConfYaml).SanitizedCopy() to redact sensitive config fields.
  • Update configHandler to return cfg.SanitizedCopy() and use HTTP 200 OK (instead of 201 Created).
  • Add/extend tests to verify secrets are not present in the /api/config response and that redaction does not mutate the original config.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
router/server.go Switch /api/config to return HTTP 200 and a sanitized config copy.
router/server_test.go Update expected status to 200 and add assertions that secrets don’t appear in the response.
config/config.go Introduce SanitizedCopy() and redact() helper for secret redaction.
config/config_test.go Add unit tests for SanitizedCopy() including empty-field behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Add Core.CertPath and Core.KeyPath to redacted fields
- Redact Core.FeedbackHeader entries that may contain API keys
- Add test assertions for new redacted fields and original immutability

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@appleboy appleboy merged commit 03c17fd into master Mar 10, 2026
12 of 13 checks passed
@appleboy appleboy deleted the fix/redact-config-endpoint-secrets branch March 10, 2026 14:27
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