Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): stop the JSON parse error leaking a body snippet to logs
Jose Ramirez95edcd83c7ee
diff --git a/control-api/src/memberRegistrationServiceClient.ts b/control-api/src/memberRegistrationServiceClient.tsindex 2ef5d1215..581749ecf 100644--- a/control-api/src/memberRegistrationServiceClient.ts+++ b/control-api/src/memberRegistrationServiceClient.ts@@ -136,10 +136,13 @@ export async function memberRegistrationServiceRequest<T>(parsed = JSON.parse(raw) as unknown} catch (cause) {if (response.ok) {+ // The parse error is NOT passed as cause here: V8 embeds ~10 chars of+ // the offending input in SyntaxError.message, so passing cause would+ // leak the upstream body into the log — contradicting this file's+ // status-only rule (line 53). The message + upstreamStatus is sufficient.throw unavailable({ ...context, upstreamStatus: response.status },- 'member-registration service returned a non-JSON response',- cause+ 'member-registration service returned a non-JSON response')}nonJsonBody = truediff --git a/control-api/test/memberRegistrationClient.errors.test.ts b/control-api/test/memberRegistrationClient.errors.test.tsindex ce6a25e8e..9751522d4 100644--- a/control-api/test/memberRegistrationClient.errors.test.ts+++ b/control-api/test/memberRegistrationClient.errors.test.ts@@ -26,6 +26,13 @@ const enrollment = vi.hoisted(() => ({}))vi.mock('../src/services/memberRegistrationEnrollment.js', () => enrollment)+const logger = vi.hoisted(() => ({+ rootLogger: {+ error: vi.fn(),+ },+}))+vi.mock('../src/observability/logger.js', () => logger)+function send(): Promise<void> {return registerAndSendInvitation('[email protected]', 'uuid-1', 'team', '2026-01-01', '2026-02-01')}@@ -138,4 +145,23 @@ describe('member-registration client failure classification', () => {expect(error.message).toContain('(404)')expect(error.message).not.toContain('upstream-internal-host.local')})++ it('REGRESSION: a non-JSON 2xx does not leak body snippet from SyntaxError.message into logs', async () => {+ vi.stubGlobal(+ 'fetch',+ vi.fn().mockResolvedValue(+ new Response('<html>SECRET_BODY_MARKER</html>', {+ status: 200,+ headers: { 'content-type': 'text/html' },+ })+ )+ )+ const error = await caught()+ expect(error).toBeInstanceOf(MemberRegistrationUnavailableError)+ // Verify the logger.error was called+ expect(logger.rootLogger.error).toHaveBeenCalled()+ // Verify the logged object does not contain the body snippet+ const [loggedObject] = logger.rootLogger.error.mock.calls[0]+ expect(JSON.stringify(loggedObject)).not.toContain('SECRET_BODY_MARKER')+ })})