{"record":{"id":"9ddcfc3e9ef73175","repo":"JuliusBrussee/caveman","slug":"invalid-claude-organization-id","errorCode":null,"errorMessage":"invalid Claude organization id","messagePattern":"invalid Claude organization id","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/internal/store/usage_import.go","lineNumber":134,"sourceCode":"\tif err := json.Unmarshal([]byte(raw), &v); err != nil {\n\t\treturn ImportSummary{}, fmt.Errorf(\"parse Claude usage JSON: %w\", err)\n\t}\n\tquotas := quotaEventsFromAny(\"anthropic\", \"claude_usage_link\", \"linked_api\", time.Now().UTC().Format(time.RFC3339), v)\n\tn, err := s.InsertQuotaEvents(quotas)\n\tif err != nil {\n\t\treturn ImportSummary{}, err\n\t}\n\treturn ImportSummary{Source: \"claude\", QuotaImported: n, Basis: \"linked_api\"}, nil\n}\n\nfunc fetchClaudeUsageJSON() ([]byte, error) {\n\tsessionKey := os.Getenv(\"CAVEMAN_CLAUDE_SESSION_KEY\")\n\torgID := os.Getenv(\"CAVEMAN_CLAUDE_ORG_ID\")\n\tif sessionKey == \"\" || orgID == \"\" {\n\t\treturn nil, fmt.Errorf(\"Claude usage refresh needs CAVEMAN_CLAUDE_USAGE_JSON or CAVEMAN_CLAUDE_SESSION_KEY plus CAVEMAN_CLAUDE_ORG_ID\")\n\t}\n\tif strings.Contains(orgID, \"/\") || strings.Contains(orgID, \"..\") {\n\t\treturn nil, fmt.Errorf(\"invalid Claude organization id\")\n\t}\n\treq, err := http.NewRequest(\"GET\", \"https://claude.ai/api/organizations/\"+orgID+\"/usage\", nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treq.Header.Set(\"accept\", \"application/json\")\n\treq.Header.Set(\"cookie\", \"sessionKey=\"+sessionKey)\n\tclient := http.Client{Timeout: 15 * time.Second}\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode < 200 || resp.StatusCode >= 300 {\n\t\treturn nil, fmt.Errorf(\"Claude usage request failed with HTTP %d\", resp.StatusCode)\n\t}\n\treturn io.ReadAll(io.LimitReader(resp.Body, 4<<20))\n}","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/internal/store/usage_import.go#L116-L152","documentation":"After reading CAVEMAN_CLAUDE_ORG_ID, fetchClaudeUsageJSON rejects ids containing '/' or '..' because the org id is interpolated into the URL path https://claude.ai/api/organizations/<orgID>/usage. This is a path-traversal/URL-injection guard ensuring the id is a plain organization identifier.","triggerScenarios":"CAVEMAN_CLAUDE_ORG_ID containing slashes or '..' — e.g. pasting a full claude.ai URL as the org id, or a path-like value that would escape the API path segment.","commonSituations":"Copy-pasting 'https://claude.ai/api/organizations/org-123/usage' into the ORG_ID var instead of just 'org-123'; an id accidentally including a trailing slash or relative segments.","solutions":["Set CAVEMAN_CLAUDE_ORG_ID to the bare id (the URL segment between /organizations/ and /usage)","Strip scheme/host/path if you copied a full URL, keeping only the org id","Reject or trim the value in wrapper scripts before export"],"exampleFix":"// before\nexport CAVEMAN_CLAUDE_ORG_ID=\"https://claude.ai/api/organizations/org-123/usage\"\n// after\nexport CAVEMAN_CLAUDE_ORG_ID=\"org-123\"","handlingStrategy":"validation","validationCode":"org := os.Getenv(\"CAVEMAN_CLAUDE_ORG_ID\")\nif strings.ContainsAny(org, \"/\") || strings.Contains(org, \"..\") {\n\treturn errors.New(\"CAVEMAN_CLAUDE_ORG_ID must be a bare organization id, not a URL\")\n}","typeGuard":"func validOrgID(s string) bool {\n\treturn s != \"\" && !strings.Contains(s, \"/\") && !strings.Contains(s, \"..\")\n}","tryCatchPattern":"if err := runUsage(); err != nil {\n\tif strings.Contains(err.Error(), \"invalid Claude organization id\") {\n\t\t// instruct user to paste only the id segment\n\t}\n}","preventionTips":["Copy only the id segment from the claude.ai URL","Validate org id format before exporting the env var","Sanitize inputs in wrapper scripts"],"tags":["validation","security","usage-import"],"backgroundTag":"path-traversal-blocked","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"}