Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions internal/handlers/git_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,15 @@ func TestGitServerHandler_AuthenticatedAccessToGitHubRepos(t *testing.T) {
req := httptest.NewRequest("GET", fmt.Sprintf("https://github.com/%s", tt.repoNWO), nil)
req, _ = handler.HandleRequest(req, nil)

if tt.expectedCredential != nil {
switch {
case tt.expectedCredential != nil:
assertHasBasicAuth(t, req,
tt.expectedCredential.GetString("username"),
tt.expectedCredential.GetString("password"),
"valid github request")
} else if tt.isAuthenticated {
case tt.isAuthenticated:
assertAuthenticated(t, req, "valid github request")
} else {
default:
assertUnauthenticated(t, req, "valid github request")
}
})
Expand Down
7 changes: 4 additions & 3 deletions internal/handlers/github_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ func TestGitHubAPIHandler_AuthenticatedAccessToGitHubRepos(t *testing.T) {
req := httptest.NewRequest("GET", fmt.Sprintf("https://api.github.com/%s", tt.repoNWO), nil)
req, _ = handler.HandleRequest(req, nil)

if tt.expectedCredential != nil {
switch {
case tt.expectedCredential != nil:
assertHasTokenAuth(t, req, "token", tt.expectedCredential.GetString("password"), "valid api request")
} else if tt.isAuthenticated {
case tt.isAuthenticated:
assertAuthenticated(t, req, "valid github request")
} else {
default:
assertUnauthenticated(t, req, "valid github request")
}
})
Expand Down
7 changes: 4 additions & 3 deletions internal/handlers/nuget_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,14 @@ func extraUrlsFromSourceResponse(body []byte, url string) []string {
var urls []string
bodyString := strings.TrimSpace(string(body))
bodyReader := bytes.NewReader(body)
if strings.HasPrefix(bodyString, "<") {
switch {
case strings.HasPrefix(bodyString, "<"):
// XML v2 API
urls = handleV2Response(bodyReader, url)
} else if strings.HasPrefix(bodyString, "{") {
case strings.HasPrefix(bodyString, "{"):
// JSON v3 API
urls = handleV3Response(bodyReader, url)
} else {
default:
logging.RequestLogf(nil, "unknown API response: %s...", bodyString[:10])
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

bodyString[:10] will panic when the response body is shorter than 10 bytes (including empty/whitespace-only bodies). Guard the slice with a length check (or log the whole string capped safely) before slicing.

Suggested change
logging.RequestLogf(nil, "unknown API response: %s...", bodyString[:10])
preview := bodyString
if len(preview) > 10 {
preview = preview[:10]
}
logging.RequestLogf(nil, "unknown API response: %s...", preview)

Copilot uses AI. Check for mistakes.
}

Expand Down
5 changes: 3 additions & 2 deletions internal/handlers/python_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/dependabot/proxy/internal/oidc"
)

var simpleSuffixRe = regexp.MustCompile(`/\+?simple/?\z`)

// PythonIndexHandler handles requests to Python indexes, adding auth.
type PythonIndexHandler struct {
credentials []pythonIndexCredentials
Expand Down Expand Up @@ -89,8 +91,7 @@ func (h *PythonIndexHandler) HandleRequest(req *http.Request, ctx *goproxy.Proxy

// Fall back to static credentials
for _, cred := range h.credentials {
re, _ := regexp.Compile(`/\+?simple/?\z`)
indexURL := re.ReplaceAllString(cred.indexURL, "/")
indexURL := simpleSuffixRe.ReplaceAllString(cred.indexURL, "/")
if !helpers.UrlMatchesRequest(req, indexURL, true) && !helpers.CheckHost(req, cred.host) {
continue
}
Expand Down
2 changes: 1 addition & 1 deletion internal/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func requestLog(ctx *goproxy.ProxyCtx, message string) {
argv = append([]any{reqId}, argv...)

if cache.WasResponseCached(ctx) {
format = format + " (cached)"
format += " (cached)"
}
}
formatted := fmt.Sprintf(format, argv...)
Expand Down
7 changes: 4 additions & 3 deletions internal/oidc/oidc_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ func CreateOIDCCredential(cred config.Credential) (*OIDCCredential, error) {
domain := cred.GetString("domain")
domainOwner := cred.GetString("domain-owner")

if tenantID != "" && clientID != "" {
switch {
case tenantID != "" && clientID != "":
parameters = &AzureOIDCParameters{
TenantID: tenantID,
ClientID: clientID,
}
} else if jfrogOidcProviderName != "" && feedUrl != "" {
case jfrogOidcProviderName != "" && feedUrl != "":
// jfrog domain is extracted from feed url
jfrogUrlParsed, err := url.Parse(feedUrl)
if err != nil {
Expand All @@ -105,7 +106,7 @@ func CreateOIDCCredential(cred config.Credential) (*OIDCCredential, error) {
Audience: cred.GetString("audience"),
IdentityMappingName: cred.GetString("identity-mapping-name"),
}
} else if awsRegion != "" && accountID != "" && roleName != "" && domain != "" && domainOwner != "" {
case awsRegion != "" && accountID != "" && roleName != "" && domain != "" && domainOwner != "":
audience := cred.GetString("audience")
if audience == "" {
audience = "sts.amazonaws.com" // defaults to this
Expand Down
12 changes: 8 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ func main() {

cfg, err := config.Parse(*configPath)
if err != nil {
log.Fatal(err)
log.Println(err)
return
}

sentry, err := setupSentry()
if err != nil {
log.Fatal(err)
log.Println(err)
return
}
Comment on lines 41 to 51
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

These early returns from main() log the error but exit with status code 0. For a CLI/service this can make startup failures look like success to the caller/supervisor. Consider returning a non-zero exit code (e.g., track an exitCode and defer os.Exit(exitCode) so deferred file.Close() still runs).

This issue also appears on line 92 of the same file.

Copilot uses AI. Check for mistakes.

envSettings := config.ProxyEnvSettings{
Expand Down Expand Up @@ -89,11 +91,13 @@ func main() {

log.Printf("Listening (%s)", *addr)
if err := server.ListenAndServe(); err != http.ErrServerClosed {
log.Fatal(err)
log.Println(err)
return
}

if err := proxy.Close(); err != nil {
log.Fatal(err)
log.Println(err)
return
}
}

Expand Down
Loading