Skip to content

Commit 28dd9b5

Browse files
authored
Merge branch 'main' into carterbrainerd-vuln-137-a-tracked-gitdir-file-escapes-the-serve-git-root-and-exposes
2 parents b092b1b + 695e69c commit 28dd9b5

13 files changed

Lines changed: 389 additions & 26 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ All notable changes to `src-cli` are documented in this file.
4646

4747
### Added
4848

49-
- SBOM support: Added `--image` and `--exclude-image` flags to `src sbom fetch` for filtering which docker images SBOMs are fetched for. Both flags support glob patterns (e.g., `frontend`, `*api*`) and comma-separated lists. The `sourcegraph/` image name prefix is optional.
49+
- SBOM support: Added `--image` and `--exclude-image` flags to `src sbom fetch` for filtering which Docker images SBOMs are fetched for. Both flags support glob patterns (e.g., `frontend`, `*api*`) and comma-separated lists. The `sourcegraph/` image name prefix is optional.
5050

5151
### Changed
5252

@@ -88,7 +88,7 @@ All notable changes to `src-cli` are documented in this file.
8888
## 5.10.0
8989

9090
- cody gateway benchmark changes
91-
- fix local builds for non sourcegraph team [1121](https://github.com/sourcegraph/src-cli/pull/1121)
91+
- fix local builds for non Sourcegraph team [1121](https://github.com/sourcegraph/src-cli/pull/1121)
9292

9393
## 5.9.1
9494

@@ -166,7 +166,7 @@ All notable changes to `src-cli` are documented in this file.
166166

167167
### Fixed
168168

169-
- The fork attribute in changesetTemplate is now acknowleged when creating a batch change via `src-cli`. [#58156](https://github.com/sourcegraph/sourcegraph/pull/58156)
169+
- The fork attribute in changesetTemplate is now acknowledged when creating a batch change via `src-cli`. [#58156](https://github.com/sourcegraph/sourcegraph/pull/58156)
170170

171171
## 5.2.0
172172

@@ -182,7 +182,7 @@ All notable changes to `src-cli` are documented in this file.
182182

183183
### Fixed
184184

185-
- The temporary docker volume created during workspace preparation is now cleaned up when failure occurs. [#1021](https://github.com/sourcegraph/src-cli/pull/1021).
185+
- The temporary Docker volume created during workspace preparation is now cleaned up when failure occurs. [#1021](https://github.com/sourcegraph/src-cli/pull/1021).
186186

187187
## 5.1.1
188188

@@ -268,7 +268,7 @@ No noteworthy changes, mechanical release to match Sourcegraph release.
268268

269269
### Fixed
270270

271-
- Fix network timeout in `src users clean` occuring in instances with many users [#901](https://github.com/sourcegraph/src-cli/pull/901)
271+
- Fix network timeout in `src users clean` occurring in instances with many users [#901](https://github.com/sourcegraph/src-cli/pull/901)
272272
- Aligned parsing of spec file parameter of `src batch repos` with other commands. [#919](https://github.com/sourcegraph/src-cli/pull/919)
273273
- Remove empty log outputs during batch spec execution. [#923](https://github.com/sourcegraph/src-cli/pull/923)
274274

@@ -280,7 +280,7 @@ No noteworthy changes, mechanical release to match Sourcegraph release.
280280

281281
### Added
282282

283-
- Batch Changes: Watchdog that checks for docker responsiveness while running commands has been added. [#898](https://github.com/sourcegraph/src-cli/pull/898)
283+
- Batch Changes: Watchdog that checks for Docker responsiveness while running commands has been added. [#898](https://github.com/sourcegraph/src-cli/pull/898)
284284

285285
## 4.2.1
286286

@@ -309,7 +309,7 @@ No noteworthy changes, mechanical release to match Sourcegraph release.
309309

310310
### Changed
311311

312-
- Improved output for failing docker pulls in batch change execution. [#880](https://github.com/sourcegraph/src-cli/pull/880)
312+
- Improved output for failing Docker pulls in batch change execution. [#880](https://github.com/sourcegraph/src-cli/pull/880)
313313

314314
## 4.1.0
315315

@@ -796,7 +796,7 @@ Re-release of 3.29.3 for Sourcegraph 3.30.
796796

797797
### Fixed
798798

799-
- When specifying `-skip-errors`, the batch spec would always be empty. This ix fixed and the intended behavior has been restored. [#539](https://github.com/sourcegraph/src-cli/pull/539)
799+
- When specifying `-skip-errors`, the batch spec would always be empty. This is fixed and the intended behavior has been restored. [#539](https://github.com/sourcegraph/src-cli/pull/539)
800800

801801
## 3.27.0
802802

@@ -871,13 +871,13 @@ Re-release of 3.29.3 for Sourcegraph 3.30.
871871

872872
### Fixed
873873

874-
- The homebrew recipe for `src-cli` contained the wrong binary name.
874+
- The Homebrew recipe for `src-cli` contained the wrong binary name.
875875

876876
## 3.24.6
877877

878878
### Fixed
879879

880-
- Workspaces could sometimes fail with docker bind mount errors, due to a race condition of multiple workspaces accessing the same auxilliary files. [#468](https://github.com/sourcegraph/src-cli/pull/468)
880+
- Workspaces could sometimes fail with Docker bind mount errors, due to a race condition of multiple workspaces accessing the same auxiliary files. [#468](https://github.com/sourcegraph/src-cli/pull/468)
881881

882882
## 3.24.5
883883

@@ -1153,7 +1153,7 @@ Re-release of 3.29.3 for Sourcegraph 3.30.
11531153

11541154
- Add `--no-progress` flag to the `lsif upload` command to disable verbose output in non-TTY environments.
11551155
- `SRC_HEADER_AUTHORIZATION="Bearer $(...)"` is now supported for authenticating `src` with custom auth proxies. See [auth proxy configuration docs](AUTH_PROXY.md) for more information. [#239](https://github.com/sourcegraph/src-cli/pull/239)
1156-
- Pull missing docker images automatically. [#191](https://github.com/sourcegraph/src-cli/pull/191)
1156+
- Pull missing Docker images automatically. [#191](https://github.com/sourcegraph/src-cli/pull/191)
11571157
- Searches that result in errors will now display any alerts returned by Sourcegraph, including suggestions for how the search could be corrected. [#221](https://github.com/sourcegraph/src-cli/pull/221)
11581158

11591159
### Changed

‎DEVELOPMENT.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ For quick end-to-end CLI sanity checks against a live Sourcegraph instance, run:
6262

6363
This script intentionally uses your currently exported `SRC_*` environment variables, is not hooked up to CI, and is meant for manual regression checks (for example, to catch issues like `src users list` failing unexpectedly).
6464

65-
We adhere to the [general Sourcegraph principles for testing](https://docs.sourcegraph.com/dev/background-information/testing_principles), as well as [the Go specific directions](https://docs.sourcegraph.com/dev/background-information/languages/testing_go_code), at least to the extent they apply to a standalone tool like `src`.
65+
We adhere to the general Sourcegraph principles for testing, as well as the Go specific directions used in the main Sourcegraph repository, at least to the extent they apply to a standalone tool like `src`.
6666

6767
## Releasing
6868

‎README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- **Search & get results in your terminal**
88
- **Search & get JSON** for programmatic consumption
99
- Make **GraphQL API requests** with auth easily & get JSON back fast
10-
- Execute **[batch changes](https://docs.sourcegraph.com/batch_changes)**
10+
- Execute **[batch changes](https://sourcegraph.com/docs/batch_changes)**
1111
- **Manage & administrate** repositories, users, and more
1212
- **Easily convert src-CLI commands to equivalent curl commands**, just add --get-curl!
1313

@@ -173,7 +173,7 @@ Is your Sourcegraph instance behind a custom auth proxy? See [auth proxy configu
173173
- `src auth` - print the active authentication token or authorization header
174174
- `src search` - perform searches and get results in your terminal or as JSON
175175
- `src api` - run Sourcegraph GraphQL API requests
176-
- `src batch` - execute and manage [batch changes](https://docs.sourcegraph.com/batch_changes)
176+
- `src batch` - execute and manage [batch changes](https://sourcegraph.com/docs/batch_changes)
177177
- `src repos` - manage repositories
178178
- `src users` - manage users
179179
- `src orgs` - manages organization
@@ -185,7 +185,7 @@ Is your Sourcegraph instance behind a custom auth proxy? See [auth proxy configu
185185
- `src version` - check version and guaranteed-compatible version for your Sourcegraph instance
186186

187187
Run `src -h` and `src <subcommand> -h` for more detailed usage information.
188-
You can also read the [usage docs for the latest version of `src-cli`](https://docs.sourcegraph.com/cli/references) online.
188+
You can also read the [usage docs for the latest version of `src-cli`](https://sourcegraph.com/docs/cli/references) online.
189189

190190
#### Optional: Renaming `src`
191191

@@ -211,7 +211,7 @@ src-cli/3.21.10 linux amd64
211211

212212
To disable this and _only_ send the version, you can set `-user-agent-telemetry=false` for a single command, or set the `SRC_DISABLE_USER_AGENT_TELEMETRY` environment variable to any non-blank string.
213213

214-
As with [other Sourcegraph telemetry](https://docs.sourcegraph.com/dev/background-information/telemetry), any collected data is only sent to Sourcegraph.com in aggregate form.
214+
As with other Sourcegraph telemetry, any collected data is only sent to Sourcegraph.com in aggregate form.
215215

216216
## Development
217217

‎cmd/src/search.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Other tips:
4848
4949
Force color output on (not on by default when piped to other programs) by setting COLOR=t
5050
51-
Query syntax: https://docs.sourcegraph.com/code_search/reference/queries
51+
Query syntax: https://sourcegraph.com/docs/code_search/reference/queries
5252
5353
Be careful with search strings including negation: a search with an initial
5454
negated term may be parsed as a flag rather than as a search string. You can

‎internal/api/flags.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func NewFlags(flagSet *flag.FlagSet) *Flags {
4242
return &Flags{
4343
dump: flagSet.Bool("dump-requests", false, "Log GraphQL requests and responses to stdout"),
4444
getCurl: flagSet.Bool("get-curl", false, "Print the curl command for executing this query and exit (WARNING: includes printing your access token!)"),
45-
trace: flagSet.Bool("trace", false, "Log the trace ID for requests. See https://docs.sourcegraph.com/admin/observability/tracing"),
45+
trace: flagSet.Bool("trace", false, "Log the trace ID for requests. See https://sourcegraph.com/docs/admin/observability/tracing"),
4646
insecureSkipVerify: flagSet.Bool("insecure-skip-verify", false, "Skip validation of TLS certificates against trusted chains"),
4747
userAgentTelemetry: flagSet.Bool("user-agent-telemetry", defaultUserAgentTelemetry(), "Include the operating system and architecture in the User-Agent sent with requests to Sourcegraph"),
4848
}

‎internal/batches/ui/tui.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ func printExecutionError(out *output.Output, err error) {
400400
out.Write("")
401401

402402
block := out.Block(output.Line(output.EmojiLightbulb, output.StyleSuggestion, "The troubleshooting documentation can help to narrow down the cause of the errors:"))
403-
block.WriteLine(output.Line("", output.StyleSuggestion, "https://docs.sourcegraph.com/batch_changes/references/troubleshooting"))
403+
block.WriteLine(output.Line("", output.StyleSuggestion, "https://sourcegraph.com/docs/batch_changes/references/troubleshooting"))
404404
block.Close()
405405
}
406406

‎internal/batches/workspace/bind_workspace.go‎

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,22 @@ func (wc *dockerBindWorkspaceCreator) Create(ctx context.Context, repo *graphql.
3434
return nil, errors.Wrap(err, "copying additional files into workspace")
3535
}
3636

37-
return w, errors.Wrap(wc.prepareGitRepo(ctx, w), "preparing local git repo")
37+
if err := wc.prepareGitRepo(ctx, w); err != nil {
38+
return nil, errors.Wrap(err, "preparing local git repo")
39+
}
40+
41+
w.gitMetadata, err = snapshotGitMetadata(w.dir)
42+
return w, errors.Wrap(err, "snapshotting local git metadata")
3843
}
3944

4045
func (*dockerBindWorkspaceCreator) prepareGitRepo(ctx context.Context, w *dockerBindWorkspace) error {
46+
// Windows can normalize archive entry names such as ".git." to ".git".
47+
// Always discard extracted Git metadata before running Git so repository
48+
// contents cannot configure commands that execute on the host.
49+
if err := os.RemoveAll(filepath.Join(w.dir, ".git")); err != nil {
50+
return errors.Wrap(err, "removing extracted git metadata")
51+
}
52+
4153
if _, err := runGitCmd(ctx, w.dir, "init"); err != nil {
4254
return errors.Wrap(err, "git init failed")
4355
}
@@ -111,6 +123,10 @@ type dockerBindWorkspace struct {
111123
// This is also the path that is directly mounted into the docker
112124
// containers.
113125
dir string
126+
// gitMetadata contains the trusted Git control files from before repository
127+
// code runs. The bind-mounted repository can modify its Git metadata, so the
128+
// snapshot must be restored before Git is run on the host.
129+
gitMetadata *gitMetadataSnapshot
114130
}
115131

116132
var _ Workspace = &dockerBindWorkspace{}
@@ -129,6 +145,10 @@ func (w *dockerBindWorkspace) DockerRunOpts(ctx context.Context, target string)
129145
func (w *dockerBindWorkspace) WorkDir() *string { return &w.dir }
130146

131147
func (w *dockerBindWorkspace) Diff(ctx context.Context) ([]byte, error) {
148+
if err := w.gitMetadata.restore(w.dir); err != nil {
149+
return nil, errors.Wrap(err, "restoring trusted git metadata")
150+
}
151+
132152
if _, err := runGitCmd(ctx, w.dir, "add", "--all"); err != nil {
133153
return nil, errors.Wrap(err, "git add failed")
134154
}
@@ -141,10 +161,14 @@ func (w *dockerBindWorkspace) Diff(ctx context.Context) ([]byte, error) {
141161
//
142162
// ATTENTION: When you change the options here, be sure to also update the
143163
// ApplyDiff method accordingly.
144-
return runGitCmd(ctx, w.dir, "diff", "--cached", "--no-prefix", "--binary")
164+
return runGitCmd(ctx, w.dir, "diff", "--cached", "--no-ext-diff", "--no-prefix", "--binary")
145165
}
146166

147167
func (w *dockerBindWorkspace) ApplyDiff(ctx context.Context, diff []byte) error {
168+
if err := w.gitMetadata.restore(w.dir); err != nil {
169+
return errors.Wrap(err, "restoring trusted git metadata")
170+
}
171+
148172
// Write the diff to a temp file so we can pass it to `git apply`
149173
tmp, err := os.CreateTemp(w.tempDir, "bind-workspace-test-*")
150174
if err != nil {
@@ -190,6 +214,15 @@ func unzip(ctx context.Context, zipFile, dest string) error {
190214
}
191215
defer r.Close()
192216

217+
for _, f := range r.File {
218+
// ZIP paths use forward slashes on every platform. Reject backslashes
219+
// rather than letting Windows reinterpret a filename from a Unix
220+
// repository as a directory hierarchy.
221+
if strings.ContainsRune(f.Name, '\\') {
222+
return fmt.Errorf("%q: illegal file path", f.Name)
223+
}
224+
}
225+
193226
outputBase := filepath.Clean(dest) + string(os.PathSeparator)
194227

195228
for _, f := range r.File {
@@ -206,6 +239,15 @@ func unzip(ctx context.Context, zipFile, dest string) error {
206239
return fmt.Errorf("%s: illegal file path", fpath)
207240
}
208241

242+
relativePath, err := filepath.Rel(dest, fpath)
243+
if err != nil {
244+
return err
245+
}
246+
firstPathElement, _, _ := strings.Cut(relativePath, string(os.PathSeparator))
247+
if strings.EqualFold(firstPathElement, ".git") {
248+
return fmt.Errorf("%s: repository archive contains Git metadata", f.Name)
249+
}
250+
209251
if f.FileInfo().IsDir() {
210252
if err := mkdirAll(dest, f.Name, 0777); err != nil {
211253
return err

0 commit comments

Comments
 (0)