{"record":{"id":"25d49a03c5278ea0","repo":"JuliusBrussee/caveman","slug":"githubapp-repository-proof-size-mismatch","errorCode":null,"errorMessage":"githubapp: repository proof size mismatch","messagePattern":"githubapp: repository proof size mismatch","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":335,"sourceCode":"\t}\n\tvar payload struct {\n\t\tType     string `json:\"type\"`\n\t\tEncoding string `json:\"encoding\"`\n\t\tContent  string `json:\"content\"`\n\t\tSize     int64  `json:\"size\"`\n\t}\n\tif err := json.Unmarshal(raw, &payload); err != nil {\n\t\treturn nil, fmt.Errorf(\"githubapp: decode repository proof: %w\", err)\n\t}\n\tif payload.Type != \"file\" || payload.Encoding != \"base64\" || payload.Size < 0 || payload.Size > 64<<10 {\n\t\treturn nil, fmt.Errorf(\"githubapp: repository proof has invalid type, encoding, or size\")\n\t}\n\tdecoded, err := base64.StdEncoding.DecodeString(strings.ReplaceAll(payload.Content, \"\\n\", \"\"))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"githubapp: decode repository proof content: %w\", err)\n\t}\n\tif len(decoded) > 64<<10 || int64(len(decoded)) != payload.Size {\n\t\treturn nil, fmt.Errorf(\"githubapp: repository proof size mismatch\")\n\t}\n\treturn decoded, nil\n}\n\n// DoToken issues an authenticated GitHub REST call with an installation token and\n// returns the status + raw body for the caller to parse. It is the reusable\n// primitive the worker's PR opener builds the Git Data API flow on, so every\n// GitHub egress goes through the one SSRF-guarded client + fixed base host.\nfunc (a *App) DoToken(ctx context.Context, token, method, path string, body any) (int, []byte, error) {\n\treturn a.do(ctx, \"Bearer \"+token, method, path, body)\n}\n\nfunc (a *App) do(ctx context.Context, authorization, method, path string, body any) (int, []byte, error) {\n\tif !strings.HasPrefix(path, \"/\") || strings.HasPrefix(path, \"//\") || strings.Contains(path, \"\\\\\") {\n\t\treturn 0, nil, fmt.Errorf(\"githubapp: request path must be a single-host absolute path\")\n\t}\n\tbase, err := url.Parse(a.baseURL)\n\tif err != nil || base.Scheme == \"\" || base.Host == \"\" || base.User != nil {","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L317-L353","documentation":"After successfully base64-decoding the file content, GetFileContent cross-checks the decoded byte length against the Size field GitHub reported and enforces the library's hard 64 KiB ceiling for connection-proof files. This error means the decoded length exceeded 64 KiB or disagreed with the payload's declared size, indicating a truncated, tampered, or oversized response.","triggerScenarios":"Calling GetFileContent on a file whose decoded bytes are larger than 64<<10, or where io truncation/proxy rewriting caused len(decoded) != payload.Size (e.g. the JSON body was cut off or the Size field was fabricated by a stub).","commonSituations":"Pointing the proof path at a large file (log, binary, bundled asset) instead of a tiny text proof file; a caching proxy returning a stale body with mismatched metadata; test doubles hand-crafting Size values that don't match the encoded content.","solutions":["Check the actual file size at the requested path/ref; use a file under 64 KiB or a dedicated small proof file.","Compare payload.Size with the real Git blob size via the Git Data API to detect truncation or proxy tampering.","If you legitimately need larger files, bypass GetFileContent and use DoToken with a raw-archive or blob endpoint plus your own size handling.","Fix test stubs so Size matches len(decoded) of the encoded content."],"exampleFix":"// before\n// proof path points at a 1 MiB build log\nerr := app.GetFileContent(ctx, tok, org, repo, \"logs/build.log\", \"\")\n// after\n// use the small dedicated proof file the connection control expects\ncontent, err := app.GetFileContent(ctx, tok, org, repo, \".caveman/proof.txt\", \"\")","handlingStrategy":"validation","validationCode":"info, _, err := app.DoToken(ctx, tok, \"GET\", \"/repos/\"+o+\"/\"+r+\"/contents/\"+p, nil)\nif err != nil { return err }\n// inspect Size from the raw JSON before calling GetFileContent\nvar meta struct{ Size int64 `json:\"size\"` }\n_ = json.Unmarshal(raw, &meta)\nif meta.Size > 64<<10 { return fmt.Errorf(\"file too large for proof: %d\", meta.Size) }","typeGuard":null,"tryCatchPattern":"content, err := app.GetFileContent(ctx, tok, o, r, p, ref)\nif err != nil && strings.Contains(err.Error(), \"size mismatch\") {\n    // fall back to Git blob API or reject the file\n}","preventionTips":["Use a dedicated small proof file (<64 KiB), never arbitrary user-chosen paths.","Verify blob size via the Git Data API when paths are dynamic.","Keep Size fields in test stubs consistent with encoded content."],"tags":["github","size-limit","validation","integrity"],"backgroundTag":"file-size-limit-exceeded","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"}