-
Notifications
You must be signed in to change notification settings - Fork 0
🛡️ Sentinel: [HIGH] Remove insecure secret retrieval from environment variables #958
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -37,3 +37,8 @@ | |||||||||||||||||
| **Vulnerability:** The application used a hardcoded fallback secret key (`"dev-secret-key-do-not-use-in-production-change-me"`) for JWT token generation and validation if the `SECRET_KEY` environment variable was missing. | ||||||||||||||||||
| **Learning:** Hardcoded cryptographic secrets are a severe vulnerability (CWE-798). If the environment variable isn't set properly, the application falls back to an insecure, easily guessable default in production, compromising all tokens. | ||||||||||||||||||
| **Prevention:** Never use default fallback values for cryptographic secrets. When removing hardcoded cryptographic secrets to use environment variables, ensure the application fails securely (e.g., raises a `ValueError`) if the variable is unset, rather than falling back to an insecure default. For testing, set dummy values in `conftest.py` before application imports. | ||||||||||||||||||
|
|
||||||||||||||||||
| ## 2025-04-05 - Remove insecure secret retrieval from environment variables | ||||||||||||||||||
| **Vulnerability:** Retrieving API keys directly from `os.getenv` instead of using the centralized secrets management solution. | ||||||||||||||||||
| **Learning:** Hardcoded environment variables don't support dynamic rotation, centralized security management (AWS Secrets Manager, Vault, etc), and potentially risk exposure if `.env` files are accidentally committed or logged. Using `core.secrets.get_secret()` allows transparent migration to secure vaults. | ||||||||||||||||||
| **Prevention:** Always use `get_secret` from `core.secrets` when accessing secrets like API keys or credentials. | ||||||||||||||||||
|
Comment on lines
+41
to
+44
|
||||||||||||||||||
| ## 2025-04-05 - Remove insecure secret retrieval from environment variables | |
| **Vulnerability:** Retrieving API keys directly from `os.getenv` instead of using the centralized secrets management solution. | |
| **Learning:** Hardcoded environment variables don't support dynamic rotation, centralized security management (AWS Secrets Manager, Vault, etc), and potentially risk exposure if `.env` files are accidentally committed or logged. Using `core.secrets.get_secret()` allows transparent migration to secure vaults. | |
| **Prevention:** Always use `get_secret` from `core.secrets` when accessing secrets like API keys or credentials. | |
| ## 2025-04-05 - Remove insecure direct environment secret retrieval | |
| **Vulnerability:** Retrieving API keys directly from `os.getenv` instead of using the centralized secrets management solution. | |
| **Learning:** Direct environment variable access for secrets via `os.getenv` does not provide centralized rotation, auditing, or secret management (AWS Secrets Manager, Vault, etc.), and still risks exposure if `.env` files are accidentally committed or logged. Using `core.secrets.get_secret()` allows transparent migration to secure vaults. | |
| **Prevention:** Always use `get_secret` from `core.secrets` when accessing secrets like API keys or credentials, rather than retrieving them directly from environment variables. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,13 +9,14 @@ | |
| import httpx | ||
| from typing import Optional, Dict, Any | ||
| import logging | ||
| from core.secrets import get_secret | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| # CurseForge API configuration | ||
| CURSEFORGE_API_BASE_URL = "https://api.curseforge.com/v1" | ||
| # Note: Requires API key in production - get from https://console.curseforge.com/ | ||
| CURSEFORGE_API_KEY = os.getenv("CURSEFORGE_API_KEY", "") | ||
| CURSEFORGE_API_KEY = get_secret("CURSEFORGE_API_KEY", "") | ||
|
|
||
|
Comment on lines
16
to
20
|
||
|
|
||
| class CurseForgeService: | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |||
| import logging | ||||
| from typing import Optional, List, Dict, Any | ||||
| from dataclasses import dataclass | ||||
| from core.secrets import get_secret | ||||
|
|
||||
| logger = logging.getLogger(__name__) | ||||
|
|
||||
|
|
@@ -283,7 +284,7 @@ def get_email_service( | |||
| if _email_service is None: | ||||
| import os | ||||
|
|
||||
|
Comment on lines
285
to
286
|
||||
| import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Validate that get_secret’s behavior on missing SENDGRID_API_KEY still allows the log-only fallback path.
Previously, a missing SENDGRID_API_KEY resulted in None and fell through to the if not api_key: block, triggering the log-only behavior. With get_secret("SENDGRID_API_KEY"), if the secret is missing and it either raises or returns a truthy sentinel, we may skip that fallback and fail earlier. Please confirm that get_secret returns a falsy value (e.g., None) when the secret is absent, or catch/handle its exceptions here to preserve the existing log-only behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (typo): Add a period after "etc" inside the parentheses for correct punctuation.
Change
etc)toetc.)so the abbreviation is correctly punctuated within the parentheses.