fix: remove plaintext bearer token from warning logs (#7) #55
No reviewers
Labels
No Label
ai-changes-requested
ai-failed
ai-merged
ai-pr-opened
ai-reviewed
ai-reviewing
ai-reviewing
ai-working
bug
enhancement
evolution
performance
phase-0
phase-1a
phase-1b
phase-1c
phase-1d
security
tech-debt
todo
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cal/paper-dynasty-database#55
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "ai/paper-dynasty-database#7"
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
Fixes #7 — Bearer tokens were being logged in plaintext on auth failures across 30 router files.
Root cause:
logging.warning(f'Bad Token: {token}')interpolated the full bearer token into the log message, writing it to the log file on every failed authentication attempt.Fix: Replaced all occurrences with
logging.warning('Bad Token: [REDACTED]')(and equivalent for messages with function-name prefixes likepatch_play - Bad Token: [REDACTED]). The f-string prefix was also removed since no interpolation is needed.Files Changed
30 router files in
app/routers_v2/:admin.py,awards.py,batstats.py,battingcardratings.py,battingcards.py,cardpositions.py,cards.py,cardsets.py,current.py,decisions.py,events.py,gamerewards.py,gauntletrewards.py,gauntletruns.py,mlbplayers.py,notifications.py,packs.py,packtypes.py,paperdex.py,pitchingcardratings.py,pitchingcards.py,pitstats.py,players.py,rarity.py,results.py,rewards.py,scouting.py,stratgame.py,stratplays.py,teams.pyTest Results
No test suite — changes verified by reviewing diff. All replacements are mechanical (find-and-replace pattern), and logging behavior is preserved (warning still fires, message still identifies the event).
Other observations
hmac.compare_digest()for token comparison inapp/dependencies.py) is a related security improvement that should be addressed separately.battingcardratings.py:162,cards.py:195,mlbplayers.py:346) — these were left as-is.Replace all logging.warning(f'Bad Token: {token}') calls with logging.warning('Bad Token: [REDACTED]') across 30 router files. Full bearer tokens were being written to log files on auth failures. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>AI Code Review
Files Reviewed
app/routers_v2/admin.py(modified)app/routers_v2/awards.py(modified)app/routers_v2/batstats.py(modified)app/routers_v2/battingcardratings.py(modified)app/routers_v2/battingcards.py(modified)app/routers_v2/cardpositions.py(modified)app/routers_v2/cards.py(modified)app/routers_v2/cardsets.py(modified)app/routers_v2/current.py(modified)app/routers_v2/decisions.py(modified)app/routers_v2/events.py(modified)app/routers_v2/gamerewards.py(modified)app/routers_v2/gauntletrewards.py(modified)app/routers_v2/gauntletruns.py(modified)app/routers_v2/mlbplayers.py(modified)app/routers_v2/notifications.py(modified)app/routers_v2/packs.py(modified)app/routers_v2/packtypes.py(modified)app/routers_v2/paperdex.py(modified)app/routers_v2/pitchingcardratings.py(modified)app/routers_v2/pitchingcards.py(modified)app/routers_v2/pitstats.py(modified)app/routers_v2/players.py(modified)app/routers_v2/rarity.py(modified)app/routers_v2/results.py(modified)app/routers_v2/rewards.py(modified)app/routers_v2/scouting.py(modified)app/routers_v2/stratgame.py(modified)app/routers_v2/stratplays.py(modified)app/routers_v2/teams.py(modified)Findings
Correctness
logging.warning(f'Bad Token: {token}')(and variants with function-name prefixes) have been replaced withlogging.warning('Bad Token: [REDACTED]'). The diff is symmetric: 107 removals, 107 additions.Bad Tokenlines inbattingcardratings.py,cards.py, andmlbplayers.pyare also updated (kept commented, token redacted) — consistent and correct.patch_decision - Bad Token: {token},patch_play - Bad Token: {token}, etc.) are all properly handled.{token}interpolation exists in any addition line.Security
valid_token()inapp/dependencies.pyusestoken == AUTH_TOKEN(simple equality), which is vulnerable to timing attacks. Issue #8 tracks thehmac.compare_digest()improvement — correctly deferred.Style & Conventions
Suggestions
log_bad_token(context: str = "")helper inapp/dependencies.pyto centralize the log message. This would make future changes (e.g., adding rate-limiting context, structured logging) a one-file update instead of 30. Not blocking — the mechanical approach is valid given the current codebase pattern.Verdict: APPROVED
Mechanical security fix is complete and correct. All 107 plaintext token interpolations are redacted across all 30 router files. No logic changes, no regressions, no new issues introduced.
Automated review by Claude PR Reviewer
8d26731096to35389cac24