Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

fix(trueforge): keep OIDC exchange failures out of the error redirect (#687)

Animesh Kumara638cfc3c763
diff --git a/.changeset/generic-oidc-exchange-failure.md b/.changeset/generic-oidc-exchange-failure.md
new file mode 100644
index 000000000..b1d962ea8
--- /dev/null
+++ b/.changeset/generic-oidc-exchange-failure.md
@@ -0,0 +1,5 @@
+---
+'@truefoundry/trueforge': patch
+---
+
+Stop reflecting the raw token-exchange error into the OIDC failure redirect. The message carried upstream endpoint and issuer detail into the browser's address bar; failures now use the same generic `login_failed` reason as the other callback paths, with full detail kept in the server log.
diff --git a/packages/trueforge/src/apis/auth.ts b/packages/trueforge/src/apis/auth.ts
index 371ee5a60..8998bfc49 100644
--- a/packages/trueforge/src/apis/auth.ts
+++ b/packages/trueforge/src/apis/auth.ts
@@ -122,8 +122,9 @@ export function createAuthRouter(params: {
if (soft) {
return soft;
}
- const reason = error instanceof Error ? error.message : 'login_failed';
- return c.redirect(oauthErrorRedirect(reason), 302);
+ // openid-client embeds token-endpoint responses and issuer hosts in the message, so it
+ // stays in the log above rather than a redirect the browser keeps in history.
+ return c.redirect(oauthErrorRedirect('login_failed'), 302);
}
});
diff --git a/packages/trueforge/tests/unit/apis/auth.test.ts b/packages/trueforge/tests/unit/apis/auth.test.ts
index 6063d5b21..ca88e0420 100644
--- a/packages/trueforge/tests/unit/apis/auth.test.ts
+++ b/packages/trueforge/tests/unit/apis/auth.test.ts
@@ -437,6 +437,40 @@ describe('auth router (auth enabled)', () => {
expect(res.headers.get('location')).toBe('/');
});
+ it('GET /callback does not reflect the exchange error message into the redirect', async () => {
+ // openid-client throws with the token-endpoint response embedded in the message, which
+ // carries the issuer host and upstream error body. None of that may reach the browser's
+ // address bar, where it lands in history, screenshots and support tickets.
+ const router = createTestAuthRouter({ oidcClient });
+ const loginRes = await router.request('/login?return_to=/', { redirect: 'manual' });
+ const stateCookieRaw = cookieValue(setCookies(loginRes), STATE_COOKIE) ?? '';
+ const authorizationUrl = new URL(loginRes.headers.get('location') ?? '');
+ const state = authorizationUrl.searchParams.get('state') ?? '';
+
+ const fetchStub = globalThis.fetch;
+ const failingFetch: typeof fetch = async (input, init) => {
+ if (String(input) === `${ISSUER}/token` && init?.method === 'POST') {
+ return new Response(
+ JSON.stringify({ error: 'invalid_grant', error_description: 'code expired at issuer.example.com' }),
+ { status: 400, headers: { 'content-type': 'application/json' } },
+ );
+ }
+ return fetchStub(input, init);
+ };
+ globalThis.fetch = failingFetch;
+
+ const res = await router.request(`/callback?code=invalid&state=${state}&iss=${encodeURIComponent(ISSUER)}`, {
+ redirect: 'manual',
+ headers: { Cookie: `${STATE_COOKIE}=${stateCookieRaw}` },
+ });
+
+ expect(res.status).toBe(302);
+ const location = res.headers.get('location') ?? '';
+ expect(location).toBe('/?error=login_failed');
+ expect(location).not.toContain(new URL(ISSUER).host);
+ expect(location).not.toContain('invalid_grant');
+ });
+
it('GET /callback keeps login_failed when exchange fails and the leftover cookie is blocked', async () => {
const restrictedClient = await initOidc({
...configuredOidc,