mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 14:08:21 +00:00
* feat: introduce optional content protection seam * feat: enforce source-aware content filters * feat: complete source-aware content enforcement * test: activate skill file-text fail-close fixtures * fix: harden source-aware content filters * fix: harden model-bound content filtering * fix: preserve legacy filters and generated files * fix: inspect shared scalar metadata * test: align mocks with current dev dependencies * feat: add persisted content filter safeguards * feat: complete source-aware content filter enforcement * fix: move resume content preflight into TypeScript * fix: close content inspection edge cases * fix: harden content protection boundaries * fix: complete content protection safeguards * test: align persisted memory filter coverage * fix: reconcile content protection with current dev * fix: reconcile content protection with latest dev * fix: close content protection review gaps * fix: enforce source-aware provider boundaries * fix: preserve legacy PII preflight semantics * test: stabilize stored branch preflight fixture * fix: defer agent writes until protected model admission * perf: harden source-aware model-bound filtering * fix: canonicalize provider lineage before validation * fix: satisfy model-bound callback type checks * perf: Bound content protection filtering work * fix: Bound submission array traversal * fix: Stabilize bounded content snapshots * fix: Scope model-bound traversal overflows * fix: Preserve scoped content inspection * fix: Accumulate aggregate traversal scopes * fix: centralize content policy boundaries * test: align deferred tool policy context * test: align controller policy mocks * style: normalize content protection imports * fix: close content policy review gaps * fix: narrow active skill policy config * fix: address content protection review boundaries * fix: retain exact provenance overflow sentinel * fix: preserve literal and scoped provenance updates * fix: narrow persisted edit provenance * fix: isolate exact overflow attribution * fix: centralize stored prompt protection * fix: fail closed on incomplete transcript evidence * fix: align canonical transcript routing * refactor: centralize content policy preflights * fix: isolate upload policy error typing * style: sort policy preflight imports * refactor: centralize content policy boundaries
127 lines
3.8 KiB
JavaScript
127 lines
3.8 KiB
JavaScript
const express = require('express');
|
|
const request = require('supertest');
|
|
|
|
const mockBlockResponse = {
|
|
error: 'content_filter_block',
|
|
message: 'Submitted content contains a protected value. Remove it and try again.',
|
|
source: 'message',
|
|
field: 'text',
|
|
};
|
|
|
|
jest.mock('@librechat/api', () => ({
|
|
inspectContent: jest.fn(),
|
|
extractStoredMessageContent: jest.fn((input) => [input]),
|
|
contentFilterBlockResponse: jest.fn(() => mockBlockResponse),
|
|
restoreTenantContextFromReq: (req, res, next) => next(),
|
|
}));
|
|
|
|
jest.mock('@librechat/data-schemas', () => ({
|
|
logger: { debug: jest.fn(), error: jest.fn() },
|
|
}));
|
|
|
|
jest.mock('librechat-data-provider', () => ({
|
|
CacheKeys: { AUDIO_RUNS: 'audio-runs' },
|
|
hasActivePiiFields: jest.fn((pii, candidates) => {
|
|
if (pii == null) {
|
|
return false;
|
|
}
|
|
const hasPatterns =
|
|
pii.starterPatterns == null ||
|
|
pii.starterPatterns.length > 0 ||
|
|
(pii.customPatterns?.length ?? 0) > 0;
|
|
return (
|
|
hasPatterns && candidates.some((field) => pii.fields == null || pii.fields.includes(field))
|
|
);
|
|
}),
|
|
}));
|
|
|
|
jest.mock('~/server/services/Files/Audio', () => ({
|
|
getVoices: jest.fn(),
|
|
streamAudio: jest.fn(),
|
|
textToSpeech: jest.fn((req, res) => res.sendStatus(200)),
|
|
}));
|
|
|
|
jest.mock('~/cache', () => ({
|
|
getLogStores: jest.fn(),
|
|
}));
|
|
|
|
const {
|
|
inspectContent,
|
|
extractStoredMessageContent,
|
|
contentFilterBlockResponse,
|
|
} = require('@librechat/api');
|
|
const { textToSpeech } = require('~/server/services/Files/Audio');
|
|
const router = require('./tts');
|
|
|
|
const createApp = (config) => {
|
|
const app = express();
|
|
app.use((req, res, next) => {
|
|
req.config = config;
|
|
next();
|
|
});
|
|
app.use(router);
|
|
return app;
|
|
};
|
|
|
|
describe('manual TTS content filtering', () => {
|
|
beforeEach(() => {
|
|
inspectContent.mockReturnValue(null);
|
|
});
|
|
|
|
it('blocks configured message content before calling the TTS provider', async () => {
|
|
const filters = { messages: { pii: {} } };
|
|
const finding = {
|
|
label: 'protected value',
|
|
source: 'message',
|
|
field: 'text',
|
|
};
|
|
inspectContent.mockReturnValueOnce(finding);
|
|
|
|
const response = await request(createApp({ filters }))
|
|
.post('/manual')
|
|
.field('input', 'submitted text');
|
|
|
|
expect(response.status).toBe(400);
|
|
expect(response.body).toEqual(mockBlockResponse);
|
|
expect(extractStoredMessageContent).toHaveBeenCalledWith({ text: 'submitted text' });
|
|
expect(inspectContent).toHaveBeenCalledWith([{ text: 'submitted text' }], {
|
|
filters,
|
|
});
|
|
expect(contentFilterBlockResponse).toHaveBeenCalledWith(finding);
|
|
expect(textToSpeech).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('preserves the default-off path without inspecting the input', async () => {
|
|
const response = await request(createApp({})).post('/manual').field('input', 'submitted text');
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(inspectContent).not.toHaveBeenCalled();
|
|
expect(textToSpeech).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('preserves the input path when the selected message policy has no active patterns', async () => {
|
|
const filters = {
|
|
messages: {
|
|
pii: { fields: ['text'], starterPatterns: [], customPatterns: [] },
|
|
},
|
|
};
|
|
|
|
const response = await request(createApp({ filters }))
|
|
.post('/manual')
|
|
.field('input', 'submitted text');
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(inspectContent).not.toHaveBeenCalled();
|
|
expect(textToSpeech).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('does not broaden the legacy chat-only filter to manual TTS', async () => {
|
|
const response = await request(createApp({ messageFilter: { pii: {} } }))
|
|
.post('/manual')
|
|
.field('input', 'submitted text');
|
|
|
|
expect(response.status).toBe(200);
|
|
expect(inspectContent).not.toHaveBeenCalled();
|
|
expect(textToSpeech).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|