Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changeset/notifications-redos-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@objectstack/runtime": patch
---

fix(runtime): replace the polynomial-redos trailing-slash regex in the notifications domain with split+filter (CodeQL high, surfaced by #3507)

The legacy `path.replace(/\/+$/, '')` in the notifications handler had
carried a polynomial-backtracking regex over request-controlled input since
ADR-0030; the domain extraction (#3507) made the line "changed code" and
CodeQL flagged it. Same split+filter treatment the security domain already
uses for the identical pattern. Redundant slashes in the sub-path now
collapse (`//read//` → `read`), matching the security domain's semantics.
8 changes: 8 additions & 0 deletions packages/runtime/src/domain-handler-registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ describe('HttpDispatcher extracted domains (PR-2)', () => {
expect(notification.listInbox).toHaveBeenCalledWith('u1', expect.objectContaining({ limit: 5 }));
});

it('/notifications tolerates redundant slashes in the sub-path (split+filter, CodeQL redos fix)', async () => {
const notification = { listInbox: vi.fn(), markRead: vi.fn().mockResolvedValue({ updated: 1 }), markAllRead: vi.fn() };
const context: any = { executionContext: { userId: 'u1' } };
const result = await makeDispatcher({ notification }).handleNotification('//read//', 'POST', { ids: ['n1'] }, {}, context);
expect(result.response?.status).toBe(200);
expect(notification.markRead).toHaveBeenCalledWith('u1', ['n1']);
});

it('/security responds 503 when no security service is wired (legacy in-handler semantics)', async () => {
const result = await makeDispatcher().dispatch('GET', '/security/suggested-bindings', undefined, {}, {} as any);
expect(result.handled).toBe(true);
Expand Down
7 changes: 6 additions & 1 deletion packages/runtime/src/domains/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ export async function handleNotificationRequest(
}

const m = method.toUpperCase();
const subPath = path.replace(/^\/+/, '').replace(/\/+$/, '');
// split+filter drops leading/trailing/duplicate slashes without a regex
// over request-controlled input (CodeQL js/polynomial-redos) — same
// treatment the security domain got for the identical latent pattern.
// Surfaced when the extraction (#3507) made this line "changed code":
// the legacy `.replace(/\/+$/, '')` had carried the trap since ADR-0030.
const subPath = path.split('/').filter(Boolean).join('/');

// GET /notifications — list the user's inbox joined with read-state.
if (subPath === '' && m === 'GET') {
Expand Down