SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix: send 403 on wrong password entry during change password operation (#4733)
Vibhu Pandey994814864cf5
diff --git a/pkg/query-service/app/http_handler.go b/pkg/query-service/app/http_handler.goindex 16b741e572..964850cbf8 100644--- a/pkg/query-service/app/http_handler.go+++ b/pkg/query-service/app/http_handler.go@@ -2363,10 +2363,9 @@ func (aH *APIHandler) changePassword(w http.ResponseWriter, r *http.Request) {return}- if err := auth.ChangePassword(context.Background(), req); err != nil {- if aH.HandleError(w, err, http.StatusInternalServerError) {- return- }+ if apiErr := auth.ChangePassword(context.Background(), req); apiErr != nil {+ RespondError(w, apiErr, nil)+ return}aH.WriteJSON(w, r, map[string]string{"data": "password changed successfully"})diff --git a/pkg/query-service/auth/auth.go b/pkg/query-service/auth/auth.goindex 6b96a6da85..e307f401ab 100644--- a/pkg/query-service/auth/auth.go+++ b/pkg/query-service/auth/auth.go@@ -234,24 +234,23 @@ func ResetPassword(ctx context.Context, req *model.ResetPasswordRequest) error {return nil}-func ChangePassword(ctx context.Context, req *model.ChangePasswordRequest) error {-+func ChangePassword(ctx context.Context, req *model.ChangePasswordRequest) *model.ApiError {user, apiErr := dao.DB().GetUser(ctx, req.UserId)if apiErr != nil {- return errors.Wrap(apiErr.Err, "failed to query user from the DB")+ return apiErr}if user == nil || !passwordMatch(user.Password, req.OldPassword) {- return ErrorInvalidCreds+ return model.ForbiddenError(ErrorInvalidCreds)}hash, err := PasswordHash(req.NewPassword)if err != nil {- return errors.Wrap(err, "Failed to generate password hash")+ return model.InternalError(errors.New("Failed to generate password hash"))}if apiErr := dao.DB().UpdateUserPassword(ctx, hash, user.Id); apiErr != nil {- return apiErr.Err+ return apiErr}return nildiff --git a/pkg/query-service/model/response.go b/pkg/query-service/model/response.goindex a8e09b9d6e..1f3970e0d4 100644--- a/pkg/query-service/model/response.go+++ b/pkg/query-service/model/response.go@@ -112,6 +112,13 @@ func UnavailableError(err error) *ApiError {}}+func ForbiddenError(err error) *ApiError {+ return &ApiError{+ Typ: ErrorForbidden,+ Err: err,+ }+}+func WrapApiError(err *ApiError, msg string) *ApiError {return &ApiError{Typ: err.Type(),