diff --git a/backend/tests/test_admin.py b/backend/tests/test_admin.py index 7c634ae..9adce82 100644 --- a/backend/tests/test_admin.py +++ b/backend/tests/test_admin.py @@ -176,6 +176,23 @@ class TestListItems: assert none["items"] == [] assert none["total"] == 0 + def test_search_with_sql_metacharacters_is_treated_as_text(self, client, session) -> None: + """Search input is a parameterized substring filter, never raw SQL.""" + _make_user(session, "root", is_admin=True) + _seed_items(session, 5) + headers = _headers(session, "root") + + attack = "1=1' OR '1'='1" + resp = client.get(BASE, params={"search": attack}, headers=headers) + assert resp.status_code == 200 + body = resp.json() + assert body["items"] == [] + assert body["total"] == 0 + + # The table is intact after the "attack". + intact = client.get(BASE, headers=headers).json() + assert intact["total"] == 5 + @pytest.mark.parametrize("order, expected_first", [("asc", "Story 00"), ("desc", "Story 04")]) def test_sort_by_title(self, client, session, order, expected_first) -> None: _make_user(session, "root", is_admin=True) diff --git a/frontend/playwright/e2e/admin.spec.ts b/frontend/playwright/e2e/admin.spec.ts index 489500d..853c3e6 100644 --- a/frontend/playwright/e2e/admin.spec.ts +++ b/frontend/playwright/e2e/admin.spec.ts @@ -341,6 +341,8 @@ test.describe('admin area (M6)', () => { await expect(page.getByRole('heading', { level: 1, name: /edit item/i })).toBeVisible(); await expect(page.getByLabel(/^Title/)).toHaveValue('Breaking: local cat discovers keyboard'); await expect(page.getByLabel('Points')).toHaveValue('42'); + // The stored body loads into the WYSIWYG editor. + await expect(page.getByLabel('Item content')).toContainText('Amazing news.'); await page.getByLabel(/^Title/).fill('Breaking: local cat becomes famous'); await page.getByRole('button', { name: /save changes/i }).click(); @@ -405,4 +407,44 @@ test.describe('admin area (M6)', () => { // (Still one page for 3 items — assert the selector round-trips.) await expect(page.getByLabel('Rows per page')).toHaveValue('10'); }); + + test('editor sanitizes hostile stored HTML (no scripts or handlers survive)', async ({ + page, + }) => { + const { store } = mockAdminApi(page); + await seedToken(page, ADMIN_TOKEN); + + // Simulate a hostile item body persisted by the backend. + store[0].content = [ + '
Safe text
', + '', + '