Skip to content

feat(scan): scan Bazel targets with --bazel - #1788

Merged
Jeppe Fredsgaard Blaabjerg (jfblaa) merged 5 commits into
v1.xfrom
jfblaa/bazel-sca-v1x
Dec 2, 2026
Merged

Jeppe Fredsgaard Blaabjerg (jfblaa) merged 5 commits into
v1.xfrom
jfblaa/bazel-sca-v1x

Conversation

@jfblaa

@jfblaa Jeppe Fredsgaard Blaabjerg (jfblaa) commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Heads up, reviewer

Add internal command for experimenting with bazel support.


Claude Code · claude-opus-5-5

socket scan create <root> --bazel -- <patterns> scans only the Bazel targets the patterns match, from the workspace root, instead of discovering manifests. Coana resolves the patterns as bazel build does and generates one Socket facts file for those targets. With --reach, it analyses the JVM, Python and JavaScript targets. --bazel is hidden.

Behaviour
  • Patterns go after --, as on Bazel's own command line, so a negative pattern such as -//app/legacy/... is no flag. A pattern before --, or any short flag the command does not declare, is refused with a message saying to move it.
  • One TARGET before --: the workspace root, the directory holding MODULE.bazel, REPO.bazel, WORKSPACE or WORKSPACE.bazel, inside the working directory (--cwd selects one outside it). --bazel is refused with --auto-manifest, --dynamic-sbom-inference, --uv-members and --exclude-paths.
  • Only the facts file is uploaded. Reachability is narrowed to the ecosystems of the targets Coana analyses, and a warning names the other targets, whose dependencies are scanned without reachability.
  • Bazel comes from SOCKET_CLI_BAZEL_PATH, else bazelisk or bazel on PATH. socket manifest bazel now also takes SOCKET_CLI_BAZEL_PATH ahead of --bazel, in every build, as Gradle, Maven and sbt take theirs.
  • Facts generation passes Coana the run's --purpose, as every other build does, and a reachability run compiles the targets.
Not in this PR
  • Bazel settings from socket.json (binary, flags, bazelrc). A Bazel scan takes none yet.
  • One workspace-root check shared with socket manifest bazel and auto-detection, which do not know REPO.bazel.
  • socket fix for Bazel builds (REA-1372).
Tests
  • cmd-scan-create.test.mts: the accepted forms, and each refusal, including a pattern before --; a declared short flag with an attached value is accepted.
  • handle-create-new-scan.test.mts: a Bazel scan uploads the facts file alone and narrows reachability to its targets' ecosystems.
  • bin-detect.test.mts: SOCKET_CLI_BAZEL_PATH ahead of --bazel; a scan's error names only SOCKET_CLI_BAZEL_PATH.
  • End to end in a testing org, with a local Coana build of #2890:
    • JVM and mixed Python/Java scans gave function-level reachable traces.
    • npm: lodash _.template was reachable from main.js, and the packages it never calls were unreachable.
    • Rust and Go scans uploaded every package with its advisories.

Closes REA-1247
Closes REA-1249
Closes REA-1250
Closes REA-1251
Closes REA-1303

🤖 Generated with Claude Code

Scans only the Bazel targets the patterns after `--` name, from the
workspace root, in place of manifest discovery. Coana resolves the
patterns as `bazel build` takes them and generates the Socket facts;
reachability analyses the JVM, Python and JavaScript targets.

Facts generation passes Coana the run's `--purpose`, as every other
build does, and a reachability run compiles the targets.
@jfblaa
Jeppe Fredsgaard Blaabjerg (jfblaa) marked this pull request as ready for review December 1, 2026 19:31
@cursor

cursor Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Introduces a new scan pipeline that shells out to Bazel/Coana and changes reachability scope; depends on an unreleased Coana build, but the flag is hidden and heavily validated.

Overview
Adds a hidden --bazel mode to socket scan create so scans are driven by Bazel target patterns after -- (e.g. socket scan create . --bazel -- //app/...) instead of walking manifests. The CLI requires a single workspace-root TARGET, validates patterns stay after --, and refuses mixing with --auto-manifest, --dynamic-sbom-inference, --uv-members, or --exclude-paths.

Bazel facts path: New runBazelFacts builds a Coana generate-socket-facts request with tool: 'bazel' and target patterns; reachability runs compile those targets. The scan uploads only the generated Socket facts file. With --reach, ecosystems are narrowed to maven, npm, and pypi from the facts payload; unsupported targets get a warning and dependency-only scanning.

Bazel binary resolution: resolveBazelBinary now prefers SOCKET_CLI_BAZEL_PATH over --bazel (aligned with other build tools), with clearer errors when no CLI flag names Bazel. AUTO_MANIFEST_HINTS is centralized in run-manifest-facts.mts.

Reviewed by Cursor Bugbot for commit 8cf7dae. Configure here.

Comment thread src/commands/scan/cmd-scan-create.mts Resolved
Comment thread src/commands/scan/cmd-scan-create.mts Resolved
Comment thread CHANGELOG.md Resolved
Refuse a --bazel workspace root outside the working directory, as
--reach does for its target, and point at --cwd. The repeat-command
hint now names the org with --org and includes --bazel.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread CHANGELOG.md Resolved
--bazel is hidden, so the release notes leave it out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	src/commands/scan/handle-create-new-scan.mts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jfblaa
Jeppe Fredsgaard Blaabjerg (jfblaa) merged commit 4cc885d into v1.x Dec 2, 2026
19 of 31 checks passed
@jfblaa
Jeppe Fredsgaard Blaabjerg (jfblaa) deleted the jfblaa/bazel-sca-v1x branch December 2, 2026 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants