@eeacms/volto-eea-chatbot 2.0.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +230 -0
- package/CHANGELOG.md +43 -2
- package/locales/de/LC_MESSAGES/volto.po +44 -0
- package/locales/en/LC_MESSAGES/volto.po +44 -0
- package/locales/it/LC_MESSAGES/volto.po +44 -0
- package/locales/ro/LC_MESSAGES/volto.po +44 -0
- package/locales/volto.pot +46 -2
- package/package.json +2 -1
- package/src/AISearchInput/AISearchInputEdit.jsx +37 -0
- package/src/AISearchInput/AISearchInputView.jsx +130 -0
- package/src/AISearchInput/components/DeepResearchToggle.jsx +35 -0
- package/src/AISearchInput/components/DisclaimerText.jsx +10 -0
- package/src/AISearchInput/components/IntroHeader.jsx +24 -0
- package/src/AISearchInput/components/PromptChips.jsx +22 -0
- package/src/AISearchInput/components/SearchInput.jsx +53 -0
- package/src/AISearchInput/index.js +32 -0
- package/src/AISearchInput/messages.js +38 -0
- package/src/AISearchInput/schema.jsx +215 -0
- package/src/AISearchInput/styles.less +320 -0
- package/src/ChatBlock/ChatBlockView.jsx +4 -0
- package/src/ChatBlock/chat/ChatWindow.tsx +23 -0
- package/src/halloumi/middleware.js +16 -0
- package/src/halloumi/middleware.test.js +129 -9
- package/src/icons/sparkle.svg +3 -0
- package/src/index.js +2 -0
- package/src/middleware.js +34 -0
- package/src/middleware.test.js +113 -1
package/src/middleware.test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Mock superagent
|
|
2
|
-
import middleware from './middleware';
|
|
2
|
+
import middleware, { isPathAllowed, ALLOWED_PROXY_PATHS } from './middleware';
|
|
3
3
|
|
|
4
4
|
jest.mock('superagent', () => ({
|
|
5
5
|
post: jest.fn().mockReturnValue({
|
|
@@ -234,4 +234,116 @@ describe('src/middleware', () => {
|
|
|
234
234
|
'/tmp/dumped_response.jsonl',
|
|
235
235
|
);
|
|
236
236
|
});
|
|
237
|
+
|
|
238
|
+
it('rejects disallowed paths with 404', async () => {
|
|
239
|
+
process.env.ONYX_API_KEY = 'test-key';
|
|
240
|
+
process.env.ONYX_URL = 'http://localhost:3000';
|
|
241
|
+
req.url = '/_da/admin/users/delete';
|
|
242
|
+
req.method = 'POST';
|
|
243
|
+
|
|
244
|
+
await middleware(req, res, next);
|
|
245
|
+
|
|
246
|
+
expect(res.statusCode).toBe(404);
|
|
247
|
+
expect(res.send).toHaveBeenCalledWith({ error: 'Not Found' });
|
|
248
|
+
expect(nodeFetch).not.toHaveBeenCalled();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('rejects allowed path with wrong HTTP method', async () => {
|
|
252
|
+
process.env.ONYX_API_KEY = 'test-key';
|
|
253
|
+
process.env.ONYX_URL = 'http://localhost:3000';
|
|
254
|
+
req.url = '/_da/persona';
|
|
255
|
+
req.method = 'DELETE';
|
|
256
|
+
|
|
257
|
+
await middleware(req, res, next);
|
|
258
|
+
|
|
259
|
+
expect(res.statusCode).toBe(404);
|
|
260
|
+
expect(res.send).toHaveBeenCalledWith({ error: 'Not Found' });
|
|
261
|
+
expect(nodeFetch).not.toHaveBeenCalled();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('rejects path traversal attempts', async () => {
|
|
265
|
+
process.env.ONYX_API_KEY = 'test-key';
|
|
266
|
+
process.env.ONYX_URL = 'http://localhost:3000';
|
|
267
|
+
req.url = '/_da/../../etc/passwd';
|
|
268
|
+
req.method = 'GET';
|
|
269
|
+
|
|
270
|
+
await middleware(req, res, next);
|
|
271
|
+
|
|
272
|
+
expect(res.statusCode).toBe(404);
|
|
273
|
+
expect(res.send).toHaveBeenCalledWith({ error: 'Not Found' });
|
|
274
|
+
expect(nodeFetch).not.toHaveBeenCalled();
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
describe('isPathAllowed', () => {
|
|
279
|
+
it('allows all defined _da proxy paths with correct methods', () => {
|
|
280
|
+
expect(isPathAllowed('/persona', 'GET', ALLOWED_PROXY_PATHS)).toBe(true);
|
|
281
|
+
expect(isPathAllowed('/persona/25', 'GET', ALLOWED_PROXY_PATHS)).toBe(true);
|
|
282
|
+
expect(
|
|
283
|
+
isPathAllowed('/chat/create-chat-session', 'POST', ALLOWED_PROXY_PATHS),
|
|
284
|
+
).toBe(true);
|
|
285
|
+
expect(
|
|
286
|
+
isPathAllowed('/chat/send-message', 'POST', ALLOWED_PROXY_PATHS),
|
|
287
|
+
).toBe(true);
|
|
288
|
+
expect(
|
|
289
|
+
isPathAllowed('/chat/send-chat-message', 'POST', ALLOWED_PROXY_PATHS),
|
|
290
|
+
).toBe(true);
|
|
291
|
+
expect(
|
|
292
|
+
isPathAllowed(
|
|
293
|
+
'/chat/create-chat-message-feedback',
|
|
294
|
+
'POST',
|
|
295
|
+
ALLOWED_PROXY_PATHS,
|
|
296
|
+
),
|
|
297
|
+
).toBe(true);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
it('rejects allowed paths with wrong methods', () => {
|
|
301
|
+
expect(isPathAllowed('/persona', 'POST', ALLOWED_PROXY_PATHS)).toBe(false);
|
|
302
|
+
expect(
|
|
303
|
+
isPathAllowed('/chat/send-message', 'GET', ALLOWED_PROXY_PATHS),
|
|
304
|
+
).toBe(false);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it('rejects disallowed paths', () => {
|
|
308
|
+
expect(
|
|
309
|
+
isPathAllowed('/admin/users/delete', 'POST', ALLOWED_PROXY_PATHS),
|
|
310
|
+
).toBe(false);
|
|
311
|
+
expect(isPathAllowed('/../../etc/passwd', 'GET', ALLOWED_PROXY_PATHS)).toBe(
|
|
312
|
+
false,
|
|
313
|
+
);
|
|
314
|
+
expect(isPathAllowed('/api/debug', 'GET', ALLOWED_PROXY_PATHS)).toBe(false);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('strips query strings before comparison', () => {
|
|
318
|
+
expect(
|
|
319
|
+
isPathAllowed(
|
|
320
|
+
'/persona?include_deleted=false',
|
|
321
|
+
'GET',
|
|
322
|
+
ALLOWED_PROXY_PATHS,
|
|
323
|
+
),
|
|
324
|
+
).toBe(true);
|
|
325
|
+
expect(
|
|
326
|
+
isPathAllowed('/persona/25?fields=name', 'GET', ALLOWED_PROXY_PATHS),
|
|
327
|
+
).toBe(true);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('rejects non-numeric persona IDs', () => {
|
|
331
|
+
expect(isPathAllowed('/persona/abc', 'GET', ALLOWED_PROXY_PATHS)).toBe(
|
|
332
|
+
false,
|
|
333
|
+
);
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
describe('isPathAllowed with _rq paths', () => {
|
|
338
|
+
it('allows related question paths via shared allowlist', () => {
|
|
339
|
+
expect(
|
|
340
|
+
isPathAllowed('/chat/create-chat-session', 'POST', ALLOWED_PROXY_PATHS),
|
|
341
|
+
).toBe(true);
|
|
342
|
+
expect(
|
|
343
|
+
isPathAllowed('/chat/send-message', 'POST', ALLOWED_PROXY_PATHS),
|
|
344
|
+
).toBe(true);
|
|
345
|
+
expect(
|
|
346
|
+
isPathAllowed('/chat/send-chat-message', 'POST', ALLOWED_PROXY_PATHS),
|
|
347
|
+
).toBe(true);
|
|
348
|
+
});
|
|
237
349
|
});
|