{"record":{"id":"a862a3d7900779e0","repo":"goharbor/harbor","slug":"unauthorized-a862a3","errorCode":"UNAUTHORIZED","errorMessage":"unauthorized","messagePattern":"unauthorized","errorType":"http","errorClass":"*errors.Error","httpStatus":401,"severity":"error","filePath":"src/server/middleware/v2auth/auth.go","lineNumber":57,"sourceCode":"\tauthHeader = \"Authorization\"\n)\n\ntype reqChecker struct {\n\tctl project.Controller\n}\n\nfunc (rc *reqChecker) check(req *http.Request) (string, error) {\n\tsecurityCtx, ok := security.FromContext(req.Context())\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"the security context got from request is nil\")\n\t}\n\tal := accessList(req)\n\tif len(al) == 0 {\n\t\treturn \"\", fmt.Errorf(\"un-recognized request: %s %s\", req.Method, req.URL.Path)\n\t}\n\tfor _, a := range al {\n\t\tif a.target == login && !securityCtx.IsAuthenticated() {\n\t\t\treturn getChallenge(req, al), errors.New(\"unauthorized\")\n\t\t}\n\t\tif a.target == catalog {\n\t\t\tresource := system.NewNamespace().Resource(rbac.ResourceCatalog)\n\t\t\tif !securityCtx.Can(req.Context(), rbac.ActionRead, resource) {\n\t\t\t\treturn getChallenge(req, al), fmt.Errorf(\"unauthorized to list catalog\")\n\t\t\t}\n\t\t}\n\t\tif a.target == repository && req.Header.Get(authHeader) == \"\" &&\n\t\t\t(req.Method == http.MethodHead || req.Method == http.MethodGet) { // make sure 401 is returned for CLI HEAD, see #11271\n\t\t\treturn getChallenge(req, al), fmt.Errorf(\"authorize header needed to send HEAD to repository\")\n\t\t} else if a.target == repository {\n\t\t\tpn := strings.Split(a.name, \"/\")[0]\n\t\t\tpid, err := rc.projectID(req.Context(), pn)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t\tresource := rbac_project.NewNamespace(pid).Resource(rbac.ResourceRepository)\n\t\t\tif !securityCtx.Can(req.Context(), a.action, resource) {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/goharbor/harbor/blob/7b2fd08cc568955cca339afeefab27372840d936/src/server/middleware/v2auth/auth.go#L39-L75","documentation":"Error \"unauthorized\" thrown in goharbor/harbor.","triggerScenarios":"Thrown at src/server/middleware/v2auth/auth.go:57 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7b2fd08cc568955cca339afeefab27372840d936","analyzedAt":"2026-08-16T00:00:10.961Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}