Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

gitserver: use cat-file for reading blobs containing ..#52605

Merged
keegancsmith merged 3 commits into
mainfrom
k/git-cat-file
May 31, 2023
Merged

gitserver: use cat-file for reading blobs containing ..#52605
keegancsmith merged 3 commits into
mainfrom
k/git-cat-file

Conversation

@keegancsmith

@keegancsmith keegancsmith commented May 30, 2023

Copy link
Copy Markdown
Member

We special case ".." in path to running a less efficient two commands. For other paths we can rely on the faster git show.

git show will try and resolve revisions on anything containing "..". Depending on what branches/files exist, this can lead to:

  • error: object $SHA is a tree, not a commit
  • fatal: Invalid symmetric difference expression $SHA:$name
  • outputting a diff instead of the file

The last point is a security issue for repositories with sub-repo permissions since the diff will not be filtered.

Test Plan: wrote tests and test e2e

@cla-bot cla-bot Bot added the cla-signed label May 30, 2023
@keegancsmith keegancsmith changed the title gitserver: use cat-file for reading blobs gitserver: use cat-file for reading blobs containing .. May 31, 2023
We special case ".." in path to running a less efficient two commands.
For other paths we can rely on the faster git show.

git show will try and resolve revisions on anything containing "..".
Depending on what branches/files exist, this can lead to:

- error: object $SHA is a tree, not a commit
- fatal: Invalid symmetric difference expression $SHA:$name
- outputting a diff instead of the file

The last point is a security issue for repositories with sub-repo
permissions since the diff will not be filtered.

Test Plan: wrote tests and test e2e
@keegancsmith keegancsmith requested review from a team, jac and mrnugget May 31, 2023 08:50
@keegancsmith keegancsmith marked this pull request as ready for review May 31, 2023 08:50
@keegancsmith

Copy link
Copy Markdown
Member Author

I cleaned up this PR and added tests. I'd like to land this today to backport it to the patch release we are cutting today given this will fix an issue at a customer.

@sourcegraph-bot

sourcegraph-bot commented May 31, 2023

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff abad81b...7aff26a.

Notify File(s)
@indradhanush internal/gitserver/commands.go
internal/gitserver/commands_test.go
@sashaostrikov internal/gitserver/commands.go
internal/gitserver/commands_test.go

@sashaostrikov sashaostrikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for finding and fixing this! 🙏🏻

@keegancsmith keegancsmith enabled auto-merge (squash) May 31, 2023 09:05
@evict evict self-requested a review May 31, 2023 09:07

@kopancek kopancek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:shipit:

@keegancsmith

Copy link
Copy Markdown
Member Author

Running into the test failing on CI but not locally. I am guessing this is a difference between my local git and what is running on CI. After digging into the git history it seems this is actually a bug in git ls-tree that was fixed. https://lore.kernel.org/git/211115.86o86lqe3c.gmgdl@evledraar.gmail.com/

I'll see if I can find a more reliable way to lookup the blob OID of a path.

Believe I am running into a bug in ls-tree for the version of git
running on CI
its possible the version of git on ci doesn't yet support --format
@keegancsmith keegancsmith merged commit 9d52321 into main May 31, 2023
@keegancsmith keegancsmith deleted the k/git-cat-file branch May 31, 2023 09:59
github-actions Bot pushed a commit that referenced this pull request May 31, 2023
We special case ".." in path to running a less efficient two commands.
For other paths we can rely on the faster git show.

git show will try and resolve revisions on anything containing "..".
Depending on what branches/files exist, this can lead to:

- error: object $SHA is a tree, not a commit
- fatal: Invalid symmetric difference expression $SHA:$name
- outputting a diff instead of the file

The last point is a security issue for repositories with sub-repo
permissions since the diff will not be filtered.

Test Plan: wrote tests and test e2e

(cherry picked from commit 9d52321)
keegancsmith added a commit that referenced this pull request May 31, 2023
#52688)

We special case ".." in path to running a less efficient two
commands. For other paths we can rely on the faster git show.

git show will try and resolve revisions on anything containing
"..". Depending on what branches/files exist, this can lead
to:

- error: object $SHA is a tree, not a commit
- fatal: Invalid symmetric difference expression $SHA:$name
- outputting a diff instead of the file

The last point is a security issue for repositories with sub-repo
permissions since the diff will not be filtered.

Test Plan: wrote tests and test e2e
 
Backport 9d52321 from #52605

Co-authored-by: Keegan Carruthers-Smith <keegan.csmith@gmail.com>
ErikaRS pushed a commit that referenced this pull request Jun 22, 2023
We special case ".." in path to running a less efficient two commands.
For other paths we can rely on the faster git show.

git show will try and resolve revisions on anything containing "..".
Depending on what branches/files exist, this can lead to:

- error: object $SHA is a tree, not a commit
- fatal: Invalid symmetric difference expression $SHA:$name
- outputting a diff instead of the file

The last point is a security issue for repositories with sub-repo
permissions since the diff will not be filtered.

Test Plan: wrote tests and test e2e
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants