fix: defer logger serialization to sanitized transports (#17169)
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run

This commit is contained in:
Dustin Healy 2026-10-15 11:40:18 -07:00 • committed by GitHub
parent d4e52acdfb
commit e01b570779
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 0 deletions

View file

@ -0,0 +1,50 @@
import type winston from 'winston';
/** Check the real logger configuration: transport-only formatter tests miss
* Winston's implicit JSON serialization before any transport receives a record. */
describe('logger serialization boundary', () => {
let logger: winston.Logger;
const originalLogToFile = process.env.LOG_TO_FILE;
beforeAll(() => {
process.env.LOG_TO_FILE = 'false';
jest.isolateModules(() => {
logger = jest.requireActual<typeof import('./winston')>('./winston').default;
});
});
afterAll(() => {
logger.close();
if (originalLogToFile === undefined) {
delete process.env.LOG_TO_FILE;
} else {
process.env.LOG_TO_FILE = originalLogToFile;
}
});
it('does not serialize a raw HTTP agent graph before transport sanitization', () => {
const serializeAgent = jest.fn(() => ({ sockets: 'raw socket graph' }));
const error = Object.assign(new Error('Request failed with status code 403'), {
isAxiosError: true,
config: {
method: 'delete',
url: 'https://example.test/files/1',
httpAgent: { toJSON: serializeAgent },
},
});
// Winston merges enumerable error metadata into the top-level info before
// running the logger-level format, including config and request objects.
const info: winston.Logform.TransformableInfo = {
...error,
level: 'error',
message: 'Error deleting file',
[Symbol.for('level')]: 'error',
[Symbol.for('splat')]: [error],
};
const result = logger.format.transform(info, logger.format.options);
expect(serializeAgent).not.toHaveBeenCalled();
expect(Object.getOwnPropertySymbols(result || {})).not.toContain(Symbol.for('message'));
});
});

View file

@ -132,6 +132,9 @@ if (useDebugConsole) {
// Create logger
const logger: winston.Logger = winston.createLogger({
level: level(),
// Transports sanitize and serialize. Winston otherwise JSON-serializes raw
// errors here, walking the shared HTTP agent graph before those guards run.
format: winston.format((info) => info)(),
levels: logLevels,
transports,
});