🪧 fix: Emit the Configured-Footer Answer With the HTML Shell (#15886)

* 🪧 fix: Emit the Configured-Footer Answer With the HTML Shell

The chat surface lays out against whether the deployment configured a footer
(customFooter, privacy policy, terms of service). The client answered that from
localStorage — whatever the last resolved `/api/config` recorded — so the answer
was a guess on a first-ever visit and could be stale for a deployment whose
configuration changed.

The backend already knows when it serves client/dist/index.html, so it says so
there: `injectConfiguredFooterBootstrap` writes `hasConfiguredFooter` into
`window.__LIBRECHAT_CONFIG__` ahead of the app's own scripts, once at boot from
the base app config, and the client reads it on its first render instead of
remembering the last answer. The `configured-footer` storage atom is gone.

Client and server share one predicate (`hasConfiguredFooter` in
librechat-data-provider) so the two cannot disagree, and the shell injection is
generalized (`injectBootstrapConfig`), with the query-devtools flag now going
through it.

* 🧷 fix: Keep Bootstrap Values Literal and State the Shell's Contract

`injectBootstrapConfig` passed its script as a replacement string, so a `$&`,
`$1` or `$'` inside an injected value was expanded by `String.replace` instead
of reaching the client. Both insertion points take a replacement function now,
and the spec reads its values back off the global through an explicit result
type rather than an unchecked dictionary.

The shell answers from the deployment's own configuration, which a per-tenant,
role or user override of `interface.privacyPolicy` or `termsOfService` can
disagree with — `/api/config` resolves the caller's and the client prefers it.
That contract was overstated in three comments ("a deployment-lifetime fact",
"the same one the config will give"); they now say what the answer is and what
resolves the rest. Two scenarios cover the disagreement end to end: a document
served without the answer, and a policy link only this caller's config carries.
This commit is contained in:
Marco Beretta 2026-09-14 03:53:54 +02:00 • committed by GitHub
parent 91e00bbe6e
commit 8e6e6f062d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 536 additions and 80 deletions

View file

@ -37,6 +37,7 @@ const {
initializeFileStorage,
loadToolApprovalHooks,
maybeInjectQueryDevtoolsBootstrap,
injectConfiguredFooterBootstrap,
preAuthTenantMiddleware,
requestContextMiddleware,
configureServerTimeouts,
@ -551,6 +552,15 @@ if (cluster.isMaster) {
}
}
/* The composer lays out against whether a footer bar sits beneath it, and
`/api/config` answers that only after it has painted. One shell serves
every request, before there is a caller whose overrides could be resolved,
so the answer is the deployment's base configuration, like index.js. */
indexHTML = injectConfiguredFooterBootstrap(indexHTML, {
customFooter: process.env.CUSTOM_FOOTER,
interfaceConfig: baseAppConfig?.interfaceConfig,
});
const cspPolicy = createCspPolicy();
const shellCache = shellCacheHeaders(cspPolicy != null);

View file

@ -43,6 +43,7 @@ const {
setPluginHookSource,
loadToolApprovalHooks,
maybeInjectQueryDevtoolsBootstrap,
injectConfiguredFooterBootstrap,
preAuthTenantMiddleware,
requestContextMiddleware,
registerShutdownTask,
@ -284,6 +285,16 @@ const startServer = async () => {
}
}
/* The composer lays out against whether a footer bar sits beneath it, and
`/api/config` answers that only after it has painted. One shell serves every
request, before there is a caller whose overrides could be resolved, so the
answer is the deployment's base configuration; `/api/config` resolves the
caller's and the client prefers it. */
indexHTML = injectConfiguredFooterBootstrap(indexHTML, {
customFooter: process.env.CUSTOM_FOOTER,
interfaceConfig: appConfig?.interfaceConfig,
});
const cspPolicy = createCspPolicy();
const shellCache = shellCacheHeaders(cspPolicy != null);

View file

@ -280,6 +280,9 @@ describe('Server Configuration', () => {
mongoServer = await MongoMemoryServer.create();
process.env.MONGO_URI = mongoServer.getUri();
process.env.PORT = '0'; // Use a random available port
/* This deployment configures a footer, so the shell it serves has to say so
before any `/api/config` request: the composer lays out against it. */
process.env.CUSTOM_FOOTER = 'Operator policy footer';
/* index.js listens at module scope and exports only the app, so capture the server to close it. */
const listenSpy = jest.spyOn(express.application, 'listen');
app = require('~/server');
@ -294,6 +297,7 @@ describe('Server Configuration', () => {
await promisify(server.close).call(server);
await mongoServer.stop();
await mongoose.disconnect();
delete process.env.CUSTOM_FOOTER;
});
it('should return OK for /health', async () => {
@ -391,6 +395,19 @@ describe('Server Configuration', () => {
expect(directIndexResponse.text).toContain('"enableQueryDevtools":true');
});
it('serves the configured-footer answer with the shell', async () => {
const [fallbackResponse, indexResponse] = await Promise.all([
request(app).get('/this/does/not/exist'),
request(app).get('/index.html'),
]);
for (const response of [fallbackResponse, indexResponse]) {
expect(response.status).toBe(200);
expect(response.text).toContain('window.__LIBRECHAT_CONFIG__');
expect(response.text).toContain('"hasConfiguredFooter":true');
}
});
it('should return 500 for unknown errors via ErrorController', async () => {
// Testing the error handling here on top of unit tests to ensure the middleware is correctly integrated