GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix/batch-changes: validate files target paths in changeset hooks and executor by cbrnrd · Pull Request #1352 · sourcegraph/src-cli

Conversation

@cbrnrd

@cbrnrd cbrnrd commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Problem

src-cli rejects commas in top-level steps.files target paths because a comma breaks out of Docker --mount syntax and lets an attacker inject arbitrary source=/target= pairs (e.g. mounting /var/run/docker.sock). That same validation was missing for changesetHooks.*.steps[].files, so a malicious v3 batch spec could smuggle a dangerous files target path through a hook and reach the executor-side Docker mount sink.

The executor (src batch exec) makes this worse: it loads already-parsed Step structs from JSON and never re-runs ParseBatchSpec/validateHooks, so parse-time validation alone is a coordinator-only guard.

Solution

  • Add the missing comma check for files target paths in validateHooks (covers both onCIFailure and onMergeConflict).
  • Add defense-in-depth validation at the executor sink in createFilesToMount, so the check holds regardless of how a step reaches the executor.

Verification Evidence

$ go test ./internal/batches/service/ -run ParseBatchSpec -v
--- PASS: TestService_ParseBatchSpec/hook_files_target_path_with_comma

$ go test ./internal/batches/executor/ -run CreateFilesToMount -v
--- PASS: TestCreateFilesToMount_RejectsCommaInTargetPath

$ go test ./internal/batches/...
ok  	github.com/sourcegraph/src-cli/internal/batches/executor	2.402s
ok  	github.com/sourcegraph/src-cli/internal/batches/service	0.626s
(all batch packages pass)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@cbrnrd
fix/batch-changes: validate files target paths in changeset hooks and…
8870df6
… executor
@cbrnrd
cbrnrd requested review from andreeleuterio and bahrmichael July 7, 2026 17:27
keegancsmith
keegancsmith approved these changes Jul 9, 2026
View reviewed changes
Comment thread lib/batches/batch_spec.go Outdated
)))
}
}
for name := range step.Files {

@keegancsmith keegancsmith Jul 9, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI the code here is vendored from our monorepo.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cbrnrd cbrnrd Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gah right, my previous attempts to re-vendor this did not go so well, but I will split this off into a separate PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cbrnrd cbrnrd Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/sourcegraph/sourcegraph/pull/13942

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread internal/batches/executor/run_steps.go
Comment on lines +543 to +552
// Defense-in-depth: the mount target name is concatenated directly
// into a Docker `--mount type=bind,...,target=<name>` argument. A comma
// in the name would let an attacker break out of the mount spec and
// inject arbitrary source=/target= pairs (e.g. /var/run/docker.sock).
// Parse-time validation rejects this, but the executor receives
// pre-parsed steps via JSON and never re-runs that validation, so we
// re-check here at the sink.
if strings.Contains(name, ",") {
return nil, cleanup, errors.Newf("files target path %q contains invalid characters", name)
}

@keegancsmith keegancsmith Jul 9, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok so this would of failed which is what we want, but now we fail earlier? And that is better from both a UX perspective + extra defense incase the other check for some reason doesn't run?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@cbrnrd cbrnrd Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
cbrnrd added 3 commits July 9, 2026 10:47
@cbrnrd
remove lib/ changes
996bcec
@cbrnrd
fix/batch-changes: drop orphaned hook files parse test
dfcb336
The hook-files parse-time validation lives in lib/batches (synced from the
sourcegraph monorepo) and was intentionally removed from this PR in
996bcec. The service_test case for it remained, so ParseBatchSpec returned
no error and the test nil-dereferenced err.Error(). The executor sink check
in createFilesToMount (and its test) remains as src-cli's defense.
@cbrnrd
Merge branch 'main' into carterbrainerd-vuln-104-changesethooks-files…
555885f
…-validation-bypass-can-reach-executor
@cbrnrd
cbrnrd enabled auto-merge (squash) July 9, 2026 16:39
@cbrnrd
cbrnrd merged commit 747e920 into main Jul 9, 2026
8 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@cbrnrd
cbrnrd deleted the carterbrainerd-vuln-104-changesethooks-files-validation-bypass-can-reach-executor branch July 9, 2026 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@keegancsmith keegancsmith keegancsmith approved these changes
@bahrmichael bahrmichael Awaiting requested review from bahrmichael
@andreeleuterio andreeleuterio Awaiting requested review from andreeleuterio

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@cbrnrd @keegancsmith
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.