{"record":{"id":"b27777588ce17a1d","repo":"JuliusBrussee/caveman","slug":"githubapp-decode-repository-proof-content-w","errorCode":null,"errorMessage":"githubapp: decode repository proof content: %w","messagePattern":"githubapp: decode repository proof content: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/githubapp/githubapp.go","lineNumber":332,"sourceCode":"\t}\n\tif status != http.StatusOK {\n\t\treturn nil, fmt.Errorf(\"githubapp: get repository proof: HTTP %d: %s\", status, snippet(raw))\n\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\")","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/githubapp/githubapp.go#L314-L350","documentation":"GetFileContent fetches a repository file (used for connection proofs) from GitHub's contents API, which returns the content base64-encoded. After stripping newlines GitHub inserts into the base64 blob, the library decodes it with Go's strict StdEncoding. This error wraps any base64 decode failure, meaning the API payload's content field was not valid standard base64.","triggerScenarios":"Calling GetFileContent when the GitHub contents endpoint returns a payload whose Content field fails strict std base64 decoding — e.g. the endpoint returned a JSON error/alternate shape that still passed the type/encoding checks, a proxy mangled the content string, or the response contains URL-safe base64 characters (- and _) instead of standard (+ and /).","commonSituations":"Hitting a GitHub Enterprise Server or proxy that returns a non-canonical encoding; a test stub or recorded fixture with hand-written base64 containing illegal characters or wrong padding; the path pointed at an object whose API response shape differs (e.g. symlinks or submodule metadata variants) while type/encoding fields coincidentally matched.","solutions":["Print the wrapped base64.CorruptInputError offset from the %w chain to find the first illegal byte in the content string.","Verify the request hit the real GitHub API (check baseURL configuration) and that the path targets a regular file, not a symlink/submodule entry.","If a proxy or test fixture is involved, regenerate the fixture with proper standard base64 (e.g. base64.StdEncoding.EncodeToString) including correct padding.","If content may be URL-safe base64, decode defensively: try base64.StdEncoding then base64.RawURLEncoding before failing."],"exampleFix":"// before\ncontent := \"aGVsbG8_g\" // URL-safe char '_' illegal for StdEncoding\ndecoded, err := base64.StdEncoding.DecodeString(content)\n// after\ncontent = strings.ReplaceAll(content, \"\\n\", \"\")\ndecoded, err := base64.StdEncoding.DecodeString(content)\nif err != nil {\n    decoded, err = base64.RawURLEncoding.DecodeString(content)\n}","handlingStrategy":"validation","validationCode":"payload, err := fetchPayload(ctx)\nif err != nil { return err }\ntrimmed := strings.ReplaceAll(payload.Content, \"\\n\", \"\")\nif _, err := base64.StdEncoding.DecodeString(trimmed); err != nil {\n    return fmt.Errorf(\"content is not valid std base64: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if _, err := app.GetFileContent(ctx, tok, o, r, p, ref); err != nil {\n    var corrupt base64.CorruptInputError\n    if errors.As(err, &corrupt) {\n        // handle invalid encoding: re-fetch or log payload shape\n    }\n}","preventionTips":["Always fetch files via the real GitHub API, never hand-written fixtures without round-tripping through base64.StdEncoding.","Target regular files, not symlinks or submodules.","Round-trip test fixtures with Encode/Decode to guarantee validity."],"tags":["github","base64","decoding","api-response"],"backgroundTag":"invalid-argument-format","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"}