Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-proxy-device-flow-signin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The bundled proxy no longer rejects device-flow sign-in on direct-route spokes: `POST /api/gh-user-auth/start` and `/poll` (exact paths) are forwarded without the shared token, and mutating requests carrying a `hive_session` cookie reach the Go API, which authenticates the session itself. Neither gets `X-Hive-Internal`; all other unauthenticated mutations still return 401 ([#15872](https://github.com/hivecommons/hive/issues/15872)).
24 changes: 24 additions & 0 deletions src/proxy/api_internal_header.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,30 @@ async function main() {
assert.equal(seen.internal, null);
});

for (const p of ['/api/gh-user-auth/start', '/api/gh-user-auth/poll']) {
await check(`unauthenticated POST ${p} is forwarded WITHOUT X-Hive-Internal`, async () => {
const res = await req('POST', p);
assert.equal(res.status, 200);
assert.equal(JSON.parse(res.body).internal, null);
});
}

await check('POST /api/gh-user-auth/startx is still 401 (exact match, not prefix)', async () => {
const res = await req('POST', '/api/gh-user-auth/startx');
assert.equal(res.status, 401);
});

await check('POST to another unauthenticated route is still 401', async () => {
const res = await req('POST', '/api/gh-user-auth/other');
assert.equal(res.status, 401);
});

await check('POST with a hive_session cookie is forwarded WITHOUT X-Hive-Internal', async () => {
const res = await req('POST', '/api/pause', { Cookie: 'hive_session=abc123' });
assert.equal(res.status, 200);
assert.equal(JSON.parse(res.body).internal, null);
});

await stopProxy(proxy);

// ── hosted mode: no shared token exists at all ──────────────────────────
Expand Down
9 changes: 9 additions & 0 deletions src/proxy/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,10 @@ app.use(async (req, res, next) => {
});

const PUBLIC_POST_PATHS = ['/api/contribute/register', '/api/contribute/reissue-token'];
// Device-flow sign-in runs before the visitor holds any credential. Matched
// EXACTLY (query string aside), never by prefix, so a sibling route is not
// opened by accident. /poll only completes a flow for the holder of its flow_id.
const PUBLIC_EXACT_POST_PATHS = ['/api/gh-user-auth/start', '/api/gh-user-auth/poll'];
app.use((req, res, next) => {
// SECURITY (CWE-306): decide ONCE, for every method, whether this request
// actually presented the shared dashboard token. apiProxy injects the
Expand All @@ -1004,6 +1008,11 @@ app.use((req, res, next) => {
req.hiveTokenVerified = bearerTokenMatches(req.headers.authorization);
if (['POST', 'PUT', 'PATCH', 'DELETE'].includes(req.method)) {
if (PUBLIC_POST_PATHS.some(p => req.url.startsWith(p))) return next();
if (PUBLIC_EXACT_POST_PATHS.includes(req.url.split('?')[0])) return next();
// A hive_session request is authenticated by the Go API itself (it resolves
// the session and re-checks the role). It never gets X-Hive-Internal:
// hiveTokenVerified stays false. The cookie is SameSite=Lax.
if (parseCookies(req.headers.cookie)['hive_session']) return next();
return requireAuth(req, res, next);
}
next();
Expand Down
Loading