fix: resolve critical review findings (data race, permissions, goroutine leak, CSP) - #18
Open
jgardiner68 wants to merge 4 commits into
Open
fix: resolve critical review findings (data race, permissions, goroutine leak, CSP)#18jgardiner68 wants to merge 4 commits into
jgardiner68 wants to merge 4 commits into
Conversation
Job.Sent/Failed/Progress, DailyLimit, DaySent, Status and Error were written directly from the send goroutine while HTTP handlers read them via the mutex-guarded ToJSON. Route all writes through new locked methods (Resume, SetDailyLimit, PauseForDailyLimit) and add locked reads (GetStatus, finishedBefore) for JobManager.GetActive, Cleanup and saveJobProgress.
The SQLite history DB and browser screenshots both contain personal data but were created with umask-dependent / world-readable modes. Chmod the DB to 0600 after creation; write screenshots 0600 in a 0700 directory.
WatchForNewEmails returned on ctx.Done without waiting for the IDLE goroutine to exit, leaking one goroutine (and its channel send) per cancelled watch. Drain idleDone after closing stop.
Serve the Tailwind runtime and HTMX from /static/js instead of cdn.tailwindcss.com and unpkg.com (the local Tailwind runtime was already vendored but misnamed .css). Drop the CDN hosts and 'unsafe-eval' from script-src and add object-src 'none'. 'unsafe-inline' remains until inline handlers move to a nonce-based setup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the critical and high-severity findings from a full code review: a data race on job state, world-readable files containing personal data, a goroutine leak in the IMAP watcher, and a weak Content-Security-Policy relying on third-party CDNs.
Changes
Data race on
Jobfields (critical)internal/web/server.gowroteJob.Sent,Failed,Progress,DailyLimit,DaySent,Status, andErrordirectly from the background send goroutine while HTTP handlers (/api/job/active,/api/job/{id}/status) read them concurrently through the mutex-guardedToJSON. All writes now go through new locked methods onJob(Resume,SetDailyLimit,PauseForDailyLimit), and previously-unlocked reads inJobManager.GetActive,JobManager.Cleanup, andsaveJobProgressnow use locked accessors (GetStatus,finishedBefore).File permissions on personal data (high)
chmod 0600after creation (internal/history/history.go).0644in a0755directory; now0600in a0700directory (internal/browser/browser.go).IMAP IDLE goroutine leak (high)
WatchForNewEmailsreturned on context cancellation without waiting for the IDLE goroutine to finish, leaking one goroutine (blocked on a channel send) per cancelled watch. It now drainsidleDoneafter closingstop(internal/inbox/monitor.go).CSP hardening (high)
/static/js/instead of loaded fromcdn.tailwindcss.comandunpkg.com— no third-party script execution, no usage leaked to CDNs. The Tailwind runtime was already vendored but misnamedstatic/css/tailwind.min.css(it's the JS Play CDN runtime); renamed tostatic/js/tailwind.min.js.script-srcdrops the CDN hosts and'unsafe-eval'(no template uses htmx'shx-on/js:eval features); addedobject-src 'none'.'unsafe-inline'is retained for now — templates use inlineonclickhandlers and script blocks; removing it needs a nonce-based refactor (follow-up).Test plan
go build ./...,go vet ./...passgo test -race ./...passesJobwrites +ToJSONreads under-race