Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

fix: forward Authorization/IBM credentials headers in server-side fetchFromBackend (#1811)

Edwin Jose03f1c918375b
diff --git a/frontend/lib/fetch-server.ts b/frontend/lib/fetch-server.ts
index e966a15fe..b87057a09 100644
--- a/frontend/lib/fetch-server.ts
+++ b/frontend/lib/fetch-server.ts
@@ -1,4 +1,4 @@
-import { cookies } from "next/headers";
+import { cookies, headers } from "next/headers";
export async function fetchFromBackend(
path: string,
@@ -11,12 +11,35 @@ export async function fetchFromBackend(
: `http://${backendHost}:8000`;
const cookieStore = await cookies();
+ const incoming = await headers();
+
+ // Forward the gateway-injected auth headers, not just the cookie. In RBAC
+ // mode (OPENRAG_RBAC_ENFORCE=true) the backend derives identity/permissions
+ // from the JWT in the Authorization header and ignores the session cookie
+ // (src/dependencies.py). The browser proxy (app/api/[...path]/route.ts)
+ // already forwards these; server components must too, or server-rendered
+ // permission checks (e.g. settings/[tab]/page.tsx) see no permissions and
+ // wrongly redirect. Header names honor the backend's env overrides.
+ const jwtAuthHeader = (
+ process.env.OPENRAG_JWT_AUTH_HEADER || "Authorization"
+ ).toLowerCase();
+ const ibmCredentialsHeader = (
+ process.env.IBM_CREDENTIALS_HEADER || "X-IBM-LH-Credentials"
+ ).toLowerCase();
+
+ const forwarded: Record<string, string> = {
+ Cookie: cookieStore.toString(),
+ };
+ const authValue = incoming.get(jwtAuthHeader);
+ if (authValue) forwarded[jwtAuthHeader] = authValue;
+ const credentialsValue = incoming.get(ibmCredentialsHeader);
+ if (credentialsValue) forwarded[ibmCredentialsHeader] = credentialsValue;
return fetch(`${baseUrl}/${path}`, {
...init,
headers: {
+ ...forwarded,
...init?.headers,
- Cookie: cookieStore.toString(),
},
cache: "no-store",
});