From eda1ee682615c88f19f468e5da39784d325b19c8 Mon Sep 17 00:00:00 2001 From: Yassin Elmoniry Date: Tue, 10 Nov 2026 09:52:57 +0200 Subject: [PATCH 1/4] Task 5-2 --- client/package.json | 1 + client/src/lib/sanitize.js | 4 +++- package-lock.json | 30 ++++++++++++++++++++++++++++++ server/package.json | 1 + server/src/app.js | 14 ++++++++++++++ 5 files changed, 49 insertions(+), 1 deletion(-) 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..f8de0b9 100644 --- a/client/src/lib/sanitize.js +++ b/client/src/lib/sanitize.js @@ -1,3 +1,5 @@ +import DOMPurify from "dompurify"; + // 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. @@ -5,4 +7,4 @@ // 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