fix(scan): resolve .socket.facts.json against the scan cwd so tier1 finalize isn't silently skipped#1348
Merged
Benjamin Barslev Nielsen (barslev) merged 1 commit intoMay 31, 2026
Conversation
…inalize isn't silently skipped performReachabilityAnalysis spawns Coana with the scan cwd, so Coana writes <scanCwd>/.socket.facts.json, but the tier1 scan id was read back via a relative path resolved against process.cwd(). When the scan cwd differed from process.cwd() (e.g. --cwd <dir>) the read missed, the tier1 id came back undefined, and the finalize guard fell through with nothing logged, leaving the tier1 reachability row unlinked. extractReachabilityErrors (used by scan reach) shared the same bug. Resolve the facts path against the scan cwd at the read sites (extractTier1ReachabilityScanId and extractReachabilityErrors); the returned/uploaded report path stays cwd-relative so upload and cleanup behavior is unchanged. Warn when reachability ran and a scan was created but no tier1 id could be extracted, so the skip is never silent. Adds regression coverage for the cwd-mismatch case, the reachability-errors read, and the warning path.
Martin Torp (mtorp)
approved these changes
May 31, 2026
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.
Problem
socket scan reachandsocket scan create --reachcould silently skip the tier1 reachability finalize when the scan's cwd differed from the CLI process's cwd (e.g.--cwd <dir>, or a wrapper thatchdirs elsewhere).performReachabilityAnalysisdefaults the facts output to the relative.socket.facts.jsonand spawns Coana with the scancwd, so Coana writes<scanCwd>/.socket.facts.json. The result then read the tier1 scan id back viaextractTier1ReachabilityScanId(outputFilePath), which resolves that relative path againstprocess.cwd(). WhenscanCwd !== process.cwd()the read missed →tier1ReachabilityScanIdwasundefined→ the finalize guard fell through with nothing logged → the tier1 reachability row stayed in its post-Coana state and the full scan's reachability report was never linked.extractReachabilityErrors(used byscan reach) shared the same relative-read bug.The default case (run from inside the project, no
--cwd) was unaffected.Fix
cwdat the read sites —extractTier1ReachabilityScanIdandextractReachabilityErrorsnow readpath.resolve(cwd, …)— so Coana's write and the CLI's read always agree. The returned/uploaded report path stays cwd-relative and unchanged, so upload and post-success cleanup behavior is untouched.cwd !== process.cwd()case (fails before this change), plus the reachability-errors read and the warning path.Follow-up
#1331 adds a standalone tier1 finalize to
socket scan reach. It reads the sametier1ReachabilityScanIdfrom the shared analysis function, so it inherits this path fix automatically. When the two land together: keep both edits at the tail ofhandle-scan-reach.mts(its finalize block plus thecwdargument added here), and add the same "missing tier1 id" warning to its guard for parity with the scan-create path.Note
Medium Risk
Changes reachability scan linking and facts-file I/O in scan create/reach paths; behavior is localized with regression tests but affects enterprise tier1 finalize correctness.
Overview
Fixes reachability flows when the scan
cwdis not the CLI’sprocess.cwd()(e.g.--cwd): Coana writes.socket.facts.jsonunder the scan cwd, but tier 1 ID extraction and per-vulnerability error reads used a bare relative path and could miss that file—skippingfinalizeTier1Scanand hiding reachability errors.performReachabilityAnalysisnow reads the tier 1 scan id viapath.resolve(cwd, …)while still returning a cwd-relative report path for upload/cleanup.outputScanReachtakescwdand resolves the facts file the same way forextractReachabilityErrors.handleCreateNewScanlogs a warning when reachability ran and a full scan was created but no tier 1 id was found, instead of silently skipping finalize.Regression tests cover the
cwd !== process.cwd()case, the warning path, and error surfacing fromoutputScanReach.Reviewed by Cursor Bugbot for commit c831cbf. Configure here.