Skip to content

Commit 679b006

Browse files
cfsmp3claude
andauthored
security: sanitize error messages to prevent info disclosure (#412)
Replace detailed error messages with generic ones to prevent leaking internal system information to users. Actual errors are logged for debugging. - OAuth errors: "Authentication failed" instead of err.Error() - Session errors: "Session error" instead of err.Error() - JSON decode errors: "Invalid request body" instead of decode error - Logout errors: "Logout failed" instead of err.Error() Note: Validation errors (like "Invalid date format") are kept as they help users understand what needs to be fixed. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 08d3d28 commit 679b006

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

backend/controllers/add_task.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ func AddTaskHandler(w http.ResponseWriter, r *http.Request) {
2727
if r.Method == http.MethodPost {
2828
var requestBody models.AddTaskRequestBody
2929
if err := json.NewDecoder(r.Body).Decode(&requestBody); err != nil {
30-
http.Error(w, fmt.Sprintf("error decoding request body: %v", err), http.StatusBadRequest)
30+
utils.Logger.Warnf("Failed to decode add task request: %v", err)
31+
http.Error(w, "Invalid request body", http.StatusBadRequest)
3132
return
3233
}
3334
defer r.Body.Close()

backend/controllers/app_handlers.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,24 @@ func (a *App) OAuthCallbackHandler(w http.ResponseWriter, r *http.Request) {
9191

9292
t, err := a.Config.Exchange(context.Background(), code)
9393
if err != nil {
94-
http.Error(w, err.Error(), http.StatusBadRequest)
94+
utils.Logger.Errorf("OAuth token exchange failed: %v", err)
95+
http.Error(w, "Authentication failed", http.StatusBadRequest)
9596
return
9697
}
9798

9899
client := a.Config.Client(context.Background(), t)
99100
resp, err := client.Get("https://www.googleapis.com/oauth2/v2/userinfo")
100101
if err != nil {
101-
http.Error(w, err.Error(), http.StatusBadRequest)
102+
utils.Logger.Errorf("Failed to fetch user info from Google: %v", err)
103+
http.Error(w, "Authentication failed", http.StatusBadRequest)
102104
return
103105
}
104106
defer resp.Body.Close()
105107

106108
var userInfo map[string]interface{}
107109
if err := json.NewDecoder(resp.Body).Decode(&userInfo); err != nil {
108-
http.Error(w, err.Error(), http.StatusInternalServerError)
110+
utils.Logger.Errorf("Failed to decode user info: %v", err)
111+
http.Error(w, "Authentication failed", http.StatusInternalServerError)
109112
return
110113
}
111114

@@ -122,7 +125,8 @@ func (a *App) OAuthCallbackHandler(w http.ResponseWriter, r *http.Request) {
122125
userInfo["encryption_secret"] = encryptionSecret
123126
session.Values["user"] = userInfo
124127
if err := session.Save(r, w); err != nil {
125-
http.Error(w, err.Error(), http.StatusInternalServerError)
128+
utils.Logger.Errorf("Failed to save session: %v", err)
129+
http.Error(w, "Session error", http.StatusInternalServerError)
126130
return
127131
}
128132

@@ -179,7 +183,8 @@ func (a *App) LogoutHandler(w http.ResponseWriter, r *http.Request) {
179183
session, _ := a.SessionStore.Get(r, "session-name")
180184
session.Options.MaxAge = -1
181185
if err := session.Save(r, w); err != nil {
182-
http.Error(w, err.Error(), http.StatusInternalServerError)
186+
utils.Logger.Errorf("Failed to clear session on logout: %v", err)
187+
http.Error(w, "Logout failed", http.StatusInternalServerError)
183188
return
184189
}
185190

0 commit comments

Comments
 (0)