fix(security,test): clear 3 SonarCloud vulnerabilities + flaky pipeline test#74
Merged
Conversation
…ne test
Three real findings flagged by SonarCloud's analysis on main, plus a
race-detector flake that surfaced post-merge.
Vulnerabilities
* BLOCKER gosecurity:S2083 — internal/ui/ui.go:58 path-injection.
The SPA fallback handler passed r.URL.Path straight to distFS.Open.
embed.FS already rejects ".." segments, but Sonar's taint tracker
can't see that. Sanitize at the boundary: path.Clean + reject any
residual ".." + default empty path to "index.html". Same behavior,
explicit gate.
* MAJOR githubactions:S8234 ×2 — .github/workflows/{scorecard,security}.yml.
Top-level "permissions: read-all" replaced with the minimum
"permissions: { contents: read }" needed for actions/checkout.
Each job already declares the narrower scopes it actually needs
(security-events: write, id-token: write, etc.), so the overly
permissive default was redundant and tripped Scorecard's
Token-Permissions guidance.
Flaky test
* internal/ingest/pipeline_test.go:497,504 —
TestPipeline_PerTenantCap_ReleasedAfterProcess used 2s waitFor
deadlines that fail under the race detector on busy CI runners.
Bumped both to 5s. Test passes locally in milliseconds; the
timeout is purely a CI-flake margin. Confirmed reproducible-pass
locally with -race -count=5.
Verification
* go vet ./... clean
* go test ./... — 516 pass / 27 packages
* go build ./... clean
Out of scope (next pass)
* 147 code-smell issues (cognitive complexity ×55, string-literal
duplication ×31, TS-specific ×24, etc.). Tracked separately —
fixing them in this PR would muddle the security-fix scope.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sonar's go-security taint engine kept flagging the explicit distFS.Open(rel) call in the SPA-fallback handler even after path.Clean + ".." check. The pattern is structurally safe (embed.FS rejects ".." on its own) but the engine can't model it. Restructure: wrap the dist sub-FS with spaFS — when http.FileServer hits ErrNotExist on an extensionless path, the wrapper transparently serves index.html so the React router can claim the URL. Asset-shaped paths (anything with ".") still 404 normally, so a missing favicon doesn't surprise the browser with an HTML body. Net result: the user-controlled URL never crosses our own Open() call — http.FileServer is the only caller, and Sonar trusts that boundary. Verification * go vet ./... clean * go test ./... — 516 pass / 27 packages * go build ./... clean Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The PR #74 amendment surfaced a second flaky test (TestPipeline_PreservesInsertionOrder) that fails on CI under the race detector for the same reason as the first: 2-second deadlines too tight. Two fixes * Bulk-bump all remaining waitFor(t, 2*time.Second, ...) calls in pipeline_test.go to 5 seconds (5 sites). Tolerates race-detector overhead on slow CI runners; locally these all complete in milliseconds. * TestPipeline_PreservesInsertionOrder synced on Stats().Processed == 1 but asserted on snapshotOrder() length. Stats() can bump between BatchCreate calls under the race detector, leaving the order snapshot partial. Switched the wait to len(w.snapshotOrder()) >= 3 — the actual condition the assertion cares about. Verification * go test -race -count=3 ./internal/ingest/... — 114 pass × 3 runs * go vet ./... clean * locally reproducible-pass under -race Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
SonarCloud quality gate failed PR #74 on new_duplicated_lines_density=3.5% (threshold 3%). The duplication is between TestPipeline_FailedSpansSkipsLogs and TestPipeline_FailedTracesAbortsBatch — same boilerplate, same waitFor, same assertion shape. The waitFor 2s→5s bump made those lines "new code", so Sonar recounted the existing duplication against the PR's new-code budget. Extract runFailureSkipsCheck(t, writer, forbidden...) — single helper takes the configured fakeWriter and the BatchCreate* names that must not fire after the seeded upstream failure. Each failing-path test collapses to a single line. Verification * go test -race -count=3 -run 'TestPipeline_Failed*' — pass × 3 * go vet ./... clean Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
aksOps
added a commit
that referenced
this pull request
May 25, 2026
CI's build/vet/test job and OSV-Scanner both fail because the runner
cannot authenticate to github.com/RandomCodeSpace/central-ops — the
private repo returns 404 to the GH App identity the action uses. Local
agents hit the same wall. The dep was contributing exactly two tiny
helpers; inline them so otelcontext compiles with public Go modules
only.
- main.go: replace version.Detect() with detectVersion(), an inline
helper that walks runtime/debug.BuildInfo for Main.Version (the same
thing version.Detect did). Falls back to "local" for go run / unstamped
builds. The runtime/debug import was already present.
- internal/mcp/server.go: replace httputil.CORSMiddleware("*", h) with
corsMiddleware("*", h), an inline 12-line http.Handler wrapper. Adds
Access-Control-Allow-* headers, expects only the verbs and request
headers the MCP transport actually uses (Content-Type, Authorization,
Accept, X-Tenant-ID, Mcp-Session-Id), short-circuits OPTIONS with 204.
Same surface, no behaviour change.
- go.mod: drop `require github.com/RandomCodeSpace/central-ops v0.1.0`.
go mod tidy then auto-bumps two indirect transitive deps that were
pinned by the dep graph reshuffle: golang.org/x/sys v0.44.0 -> v0.45.0
and golang.org/x/text v0.36.0 -> v0.37.0. Both above the OSV-Scanner
patched baselines.
- go.sum: 6 lines removed (2 each for central-ops, x/sys old, x/text old).
Verified: go build ./..., go vet ./..., go test ./internal/{config,mcp}/...
all pass against a 100% public module graph. Full test suite has one
known-flaky pipeline_test (TestPipeline_StoreMinSeverity) that fixed
itself on 3 single-package re-runs and was flagged on the same branch
in commit d7c8064 (#74); not introduced here.
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 real SonarCloud vulnerability findings + the
TestPipeline_PerTenantCap_ReleasedAfterProcessrace-detector flake that surfaced post-merge onmain.gosecurity:S2083(path injection)internal/ui/ui.go:58path.Clean+ reject..at the boundary; default empty path toindex.html. Same behavior, taint-clean.githubactions:S8234.github/workflows/scorecard.yml:18permissions: read-all→permissions: { contents: read }.githubactions:S8234.github/workflows/security.yml:20internal/ingest/pipeline_test.go:497,5042s waitFor→5sto tolerate race detector on slow CI runners.The 147 code smells (cognitive complexity, string-literal dup, TS rules) are out of scope for this security-focused PR — tracked for a follow-up cleanup pass.
Test plan
go vet ./...— cleango test ./...— 516 pass / 27 packagesgo test -race -count=5 ./internal/ingest/— flaky test passes 5/5 locallygo build ./...— cleanmain(gate value refreshes on next analysis run, which this PR triggers)🤖 Generated with Claude Code