Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(go): stop leaking password hash and access token in user API responses (#20277)

Isabel Wu366b5c3a4237
diff --git a/internal/handler/user.go b/internal/handler/user.go
index ee41e9c3c7..dc010db99d 100644
--- a/internal/handler/user.go
+++ b/internal/handler/user.go
@@ -726,13 +726,6 @@ func (h *UserHandler) ForgotResetPassword(c *gin.Context) {
c.Header("Authorization", authToken)
c.Header("Access-Control-Expose-Headers", "Authorization")
- // GetUserProfile includes the password hash and the live access_token,
- // which must never appear in the reset response body (the token is
- // already in the Authorization header). Mirror the Python contract
- // `user.to_safe_dict(for_self=True)` by stripping those fields before
- // writing. PR #15290 review.
profile := h.userService.GetUserProfile(ctx, user)
- delete(profile, "password")
- delete(profile, "access_token")
common.SuccessWithData(c, profile, "Password reset successful. Logged in.")
}
diff --git a/internal/service/user.go b/internal/service/user.go
index 68233f80ce..646e51a943 100644
--- a/internal/service/user.go
+++ b/internal/service/user.go
@@ -663,12 +663,6 @@ func (s *UserService) GetUserProfile(ctx context.Context, user *entity.User) map
lastLoginTime = user.LastLoginTime.Format("2006-01-02T15:04:05")
}
- // Get access token
- var accessToken string
- if user.AccessToken != nil {
- accessToken = *user.AccessToken
- }
-
// Get avatar
var avatar interface{}
if user.Avatar != nil {
@@ -701,12 +695,6 @@ func (s *UserService) GetUserProfile(ctx context.Context, user *entity.User) map
loginChannel = *user.LoginChannel
}
- // Get password
- var password string
- if user.Password != nil {
- password = *user.Password
- }
-
// Get status
status := "1"
if user.Status != nil {
@@ -719,8 +707,10 @@ func (s *UserService) GetUserProfile(ctx context.Context, user *entity.User) map
isSuperuser = *user.IsSuperuser
}
+ // NOTE: access_token and password (hash) are intentionally omitted. This map
+ // is serialized into user-facing API responses (login/register/oauth/profile);
+ // the auth token is delivered via the Authorization header + cookie, not here.
return map[string]interface{}{
- "access_token": accessToken,
"avatar": avatar,
"color_schema": colorSchema,
"create_date": createDate,
@@ -735,7 +725,6 @@ func (s *UserService) GetUserProfile(ctx context.Context, user *entity.User) map
"last_login_time": lastLoginTime,
"login_channel": loginChannel,
"nickname": user.Nickname,
- "password": password,
"status": status,
"timezone": timezone,
"update_date": updateDate,
diff --git a/internal/service/user_profile_test.go b/internal/service/user_profile_test.go
new file mode 100644
index 0000000000..ed2d1fbbd4
--- /dev/null
+++ b/internal/service/user_profile_test.go
@@ -0,0 +1,52 @@
+//
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+package service
+
+import (
+ "context"
+ "testing"
+
+ "ragflow/internal/entity"
+)
+
+// Regression for #14789: GetUserProfile is serialized into user-facing API
+// responses (login/register/oauth/profile). It must never expose the password
+// hash or the live access token; the token is delivered via the Authorization
+// header + cookie instead.
+func TestGetUserProfileOmitsCredentials(t *testing.T) {
+ token := "live-access-token"
+ pw := "bcrypt$hash$secret"
+ user := &entity.User{
+ ID: "u1",
+ Nickname: "alice",
+ Email: "[email protected]",
+ AccessToken: &token,
+ Password: &pw,
+ }
+
+ profile := NewUserService().GetUserProfile(context.Background(), user)
+
+ if _, ok := profile["access_token"]; ok {
+ t.Errorf("GetUserProfile leaked access_token: %v", profile["access_token"])
+ }
+ if _, ok := profile["password"]; ok {
+ t.Errorf("GetUserProfile leaked password: %v", profile["password"])
+ }
+ if profile["nickname"] != "alice" {
+ t.Errorf("expected nickname preserved, got %v", profile["nickname"])
+ }
+}