Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: fixed a security issue caused by fake VCS (#834)
Zilong Zhoua578ed58e478
diff --git a/api/auth.go b/api/auth.goindex a62a0982ba..ed8dfefc54 100644--- a/api/auth.go+++ b/api/auth.go@@ -4,6 +4,7 @@ import "github.com/bytebase/bytebase/plugin/vcs"// AuthProvider is the authentication provider which only supports GitLab for now.type AuthProvider struct {+ ID int `jsonapi:"attr,id"`Type vcs.Type `jsonapi:"attr,type"`Name string `jsonapi:"attr,name"`InstanceURL string `jsonapi:"attr,instanceUrl"`@@ -14,10 +15,9 @@ type AuthProvider struct {// GitlabLogin is the API message for logins via Gitlab.type GitlabLogin struct {- InstanceURL string `jsonapi:"attr,instanceUrl"`- ApplicationID string `jsonapi:"attr,applicationId"`- Secret string `jsonapi:"attr,secret"`- AccessToken string `jsonapi:"attr,accessToken"`+ ID int `jsonapi:"attr,id"`+ Name string `jsonapi:"attr,name"`+ AccessToken string `jsonapi:"attr,accessToken"`}// Login is the API message for logins.diff --git a/frontend/src/types/auth.ts b/frontend/src/types/auth.tsindex aeaf28cb8c..d0680156bc 100644--- a/frontend/src/types/auth.ts+++ b/frontend/src/types/auth.ts@@ -1,5 +1,7 @@// Auth+import { VCSId } from "./id";+// For now, a single user's auth provider should either belong to GITLAB_SELF_HOST or BYTEBASEexport type AuthProviderType = "GITLAB_SELF_HOST" | "BYTEBASE";@@ -27,6 +29,7 @@ export type BytebaseLoginInfo = {};export type AuthProvider = {+ id: VCSId;type: AuthProviderType;name: string;instanceUrl: string;@@ -35,6 +38,7 @@ export type AuthProvider = {};export const EmptyAuthProvider: AuthProvider = {+ id: 0,type: "BYTEBASE",name: "",instanceUrl: "",@@ -43,8 +47,7 @@ export const EmptyAuthProvider: AuthProvider = {};export type VCSLoginInfo = {- applicationId: string;- secret: string;- instanceUrl: string;+ id: VCSId;+ name: string;accessToken: string;};diff --git a/frontend/src/views/auth/Signin.vue b/frontend/src/views/auth/Signin.vueindex 738cb4a7b7..5f8ac2e6c5 100644--- a/frontend/src/views/auth/Signin.vue+++ b/frontend/src/views/auth/Signin.vue@@ -236,9 +236,8 @@ export default {}).then((token: OAuthToken) => {const gitlabLoginInfo: VCSLoginInfo = {- applicationId: state.activeAuthProvider!.applicationId,- secret: state.activeAuthProvider.secret,- instanceUrl: state.activeAuthProvider.instanceUrl,+ id: state.activeAuthProvider.id,+ name: state.activeAuthProvider.name,accessToken: token.accessToken,};diff --git a/server/auth.go b/server/auth.goindex 8a6dc4ee60..d8ac8f15bb 100644--- a/server/auth.go+++ b/server/auth.go@@ -8,6 +8,7 @@ import ("github.com/bytebase/bytebase/api""github.com/bytebase/bytebase/common"+ "github.com/bytebase/bytebase/plugin/vcs"vcsPlugin "github.com/bytebase/bytebase/plugin/vcs""github.com/google/jsonapi""github.com/labstack/echo/v4"@@ -28,6 +29,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {var authProviderList []*api.AuthProviderfor _, vcs := range list {newProvider := &api.AuthProvider{+ ID: vcs.ID,Type: vcs.Type,Name: vcs.Name,InstanceURL: vcs.InstanceURL,@@ -81,15 +83,24 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {if err := jsonapi.UnmarshalPayload(c.Request().Body, gitlabLogin); err != nil {return echo.NewHTTPError(http.StatusBadRequest, "Malformatted gitlab login request").SetInternal(err)}- gitlabUserInfo, err := vcsPlugin.Get("GITLAB_SELF_HOST", vcsPlugin.ProviderConfig{Logger: s.l}).TryLogin(ctx,+ findVCS := &api.VCSFind{ID: &gitlabLogin.ID}+ vcsFound, err := s.VCSService.FindVCS(ctx, findVCS)+ if err != nil {+ return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch vcs, name: %v, ID: %v", gitlabLogin.Name, gitlabLogin.Name)).SetInternal(err)+ }+ if vcsFound == nil {+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("vcs do not exist, name: %v, ID: %v", gitlabLogin.Name, gitlabLogin.Name)).SetInternal(err)+ }++ gitlabUserInfo, err := vcsPlugin.Get(vcs.GitLabSelfHost, vcsPlugin.ProviderConfig{Logger: s.l}).TryLogin(ctx,common.OauthContext{- ClientID: gitlabLogin.ApplicationID,- ClientSecret: gitlabLogin.Secret,+ ClientID: vcsFound.ApplicationID,+ ClientSecret: vcsFound.Secret,AccessToken: gitlabLogin.AccessToken,RefreshToken: "",Refresher: nil,},- gitlabLogin.InstanceURL,+ vcsFound.InstanceURL,)if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, "Fail to fetch user info from gitlab").SetInternal(err)