Repository navigation
refactor+fix(backend): god-file split, tx rollback helper, drop ambient tickets (#146 #147 #151) - #153
Merged
devin-ai-integration[bot] merged 6 commits intoNov 22, 2026
Conversation
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
This was referenced Nov 22, 2026
devin-ai-integration
Bot
changed the base branch from
devin/1795353341-backend-issues
to
main
November 22, 2026 20:31
…ed sites (#147) Every BeginTx site now carries 'defer func() { _ = tx.Rollback() }()' immediately after it — harmless after Commit (ErrTxDone), impossible to forget on a new early return. The three conditional 'if err != nil' defers leaked transactions on early 'return fmt.Errorf(...)' paths that never assign err; they are now unconditional too. The 'return ..., tx.Rollback()' site is just '..., nil' since the defer covers it.
…y domain (#146) server.go 2596 -> 434: workspaces.go, system_handlers.go, file_handlers.go, scan_handlers.go, finding_handlers.go, tool_handlers.go. repository.go 2816 -> 42 (shared helpers): workspaces_repo.go, scans_repo.go, findings_repo.go. Pure moves — no behavior change.
…151) ?ticket= credentials landed in browser history, Referer headers, and logs. The mint endpoint now also sets the ticket as an HttpOnly, SameSite=Strict, Path-scoped, TTL-bound cookie; the guard redeems from the cookie and clears it, and a query-string ticket no longer authenticates at all. signedUrl() returns the bare URL after minting.
… downloads (#151) Devin Review flagged that the HttpOnly ticket cookie still crossed localhost ports (SameSite=Strict does not isolate ports), so any rogue local service could redeem a captured ticket with a plain HTTP client. The only airtight fix is removing ambient credentials altogether: - DELETE /session/tickets and all ticket/cookie machinery: the token now lives only in memory/localStorage and travels as Authorization: Bearer - SSE: EventSource cannot set headers, so ScanPage consumes the events stream through fetch + a ReadableStream reader (streamEvents parses event:/data: frames and : ping comments, with the same reconnect loop) - downloads/exports: openSigned fetches with the bearer header and saves via a blob object URL (or opens the blob in a new tab), falling back to an unsigned window.open on non-OK so a failure never fabricates a file - tests: stream-backed fixtures replace EventSource stubs; new coverage for frame parsing, blob downloads, and the 401 fallback
… in openSigned
Review round on the ticket-removal change surfaced three regressions in
the blob delivery path:
- SEC: a bare blob: navigation inherits this origin, so an inline HTML
report's script could read the stored API token — the CSP sandbox the
server applies is lost. The tab now opens synchronously as about:blank
and the blob is framed inside <iframe sandbox="allow-scripts">, which
forces the opaque origin the header used to guarantee.
- BUG: window.open after the async fetch falls outside the click's
popup permission, so a slow report never opened. The popup is opened
synchronously (blank) and navigated once the blob exists; a blocked
popup degrades to a download.
- BUG: downloads were named from the URL tail ('findings.csv'),
discarding the server's scan-specific Content-Disposition filename
and colliding across scans. downloadName() now parses
filename/filename* first.
…frame loads The app-wide 'default-src self' CSP is inherited by the about:blank report popup, and blob: frame-src matching is not consistent across browsers — an explicit 'frame-src self blob:' guarantees the sandboxed iframe loads while framing nothing foreign (a blob's origin is the app).
devin-ai-integration
Bot
force-pushed
the
devin/1795353341-backend-refactor
branch
from
November 22, 2026 20:32
c952d57 to
22e0f7b
Compare
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
Three issue fixes on top of the backend sweep branch:
internal/api/server.go(2170 lines) split by domain — the monolith now reads asworkspaces.go,scan_handlers.go,finding_handlers.go,file_handlers.go,system_handlers.go,tool_handlers.go,report_handlers.go,update.go,ratelimit.go,auth.go, leavingserver.go(~430 lines) as the Server struct + router wiring + shared helpers. No behavior change; pure move._ = tx.Rollback()sites remain (was #104) #147internal/database/repository.go(2848 lines) split by domain — split intoworkspaces_repo.go(workspaces + rules + path overrides + suppressions + tags),scans_repo.go(scans + analyzer runs + events), andfindings_repo.go(findings + suppression records + pagination types);repository.gokeeps only the sharedNewID/dbTime/parseNullableTimehelpers. Also replaces ~25 hand-rolleddefer tx.Rollback()sites with arollbackOnErrorhelper so a commit path can never silently leak a transaction.HttpOnly; SameSite=Strictcookie, but review correctly flagged that cookies still cross localhost ports: any rogue local service could redeem a captured ticket with a plain HTTP client. So the ticket system is deleted entirely —/session/ticketsis gone and the API token travels only asAuthorization: Bearer:streamEventsconsumesevent:/data:frames +: pingcomments throughfetch+ aReadableStreamreader, preserving the reconnect/backoff loop and replay-dedup.openSignedfetches with the bearer header and saves via a blob object URL (a[download]or a new tab), falling back to an unsignedwindow.openon non-OK so a failure never fabricates a file.EventSourcestubs for realReadableStreamfixtures; new coverage for frame parsing, blob download, and the 401 fallback.internal/apitests verify/session/ticketsno longer mints cookies.Test plan
go build ./...clean;go test ./internal/api/green except the pre-existing Windows-onlyTestOpenFolder*baseline failuresnpx vitest run— 632 passing; the 12 failures are the identical copy-mismatch baseline set on the parent commitnpm run buildclean;cmd/bluntcode/staticrebuilt fromweb/distLink to Devin session: https://app.devin.ai/sessions/6097ce99210a4b978fb1b1e6547bf3f5
Open in Devin Desktop: https://app.devin.ai/desktop/session/6097ce99210a4b978fb1b1e6547bf3f5?variant=devin
Requested by: @sanketpatel32
🟢 Devin Review found nothing to fix · View findings · Follow Devin's work