这是indexloc提供的服务,不要输入任何密码
Skip to content

Security improvement: do not log full keys in logs #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 24, 2025

Conversation

lins05
Copy link
Contributor

@lins05 lins05 commented Jul 21, 2025

Before (full keys logged):

2025-07-20 08:37:01,477 | INFO     | [gemini_routes.py:129]         | Using API key: AIxxxxxxxxxx-yyyyyyyy-zzzzzzzzzzzzzzzzz
INFO POST /verify-key/AIxxxxxxxxxx-yyyyyyyy-zzzzzzzzzzzzzzzzz

After (redacted keys logged):

2025-07-20 08:37:01,477 | INFO     | [gemini_routes.py:129]         | Using API key: AIxxxx...yyyyyy
INFO POST /verify-key/AIxxxx...yyyyyy

lins05 added 3 commits July 21, 2025 02:03
- Add redact_key_for_logging() helper function to show only first/last 6 chars
- Fix API key exposure in app/service/key/key_manager.py line 68
- Apply key redaction across all Python files with API key logging
- Standardize logging security across 17 files including routers, services, handlers
- Add AccessLogFormatter class with regex patterns for API key detection
- Create setup_access_logging() function to configure uvicorn access logs
- Support redaction for Google/Gemini (AIza*) and OpenAI (sk-*) API keys
- Configure main.py to use custom access logging with redaction
- Prevent API key exposure in HTTP access logs like "POST /verify-key/AIza..."

Now access logs show: "POST /verify-key/AIzaxx...xyzxyz" instead of full keys
…ror handling

- Refactored redaction logic to use centralized helper function
- Added robust error handling in AccessLogFormatter
- Improved regex patterns for better OpenAI key detection
- Added comprehensive unit tests covering edge cases and error scenarios
- Enhanced input validation with descriptive error placeholders
@snailyp snailyp merged commit e739477 into snailyp:main Jul 24, 2025
Copy link
Owner

@snailyp snailyp left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, it's awesome!

Copy link
Owner

@snailyp snailyp left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

@lins05 lins05 deleted the hide-keys-in-logs branch July 25, 2025 12:47
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