mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-31 08:56:48 +00:00
🛂 fix: Gate RUM Proxy Route on the RUM_ENABLED Flag (#13475)
This commit is contained in:
parent
83d8ac0682
commit
f27e7d7cad
3 changed files with 81 additions and 1 deletions
|
|
@ -48,6 +48,7 @@ describe('RUM proxy configuration', () => {
|
|||
});
|
||||
|
||||
it('resolves OTLP paths against the configured collector base URL', () => {
|
||||
process.env.RUM_ENABLED = 'true';
|
||||
process.env.RUM_AUTH_MODE = 'proxy';
|
||||
process.env.RUM_PROXY_TARGET_URL = 'http://otel-collector:4318';
|
||||
|
||||
|
|
@ -57,6 +58,17 @@ describe('RUM proxy configuration', () => {
|
|||
expect(resolveRumProxyTarget('/v1/metrics')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('does not enable proxy mode when RUM is disabled', () => {
|
||||
process.env.RUM_ENABLED = 'false';
|
||||
process.env.RUM_AUTH_MODE = 'proxy';
|
||||
process.env.RUM_PROXY_TARGET_URL = 'http://otel-collector:4318';
|
||||
|
||||
expect(isRumProxyEnabled()).toBe(false);
|
||||
|
||||
delete process.env.RUM_ENABLED;
|
||||
expect(isRumProxyEnabled()).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects unsafe collector target URLs', () => {
|
||||
process.env.RUM_PROXY_TARGET_URL = 'https://user:pass@collector.example.com';
|
||||
expect(getRumProxyTargetBaseUrl()).toBeUndefined();
|
||||
|
|
@ -66,6 +78,7 @@ describe('RUM proxy configuration', () => {
|
|||
});
|
||||
|
||||
it('forwards OTLP requests without forwarding app authorization', async () => {
|
||||
process.env.RUM_ENABLED = 'true';
|
||||
process.env.RUM_AUTH_MODE = 'proxy';
|
||||
process.env.RUM_PROXY_TARGET_URL = 'http://otel-collector:4318';
|
||||
const fetchMock = jest.spyOn(global, 'fetch').mockResolvedValue(
|
||||
|
|
@ -106,6 +119,7 @@ describe('RUM proxy configuration', () => {
|
|||
});
|
||||
|
||||
it('returns 400 for missing payloads and 404 for unsupported OTLP paths', async () => {
|
||||
process.env.RUM_ENABLED = 'true';
|
||||
process.env.RUM_AUTH_MODE = 'proxy';
|
||||
process.env.RUM_PROXY_TARGET_URL = 'http://otel-collector:4318';
|
||||
const missingBodyRes = makeResponse();
|
||||
|
|
@ -122,6 +136,7 @@ describe('RUM proxy configuration', () => {
|
|||
});
|
||||
|
||||
it('returns 502 when the collector request fails', async () => {
|
||||
process.env.RUM_ENABLED = 'true';
|
||||
process.env.RUM_AUTH_MODE = 'proxy';
|
||||
process.env.RUM_PROXY_TARGET_URL = 'http://otel-collector:4318';
|
||||
const fetchMock = jest.spyOn(global, 'fetch').mockRejectedValue(new Error('collector down'));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import type { Request, Response } from 'express';
|
||||
import { logger } from '@librechat/data-schemas';
|
||||
import { isEnabled } from '~/utils';
|
||||
|
||||
const DEFAULT_PROXY_PATH = '/api/rum';
|
||||
const DEFAULT_BODY_LIMIT = '3mb';
|
||||
|
|
@ -52,7 +53,11 @@ export function getRumProxyTargetBaseUrl(): URL | undefined {
|
|||
}
|
||||
|
||||
export function isRumProxyEnabled(): boolean {
|
||||
return process.env.RUM_AUTH_MODE === 'proxy' && getRumProxyTargetBaseUrl() != null;
|
||||
return (
|
||||
isEnabled(process.env.RUM_ENABLED) &&
|
||||
process.env.RUM_AUTH_MODE === 'proxy' &&
|
||||
getRumProxyTargetBaseUrl() != null
|
||||
);
|
||||
}
|
||||
|
||||
export function resolveRumProxyTarget(path: string): string | undefined {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue