Skip to content

Commit e990bd7

Browse files
authored
Merge pull request #16 from bbrowning/narrow-github-pat
Narrow GitHub PAT injection to api.github.com only
2 parents 2b868f8 + 668b607 commit e990bd7

3 files changed

Lines changed: 17 additions & 13 deletions

File tree

CLAUDE.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ The default credential routing is defined in `internal/credentials/credentials.j
9393
| `*.anthropic.com` | `x-api-key: <key>` | `ANTHROPIC_API_KEY` |
9494
| `*.openai.com` | `Authorization: Bearer <key>` | `OPENAI_API_KEY` |
9595
| `*.cursor.com`, `*.cursorapi.com` | `Authorization: Bearer <key>` | `CURSOR_API_KEY` |
96-
| `github.com`, `api.github.com` | `Authorization: Bearer <pat>` | `GH_TOKEN` |
97-
| `*.githubusercontent.com` | `Authorization: Bearer <pat>` | `GH_TOKEN` |
96+
| `api.github.com` | `Authorization: Bearer <pat>` | `GH_TOKEN` |
9897
| `*.googleapis.com` | `Authorization: Bearer <token>` | gcloud ADC (auto-refresh) |
9998

10099
## Client Compatibility

internal/credentials/config_test.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,35 +232,40 @@ func TestBuildFromConfig_GitHubBearer(t *testing.T) {
232232
{
233233
EnvVar: "TEST_GH_TOKEN",
234234
InjectorType: "bearer",
235-
Domains: []string{"github.com", "api.github.com", ".githubusercontent.com"},
235+
Domains: []string{"api.github.com"},
236236
},
237237
},
238238
}
239239

240240
store, _, _ := BuildFromConfig(cfg)
241241

242-
// Test exact domain match
243242
req := &http.Request{
244-
URL: &url.URL{Host: "github.com"},
243+
URL: &url.URL{Host: "api.github.com"},
245244
Header: make(http.Header),
246245
}
247246
if matched, injected := store.InjectCredentials(req); !matched || !injected {
248-
t.Error("should match github.com")
247+
t.Error("should match api.github.com")
249248
}
250249
if got := req.Header.Get("Authorization"); got != "Bearer ghp_test" {
251250
t.Errorf("Authorization = %q, want %q", got, "Bearer ghp_test")
252251
}
253252

254-
// Test suffix domain match
253+
// github.com should NOT match (no PAT for git clone of public repos)
255254
req2 := &http.Request{
256-
URL: &url.URL{Host: "raw.githubusercontent.com"},
255+
URL: &url.URL{Host: "github.com"},
257256
Header: make(http.Header),
258257
}
259-
if matched, injected := store.InjectCredentials(req2); !matched || !injected {
260-
t.Error("should match raw.githubusercontent.com")
258+
if matched, _ := store.InjectCredentials(req2); matched {
259+
t.Error("should not match github.com")
261260
}
262-
if got := req2.Header.Get("Authorization"); got != "Bearer ghp_test" {
263-
t.Errorf("Authorization = %q, want %q", got, "Bearer ghp_test")
261+
262+
// raw.githubusercontent.com should NOT match
263+
req3 := &http.Request{
264+
URL: &url.URL{Host: "raw.githubusercontent.com"},
265+
Header: make(http.Header),
266+
}
267+
if matched, _ := store.InjectCredentials(req3); matched {
268+
t.Error("should not match raw.githubusercontent.com")
264269
}
265270
}
266271

internal/credentials/credentials.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
{
2222
"env_var": "GH_TOKEN",
2323
"injector": "bearer",
24-
"domains": ["github.com", "api.github.com", ".githubusercontent.com"]
24+
"domains": ["api.github.com"]
2525
},
2626
{
2727
"env_var": "GOOGLE_APPLICATION_CREDENTIALS",

0 commit comments

Comments
 (0)