Remove hardcoded secrets, load API token from env #29
No reviewers
Labels
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-card-creation#29
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fix/2-3-security-hardcoded-secrets"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
db_calls.pywithpython-dotenv+PD_API_TOKENenv varscripts/supabase_doodling.py(dead scratch file containing a hardcoded Supabase service-role JWT expiring 2031)check_prod_missing_ratings.pyto importAUTH_TOKENfromdb_callsinstead of duplicating the token.env.exampletemplate for onboardingHard fails at import time if
PD_API_TOKENis missing — prevents silent unauthenticated API requests.Post-merge action required
Both tokens remain in git history — rotate after merge:
Test plan
from db_calls import AUTH_TOKENloads token from.envPD_API_TOKENraisesEnvironmentErrorscripts/evo_milestone_simulator.pytransitive import still workspytestpasses (1 pre-existing failure intest_automated_data_fetcher.py, unrelated)Fixes #2, Fixes #3
🤖 Generated with Claude Code
AI Code Review
Files Reviewed
db_calls.py(modified).claude/ops-rework/check_prod_missing_ratings.py(modified).env.example(added)pyproject.toml(modified)scripts/supabase_doodling.py(deleted)Findings
Correctness
load_dotenv()is called at module level beforeos.environ.get(), so.envis populated into the environment before the lookup. Correct ordering.os.environ.get("PD_API_TOKEN")withif not _token:guard handles both missing and empty-string cases — both raiseEnvironmentError. Correct.load_dotenv()defaults tooverride=False, so a pre-existingPD_API_TOKENenv var (e.g., in CI) takes precedence over.env. Correct behavior.parents[2]incheck_prod_missing_ratings.pyresolves correctly:.claude/ops-rework/→.claude/→ project root. Path arithmetic verified.check_prod_missing_ratings.pyretains its ownPROD_URL(instead of importingDB_URLfromdb_calls) — this correctly insulates the diagnostic script fromalt_databaseoverrides. Intentional and correct..envis already present in.gitignore(line 105) — no risk of accidentally committing the token file.Security
Tp3aO3jhYve5NJF1IqOmJTmk) removed fromdb_calls.py. ✓check_prod_missing_ratings.py. ✓supabase_doodling.py. ✓.env.exampleprovides a safe onboarding template with no real values. ✓Style & Conventions
db_calls.py(single → double) are cosmetic and consistent within the changed lines. No functional impact.from typing import Literalremains after third-party imports — this was already the case pre-PR and is unchanged behavior, so not in scope.sys.path.insert(0, ...)in a nested ops script is pragmatic and appropriate given the file lives outside the main package structure.Suggestions
.env.exampleabout where to obtain the token (e.g., Paper Dynasty admin panel), so future contributors know where to look without having to read the codebase. Non-blocking.Verdict: APPROVED
Clean, focused security fix. Implementation is correct, fail-fast behavior is properly enforced at import time,
.envis already gitignored, and the deletion of the Supabase scratch file removes the only other hardcoded credential in the codebase. The post-merge token rotation reminder in the PR body is the right call.Automated review by Claude PR Reviewer
Security fix — removes hardcoded secrets. Reviewed by PO triage. Supersedes #42 and #44.