{"record":{"id":"453b0567d4141f0d","repo":"JuliusBrussee/caveman","slug":"githubapp-installation-response-identity-mismatch","errorCode":null,"errorMessage":"githubapp: installation response identity mismatch","messagePattern":"githubapp: installation response identity mismatch","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":178,"sourceCode":"\t\treturn out, fmt.Errorf(\"githubapp: installation id must be positive\")\n\t}\n\tjwt, err := a.AppJWT()\n\tif err != nil {\n\t\treturn out, err\n\t}\n\tstatus, raw, err := a.do(ctx, \"Bearer \"+jwt, http.MethodGet,\n\t\t\"/app/installations/\"+strconv.FormatInt(installationID, 10), nil)\n\tif err != nil {\n\t\treturn out, err\n\t}\n\tif status != http.StatusOK {\n\t\treturn out, fmt.Errorf(\"githubapp: get installation: HTTP %d: %s\", status, snippet(raw))\n\t}\n\tif err := json.Unmarshal(raw, &out); err != nil {\n\t\treturn out, fmt.Errorf(\"githubapp: decode installation: %w\", err)\n\t}\n\tif out.ID != installationID || out.Account.ID <= 0 || strings.TrimSpace(out.Account.Login) == \"\" {\n\t\treturn Installation{}, fmt.Errorf(\"githubapp: installation response identity mismatch\")\n\t}\n\treturn out, nil\n}\n\n// MintInstallationToken POSTs /app/installations/{id}/access_tokens narrowed to\n// `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\"}","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L160-L196","documentation":"After decoding a 200 response, the library verifies the installation is self-consistent: the returned ID equals the requested ID, the account ID is positive, and the account login is non-empty. Any mismatch means the response cannot be trusted to identify the installation, so it fails closed. This guards against confused-deputy bugs where a different installation's data is used.","triggerScenarios":"App.GetInstallation when GitHub (or a mock) returns an installation whose ID differs from the requested one, or whose account object lacks an ID/login — e.g. stale cached payload, wrong fixture, or a changed response schema.","commonSituations":"Test doubles returning minimal fixtures without account fields; intermittent proxies serving stale responses; schema drift from GitHub API previews.","solutions":["Compare the requested ID to the returned ID in the error context; request the correct installation ID","Fix test fixtures to include a full account object (id > 0, non-empty login)","If GitHub changed the payload shape, update the library / file an issue"],"exampleFix":"// before\n// test fixture missing account\n{\"id\": 12345}\n// after\n{\"id\": 12345, \"account\": {\"id\": 987, \"login\": \"my-org\"}}","handlingStrategy":"try-catch","validationCode":"// Pre-call: confirm you are passing the intended installation ID, not a stale cached one","typeGuard":null,"tryCatchPattern":"inst, err := app.GetInstallation(ctx, wantID)\nif err != nil {\n\tif strings.Contains(err.Error(), \"identity mismatch\") {\n\t\t// refresh installation listing; do not proceed with mismatched identity\n\t}\n\treturn err\n}","preventionTips":["Never reuse cached installation payloads across reinstalls","Include full account objects (id, login) in test fixtures","Fail closed on any identity inconsistency rather than proceeding"],"tags":["github-app","validation","fail-closed"],"backgroundTag":"unexpected-response-shape","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"}