Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

fix: defer logger serialization to sanitized transports (#17169)

Dustin Healye01b570779b0
diff --git a/packages/data-schemas/src/config/loggerSerialization.spec.ts b/packages/data-schemas/src/config/loggerSerialization.spec.ts
new file mode 100644
index 0000000000..5965a08d27
--- /dev/null
+++ b/packages/data-schemas/src/config/loggerSerialization.spec.ts
@@ -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'));
+ });
+});
diff --git a/packages/data-schemas/src/config/winston.ts b/packages/data-schemas/src/config/winston.ts
index 0d117bdaf2..589fc1c8fc 100644
--- a/packages/data-schemas/src/config/winston.ts
+++ b/packages/data-schemas/src/config/winston.ts
@@ -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,
});