Skip to content

Commit fe4b9e2

Browse files
committed
fix(security): restrict GITHUB_API_URL override origins
1 parent 3ae6634 commit fe4b9e2

3 files changed

Lines changed: 16 additions & 13 deletions

File tree

‎dashboard/github-api.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export function githubApiBaseUrl(env: GithubApiEnv = {}): string {
1515
} catch {
1616
throw invalidGithubApiUrl();
1717
}
18-
const isHttps = url.protocol === "https:";
18+
const isDefaultGithubOrigin = configured === DEFAULT_GITHUB_API_URL;
1919
const isLoopbackHttp =
2020
url.protocol === "http:" &&
2121
(url.hostname === "127.0.0.1" || url.hostname === "localhost") &&
2222
Boolean(url.port);
2323
if (
24-
(!isHttps && !isLoopbackHttp) ||
24+
(!isDefaultGithubOrigin && !isLoopbackHttp) ||
2525
url.username ||
2626
url.password ||
2727
url.pathname !== "/" ||
@@ -42,6 +42,6 @@ export function githubApiUrl(env: GithubApiEnv, path: string): string {
4242

4343
function invalidGithubApiUrl(): Error {
4444
return new Error(
45-
"invalid GITHUB_API_URL: expected an https origin or an http://127.0.0.1:<port> / http://localhost:<port> origin",
45+
"invalid GITHUB_API_URL: expected https://api.github.com or an http://127.0.0.1:<port> / http://localhost:<port> origin",
4646
);
4747
}

‎docs/proof/operational-health-zombie-runs/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
The real dashboard Worker excludes queued workflow runs older than 24 hours from queue-pressure health while retaining them in `queued_runs` and surfacing them through `zombie_queued_runs` and `oldest_zombie_queued_minutes`. A non-zombie run queued for 31 minutes still degrades operational health exactly as before.
66

7-
The GitHub base-URL binding is dependency injection for testability. Production behavior is unchanged by default: when `GITHUB_API_URL` is unset, every dashboard GitHub REST and GraphQL request still uses `https://api.github.com`.
7+
The GitHub base-URL binding is dependency injection for testability. Production behavior is unchanged by default: when `GITHUB_API_URL` is unset, every dashboard GitHub REST and GraphQL request still uses `https://api.github.com`. Other HTTPS origins are rejected by design so credentialed requests cannot be redirected away from GitHub; only explicit-port HTTP loopback origins are accepted for local proof stubs.
88

99
## Exercised surface
1010

‎test/dashboard-github-api.test.ts‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import { DEFAULT_GITHUB_API_URL, githubApiBaseUrl, githubApiUrl } from "../dashb
55

66
test("GitHub API URL uses the production origin by default", () => {
77
assert.equal(githubApiBaseUrl({}), DEFAULT_GITHUB_API_URL);
8+
assert.equal(
9+
githubApiBaseUrl({ GITHUB_API_URL: "https://api.github.com" }),
10+
DEFAULT_GITHUB_API_URL,
11+
);
812
assert.equal(githubApiUrl({}, "/graphql"), "https://api.github.com/graphql");
913
});
1014

@@ -15,24 +19,23 @@ test("GitHub API URL honors a validated loopback override", () => {
1519
githubApiUrl(env, "/repos/openclaw/clawsweeper"),
1620
"http://127.0.0.1:8788/repos/openclaw/clawsweeper",
1721
);
22+
assert.equal(
23+
githubApiBaseUrl({ GITHUB_API_URL: "http://localhost:8788" }),
24+
"http://localhost:8788",
25+
);
1826
});
1927

20-
test("GitHub API URL rejects insecure or non-origin overrides", () => {
28+
test("GitHub API URL rejects non-default remote or non-origin overrides", () => {
2129
for (const value of [
2230
"http://github.example.test",
2331
"http://localhost",
32+
"http://127.0.0.1",
2433
"http://127.0.0.1:8788/api",
2534
"https://api.github.test/v3",
2635
"https://[email protected]",
36+
"https://evil.example",
37+
"https://api.github.com:8443",
2738
]) {
2839
assert.throws(() => githubApiBaseUrl({ GITHUB_API_URL: value }), /invalid GITHUB_API_URL/);
2940
}
30-
assert.equal(
31-
githubApiBaseUrl({ GITHUB_API_URL: "https://api.github.test" }),
32-
"https://api.github.test",
33-
);
34-
assert.equal(
35-
githubApiBaseUrl({ GITHUB_API_URL: "http://localhost:8788" }),
36-
"http://localhost:8788",
37-
);
3841
});

0 commit comments

Comments
 (0)