Skip to content

Commit 9493618

Browse files
authored
Fix: Disable integration credential validation and add nil checks (#579)
## Summary This PR addresses potential issues with integration credential validation by: 1. **Disabling active validation** for GitHub PAT, Google, and GitLab credentials in the status endpoint 2. **Adding nil pointer checks** in git package initialization ## Changes ### Integration Status (integrations_status.go) - Removed active token validation for GitHub PAT, Google OAuth, and GitLab tokens - Status endpoint now assumes stored credentials are valid - Added clear comments explaining that integrations will fail gracefully if credentials are invalid ### Git Package Initialization (main.go) - Added nil checks for GitHub installation, GitHub PAT credentials, and GitLab credentials - Prevents potential nil pointer dereferences when these functions return nil ## Rationale Active validation of credentials on every status check can cause: - Unnecessary API calls to external services - Potential rate limiting issues - False negatives due to temporary network issues Since the backend auto-refreshes tokens and integrations fail gracefully on actual usage, checking for credential existence is sufficient for the status endpoint. ## Testing - [ ] Backend builds successfully - [ ] Integration status endpoints return expected data - [ ] No nil pointer dereferences occur during git operations
1 parent 51f4297 commit 9493618

2 files changed

Lines changed: 24 additions & 17 deletions

File tree

components/backend/handlers/integrations_status.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package handlers
33
import (
44
"context"
55
"net/http"
6-
"time"
76

87
"github.com/gin-gonic/gin"
98
)
@@ -63,13 +62,13 @@ func getGitHubStatusForUser(ctx context.Context, userID string) gin.H {
6362
// Check GitHub PAT
6463
patCreds, err := GetGitHubPATCredentials(ctx, userID)
6564
if err == nil && patCreds != nil {
66-
// Validate PAT token
67-
valid, _ := ValidateGitHubToken(ctx, patCreds.Token)
65+
// NOTE: Validation disabled - if credentials are stored, assume they're valid
66+
// The integration will fail gracefully if credentials are actually invalid
6867

6968
status["pat"] = gin.H{
7069
"configured": true,
7170
"updatedAt": patCreds.UpdatedAt.Format("2006-01-02T15:04:05Z07:00"),
72-
"valid": valid,
71+
"valid": true,
7372
}
7473
}
7574

@@ -89,19 +88,15 @@ func getGoogleStatusForUser(ctx context.Context, userID string) gin.H {
8988
return gin.H{"connected": false}
9089
}
9190

92-
// Check if token is expired
93-
isExpired := time.Now().After(creds.ExpiresAt)
94-
valid := !isExpired
95-
96-
// If near expiry, could validate with Google API, but checking expiry is sufficient
97-
// since backend auto-refreshes tokens
91+
// NOTE: Validation disabled - if credentials are stored, assume they're valid
92+
// The backend auto-refreshes tokens and the integration will fail gracefully if invalid
9893

9994
return gin.H{
10095
"connected": true,
10196
"email": creds.Email,
10297
"expiresAt": creds.ExpiresAt.Format("2006-01-02T15:04:05Z07:00"),
10398
"updatedAt": creds.UpdatedAt.Format("2006-01-02T15:04:05Z07:00"),
104-
"valid": valid,
99+
"valid": true,
105100
}
106101
}
107102

@@ -131,13 +126,13 @@ func getGitLabStatusForUser(ctx context.Context, userID string) gin.H {
131126
return gin.H{"connected": false}
132127
}
133128

134-
// Validate token
135-
valid, _ := ValidateGitLabToken(ctx, creds.Token, creds.InstanceURL)
129+
// NOTE: Validation disabled - if credentials are stored, assume they're valid
130+
// The integration will fail gracefully if credentials are actually invalid
136131

137132
return gin.H{
138133
"connected": true,
139134
"instanceUrl": creds.InstanceURL,
140135
"updatedAt": creds.UpdatedAt,
141-
"valid": valid,
136+
"valid": true,
142137
}
143138
}

components/backend/main.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,25 @@ func main() {
9494
// Initialize git package
9595
git.GetProjectSettingsResource = k8s.GetProjectSettingsResource
9696
git.GetGitHubInstallation = func(ctx context.Context, userID string) (interface{}, error) {
97-
return github.GetInstallation(ctx, userID)
97+
installation, err := github.GetInstallation(ctx, userID)
98+
if installation == nil {
99+
return nil, err
100+
}
101+
return installation, err
98102
}
99103
git.GetGitHubPATCredentials = func(ctx context.Context, userID string) (interface{}, error) {
100-
return handlers.GetGitHubPATCredentials(ctx, userID)
104+
creds, err := handlers.GetGitHubPATCredentials(ctx, userID)
105+
if creds == nil {
106+
return nil, err
107+
}
108+
return creds, err
101109
}
102110
git.GetGitLabCredentials = func(ctx context.Context, userID string) (interface{}, error) {
103-
return handlers.GetGitLabCredentials(ctx, userID)
111+
creds, err := handlers.GetGitLabCredentials(ctx, userID)
112+
if creds == nil {
113+
return nil, err
114+
}
115+
return creds, err
104116
}
105117
git.GitHubTokenManager = github.Manager
106118
git.GetBackendNamespace = func() string {

0 commit comments

Comments
 (0)