Repository navigation
Make the header the session JWT is read from configurable #14752
apiloqbc
started this conversation in
Feature Requests & Suggestions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
LibreChat reads its session JWT from
Authorization, hardcoded inapi/strategies/jwtStrategy.js:That's fine until something in front of LibreChat writes the same header. I run it behind an authenticating proxy that puts the provider's token into
Authorizationon the request it forwards upstream — in my case a service mesh filter, and oauth2-proxy does the same thing with--set-authorization-header=true. Once that's on, the strategy never receives the token LibreChat issued; it gets the proxy's RS256 token and returns401 {"message":"invalid algorithm"}.It's a deployment configuration that isn't supported today rather than a defect — LibreChat is doing exactly what it says it does. But there's no way to work around it from the outside, because the header is replaced before the request reaches node, so the only options are patching the source or not using that proxy configuration.
Two things made it slow to diagnose, in case anyone lands here from a search: it also fires on requests where the browser sent no
Authorizationat all, since the header is created upstream and the logs then look like a client problem. And #14311 reported the same error string from a different angle — that one was closed correctly, thealgorithmsfix proposed there is a no-op, but the explanation given in the thread (the error comes from the HS256jwtfallback) is what happens here too.What I'd like to add
An optional
JWT_AUTH_HEADERnaming a header to try beforeAuthorization, unset by default:The operator's proxy preserves the client's token in that header; it's expected raw, without a
Bearerprefix, sincefromHeaderdoesn't strip one.Affected areas:
api/strategies/jwtStrategy.jsonly, plus a commented-out line in.env.exampleand three cases appended to the existingapi/strategies/jwtStrategy.spec.js. Unset — the default — the rendered behaviour is the same single extractor as today.openIdJwtStrategyhas the identical line and I'd leave it alone: it verifies an IdP token via JWKS and an audience check, and the standard header is exactly where a proxy like this puts an IdP token.No new trust is involved. Whatever is in the header still has to be a JWT signed with
JWT_SECRET, so setting it without the secret gets you nothing.Not the same as #1856 / #8562
Those ask LibreChat to trust an identity asserted by the proxy (
Remote-User,X-Forwarded-User), which is a much bigger decision and deserves its own discussion. Here the token stays LibreChat's own and stays verified the same way — only where it's read from becomes configurable. The two would compose fine if both landed.Status
I've opened #14753 with this. 10 suites / 291 tests pass on the branch, against 288 on an unmodified
main, so the difference is exactly the three tests added there. Happy to change the shape of it — a config key instead of an env var, a different name, whatever fits better — or to close it if you'd rather not carry the option at all.All reactions