When adding logging/debug output for authentication/authorization, apply two rules:
1) Auth configuration metadata is OK
2) Any secret-like value must be redacted/truncated
Example (safe logging pattern):
def mask_secret(value: str, keep_last: int = 8) -> str:
if not value:
return '***'
return f"{'*' * 20}...{value[-keep_last:] if len(value) > keep_last else '***'}"
# Usage
logging.info(f" ANTHROPIC_API_KEY: {mask_secret(anthropic_api_key) if anthropic_api_key else '***'}")
logging.info(f" GATEWAY_ACCESS_TOKEN: {mask_secret(gateway_access_token) if gateway_access_token else '***'}")
# Auth configuration metadata is fine (no tokens/keys)
logging.info(f" AllowedOAuthFlows: {client.get('AllowedOAuthFlows', [])}")
logging.info(f" ExplicitAuthFlows: {client.get('ExplicitAuthFlows', [])}")
Enforcement guidance: