Skip to content

Commit a23606b

Browse files
authored
Fix auth vulnerability (#2805)
1 parent 5a9f8f7 commit a23606b

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

github/repos_contents.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,15 @@ func (s *RepositoriesService) DownloadContentsWithMeta(ctx context.Context, owne
192192
// as possible, both result types will be returned but only one will contain a
193193
// value and the other will be nil.
194194
//
195+
// Due to an auth vulnerability issue in the GitHub v3 API, ".." is not allowed
196+
// to appear anywhere in the "path" or this method will return an error.
197+
//
195198
// GitHub API docs: https://docs.github.com/en/rest/repos/contents#get-repository-content
196199
func (s *RepositoriesService) GetContents(ctx context.Context, owner, repo, path string, opts *RepositoryContentGetOptions) (fileContent *RepositoryContent, directoryContent []*RepositoryContent, resp *Response, err error) {
200+
if strings.Contains(path, "..") {
201+
return nil, nil, nil, errors.New("path must not contain '..' due to auth vulnerability issue")
202+
}
203+
197204
escapedPath := (&url.URL{Path: strings.TrimSuffix(path, "/")}).String()
198205
u := fmt.Sprintf("repos/%s/%s/contents/%s", owner, repo, escapedPath)
199206
u, err = addOptions(u, opts)

github/repos_contents_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,20 @@ func TestRepositoriesService_GetContents_DirectoryWithSpaces(t *testing.T) {
465465
}
466466
}
467467

468+
func TestRepositoriesService_GetContents_PathWithParent(t *testing.T) {
469+
client, mux, _, teardown := setup()
470+
defer teardown()
471+
mux.HandleFunc("/repos/o/r/contents/some/../directory/file.go", func(w http.ResponseWriter, r *http.Request) {
472+
testMethod(t, r, "GET")
473+
fmt.Fprint(w, `{}`)
474+
})
475+
ctx := context.Background()
476+
_, _, _, err := client.Repositories.GetContents(ctx, "o", "r", "some/../directory/file.go", &RepositoryContentGetOptions{})
477+
if err == nil {
478+
t.Fatal("Repositories.GetContents expected error but got none")
479+
}
480+
}
481+
468482
func TestRepositoriesService_GetContents_DirectoryWithPlusChars(t *testing.T) {
469483
client, mux, _, teardown := setup()
470484
defer teardown()

0 commit comments

Comments
 (0)