From cc10d929161e688a1a8c1be30e2efed2ce55790e Mon Sep 17 00:00:00 2001 From: Omarsameh14 Date: Tue, 10 Nov 2026 13:32:35 +0200 Subject: [PATCH 1/2] . --- .github/workflows/ci.yaml | 24 ++++++++++ babel.config.cjs | 7 +++ client/src/lib/sanitize.js | 16 +++---- jest.config.cjs | 28 +++++++++++ package-lock.json | 80 +++++++++++++------------------- package.json | 4 ++ server/src/app.js | 13 +++++- tests/client/reviewList.test.jsx | 45 ++++++++++++++++++ tests/server/csp.test.js | 67 ++++++++++++++++++++++++++ tests/setup/jest.setup.js | 2 + 10 files changed, 229 insertions(+), 57 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 babel.config.cjs create mode 100644 jest.config.cjs create mode 100644 tests/client/reviewList.test.jsx create mode 100644 tests/server/csp.test.js create mode 100644 tests/setup/jest.setup.js diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..9868ef7 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,24 @@ +name: CI + +on: + push: + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Check out the code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install dependencies + run: npm install + + - name: Run the test suite + run: npm test diff --git a/babel.config.cjs b/babel.config.cjs new file mode 100644 index 0000000..e448cc9 --- /dev/null +++ b/babel.config.cjs @@ -0,0 +1,7 @@ +// Lets jest load the project's ESM + JSX source through babel-jest. +module.exports = { + presets: [ + ['@babel/preset-env', { targets: { node: 'current' } }], + ['@babel/preset-react', { runtime: 'automatic' }] + ] +}; diff --git a/client/src/lib/sanitize.js b/client/src/lib/sanitize.js index 1c8ed3d..d1dea23 100644 --- a/client/src/lib/sanitize.js +++ b/client/src/lib/sanitize.js @@ -1,8 +1,8 @@ -// 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