{"record":{"id":"188bcabfd9f664f2","repo":"JuliusBrussee/caveman","slug":"githubapp-permission-q-q-exceeds-the-least-agen","errorCode":null,"errorMessage":"githubapp: permission %q=%q exceeds the least-agency allowlist","messagePattern":"githubapp: permission %q=%q exceeds the least-agency allowlist","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":202,"sourceCode":"// `repos` and `perms`, returning a ~1h token. Defaults (perms nil) are\n// contents:write + pull_requests:write — enough to push a branch and open a draft\n// PR, never to merge.\nfunc (a *App) MintInstallationToken(ctx context.Context, installationID int64, repos []string, perms map[string]string) (InstallationToken, error) {\n\tif installationID <= 0 {\n\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: installation id must be positive\")\n\t}\n\tif len(repos) != 1 || strings.TrimSpace(repos[0]) == \"\" {\n\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: exactly one repository is required\")\n\t}\n\trepository := strings.TrimSpace(repos[0])\n\tif perms == nil {\n\t\tperms = map[string]string{\"contents\": \"write\", \"pull_requests\": \"write\"}\n\t}\n\tallowedPermissions := map[string]bool{\"contents\": true, \"pull_requests\": true}\n\tscopedPermissions := make(map[string]string, len(perms))\n\tfor name, level := range perms {\n\t\tif !allowedPermissions[name] || (level != \"read\" && level != \"write\") {\n\t\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: permission %q=%q exceeds the least-agency allowlist\", name, level)\n\t\t}\n\t\tscopedPermissions[name] = level\n\t}\n\tjwt, err := a.AppJWT()\n\tif err != nil {\n\t\treturn InstallationToken{}, err\n\t}\n\tbody := map[string]any{\"permissions\": scopedPermissions, \"repositories\": []string{repository}}\n\tstatus, raw, err := a.do(ctx, \"Bearer \"+jwt, http.MethodPost,\n\t\t\"/app/installations/\"+strconv.FormatInt(installationID, 10)+\"/access_tokens\", body)\n\tif err != nil {\n\t\treturn InstallationToken{}, err\n\t}\n\tif status != http.StatusCreated {\n\t\treturn InstallationToken{}, fmt.Errorf(\"githubapp: mint token: HTTP %d: %s\", status, snippet(raw))\n\t}\n\tvar out InstallationToken\n\tif err := json.Unmarshal(raw, &out); err != nil {","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L184-L220","documentation":"Token permissions are restricted to an explicit least-agency allowlist: only \"contents\" and \"pull_requests\", each limited to \"read\" or \"write\". Any other permission name or level (e.g. \"administration\", \"workflows\", \"admin\") is rejected before network I/O, so the app can never mint a token that merges code or alters repo settings.","triggerScenarios":"App.MintInstallationToken called with perms containing an unlisted key (e.g. {\"contents\":\"write\",\"workflows\":\"write\"}), an unsupported level (\"admin\", \"none\"), or a mix of valid and invalid entries — one bad entry fails the whole call.","commonSituations":"Copy-pasting permission maps from GitHub's docs that include broader scopes; generic token-minting helpers passing through caller-supplied perms; typos like \"pull-request\" instead of \"pull_requests\".","solutions":["Restrict perms to {\"contents\":\"read\"|\"write\", \"pull_requests\":\"read\"|\"write\"} or pass nil for the defaults (contents:write + pull_requests:write)","Fix key spelling to GitHub's snake_case names within the allowlist","Remove any broader permission (admin, workflows, etc.) — the library will not allow them by design"],"exampleFix":"// before\nperms := map[string]string{\"contents\": \"write\", \"workflows\": \"write\"}\n// after\nperms := map[string]string{\"contents\": \"write\", \"pull_requests\": \"write\"}","handlingStrategy":"validation","validationCode":"var allowedPerms = map[string]bool{\"contents\": true, \"pull_requests\": true}\nfor name, level := range perms {\n\tif !allowedPerms[name] || (level != \"read\" && level != \"write\") {\n\t\treturn fmt.Errorf(\"permission %s=%s not allowed\", name, level)\n\t}\n}","typeGuard":"func permsAllowlisted(perms map[string]string) bool {\n\tfor n, l := range perms {\n\t\tif !(n == \"contents\" || n == \"pull_requests\") || (l != \"read\" && l != \"write\") {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}","tryCatchPattern":"tok, err := app.MintInstallationToken(ctx, id, []string{repo}, perms)\nif err != nil {\n\tif strings.Contains(err.Error(), \"least-agency allowlist\") {\n\t\t// drop the offending permission or pass nil for defaults\n\t}\n\treturn err\n}","preventionTips":["Pass nil perms to get the safe defaults (contents:write + pull_requests:write)","Centralize permission constants instead of inline maps","Never request admin/workflows/repo-level broad permissions — the allowlist forbids them by design"],"tags":["github-app","permissions","least-privilege"],"backgroundTag":"unsupported-enum-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}