From ade68958590ae745462113eb7a0689df92bc3d23 Mon Sep 17 00:00:00 2001 From: FarahAlsharawy Date: Tue, 10 Nov 2026 13:38:07 +0200 Subject: [PATCH 1/2] fix: sanitize review HTML with DOMPurify and add CSP via helmet --- client/package.json | 1 + client/src/lib/sanitize.js | 20 +++++++++++++++----- package-lock.json | 30 ++++++++++++++++++++++++++++++ server/package.json | 1 + server/src/app.js | 28 +++++++++++++++++++++++++++- 5 files changed, 74 insertions(+), 6 deletions(-) diff --git a/client/package.json b/client/package.json index d1b5a77..aee2fd7 100644 --- a/client/package.json +++ b/client/package.json @@ -10,6 +10,7 @@ }, "dependencies": { "axios": "^1.7.4", + "dompurify": "^3.4.17", "react": "^18.3.1", "react-dom": "^18.3.1", "react-router-dom": "^6.26.2" diff --git a/client/src/lib/sanitize.js b/client/src/lib/sanitize.js index 1c8ed3d..767df10 100644 --- a/client/src/lib/sanitize.js +++ b/client/src/lib/sanitize.js @@ -1,8 +1,18 @@ // Reviews are rendered as HTML so people can use light formatting (bold, links). // This helper is the single place review HTML passes through before it is handed // to React's dangerouslySetInnerHTML. -// -// TODO (security): right now this returns the HTML untouched, so whatever a -// reviewer typed — including ' + + 'click me'; + +function renderReview(body) { + const reviews = [{ _id: 'r1', rating: 5, author: { name: 'attacker' }, body }]; + return render(); +} + +describe('ReviewList renders review HTML safely', () => { + test('does not render any