diff --git a/api/authenticators/basic.go b/api/authenticators/basic.go index 4480720d51c..cf3bab449b7 100644 --- a/api/authenticators/basic.go +++ b/api/authenticators/basic.go @@ -110,12 +110,15 @@ func (self *BasicAuthenticator) AuthenticateUserHandler( err = CheckOrgAccess(self.config_obj, r, user_record) if err != nil { services.LogAudit(r.Context(), - self.config_obj, user_record.Name, "Unauthorized username", + self.config_obj, user_record.Name, "User Unauthorized for Org", ordereddict.NewDict(). + Set("err", err.Error()). Set("remote", r.RemoteAddr). Set("status", http.StatusUnauthorized)) - http.Error(w, "authorization failed", http.StatusUnauthorized) + // Return status forbidden because we dont want the user + // to reauthenticate + http.Error(w, err.Error(), http.StatusForbidden) return } diff --git a/api/authenticators/orgs.go b/api/authenticators/orgs.go index 0b249e85e40..504e8497ac3 100644 --- a/api/authenticators/orgs.go +++ b/api/authenticators/orgs.go @@ -2,6 +2,7 @@ package authenticators import ( "errors" + "fmt" "net/http" "net/url" @@ -9,6 +10,7 @@ import ( api_proto "www.velocidex.com/golang/velociraptor/api/proto" config_proto "www.velocidex.com/golang/velociraptor/config/proto" "www.velocidex.com/golang/velociraptor/services" + "www.velocidex.com/golang/velociraptor/utils" ) func GetOrgIdFromRequest(r *http.Request) string { @@ -44,7 +46,7 @@ func GetOrgIdFromRequest(r *http.Request) string { // requested. If they do not have access to the org they requested we // switch them to any org in which they have at least read // access. This behaviour ensures that when a user's access is removed -// from an org the GUI immediately switched to the next available org. +// from an org the GUI immediately switches to the next available org. func CheckOrgAccess( config_obj *config_proto.Config, r *http.Request, @@ -56,6 +58,14 @@ func CheckOrgAccess( return nil } + // For the root org or an unknown org we switch to another org, + // otherwise we need to give the user a more specific error that + // they are not authorized for this org. + if !utils.IsRootOrg(org_id) && + !errors.Is(err, services.OrgNotFoundError) { + return err + } + ctx := r.Context() // Does the user already have a preferred org they want to be in? @@ -111,7 +121,8 @@ func _checkOrgAccess(r *http.Request, org_id string, user_record *api_proto.Velo } if !perm || user_record.Locked { - return errors.New("Unauthorized username") + return fmt.Errorf("User %v accessing %v: %w", + user_record.Name, org_id, utils.NoAccessToOrgError) } return nil diff --git a/api/download.go b/api/download.go index a4c1a982524..64f0747eb8a 100644 --- a/api/download.go +++ b/api/download.go @@ -128,8 +128,6 @@ func vfsFileDownloadHandler() http.Handler { org_id = utils.NormalizedOrgId(org_id) - utils.Debug(org_id) - org_manager, err := services.GetOrgManager() if err != nil { returnError(w, 404, err.Error()) diff --git a/api/static.go b/api/static.go index 2efaaa095d8..5abc3338a53 100644 --- a/api/static.go +++ b/api/static.go @@ -93,14 +93,14 @@ func (self *CachedFilesystem) Open(name string) (http.File, error) { // We do not support gz files at all - it is either brotli or // uncompressed. if strings.HasSuffix(name, ".gz") { - return nil, services.NotFoundError + return nil, services.OrgNotFoundError } fd, err := self.FileSystem.Open(name) if err != nil { // If there is not brotli file, it is just not there. if strings.HasSuffix(name, ".br") { - return nil, services.NotFoundError + return nil, services.OrgNotFoundError } // Check if a compressed .br file exists diff --git a/gui/velociraptor/src/components/artifacts/reporting.jsx b/gui/velociraptor/src/components/artifacts/reporting.jsx index ee101f88dfa..2adf763a262 100644 --- a/gui/velociraptor/src/components/artifacts/reporting.jsx +++ b/gui/velociraptor/src/components/artifacts/reporting.jsx @@ -121,9 +121,9 @@ export default class VeloReportViewer extends React.Component { } this.setState(new_state); }).catch((err) => { - let response = err.response && err.response.data; + let response = err.response && (err.response.data || err.response.message); if (response) { - let templ = "