Skip to content

chore: re-vendor lib/#1332

Open
cbrnrd wants to merge 1 commit into
mainfrom
carterbrainerd-vuln-91-arbitrary-command-execution-in-src-cli-via-unescaped
Open

chore: re-vendor lib/#1332
cbrnrd wants to merge 1 commit into
mainfrom
carterbrainerd-vuln-91-arbitrary-command-execution-in-src-cli-via-unescaped

Conversation

@cbrnrd

@cbrnrd cbrnrd commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

This PR re-vendors lib/ (commit de6bd07264d). Among other changes, this includes a security fix to prevent attacker controlled filenames in batch changes from executing commands.

@keegancsmith keegancsmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lib is vendored in from our monorepo, so you need to make changes rather in the monorepo and then vendor it back in here.

I'm also not sure we should be escaping these values. Our templates are not just used for constructing commands in batch changes. I'll let @burmudar comment further, I think he had looked into this stuff not so long ago?? (Or did we both look into it? :) )

Generally batch changes are run on repos you have write access to though... which makes this not really an issue in practice. However, I do see us needing to provide some way to do shell escaping since that means previous uses of this would naively break i fyou r filename had a space in it

return r.FileMatches
paths := make([]string, len(r.FileMatches))
copy(paths, r.FileMatches)
sort.Strings(paths)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no need to sort

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Why not? the previous version of the function sorted the paths.

@burmudar

burmudar commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

lib is vendored in from our monorepo, so you need to make changes rather in the monorepo and then vendor it back in here.

I'm also not sure we should be escaping these values. Our templates are not just used for constructing commands in batch changes. I'll let @burmudar comment further, I think he had looked into this stuff not so long ago?? (Or did we both look into it? :) )

Generally batch changes are run on repos you have write access to though... which makes this not really an issue in practice. However, I do see us needing to provide some way to do shell escaping since that means previous uses of this would naively break i fyou r filename had a space in it

Yeah we did at some point, it's all a bit muddled now but I took a jog down memory lane. This templating is used to render into step-condition or the run step so on some level it is good to escape this.

  • I think we need to add shellquote_split too if we have join
  • Document both so that customers can use them more deliberately.

@cbrnrd

cbrnrd commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Generally batch changes are run on repos you have write access to though... which makes this not really an issue in practice.

I disagree. Even if you have access to the repository, that doesn't necessarily make it a trusted source you want to be running code from. Since the attack vector here is a filename, just by including a malicious repo in your spec can trigger command execution locally.

@cbrnrd

cbrnrd commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

@keegancsmith @burmudar I opened a PR in the monorepo for this: https://github.com/sourcegraph/sourcegraph/pull/12869
Once that's merged to main I'll update lib/ here.

@cbrnrd cbrnrd changed the title fix/security: shell-escape attacker-controlled filenames in batch change templates chore: re-vendor lib/ Jun 11, 2026
@cbrnrd cbrnrd force-pushed the carterbrainerd-vuln-91-arbitrary-command-execution-in-src-cli-via-unescaped branch from c897f06 to d5e40eb Compare June 11, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants