From f2a45159f034f489d11aac507a8b67b6f0f018b2 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 11 Nov 2026 07:29:45 +0000 Subject: [PATCH] fix(web-app-shopware): draw the showcase customer password at random MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The design spec derived the showcase customer's password from the administrator password with a bare SHA-256 (CodeQL alert 938, js/insufficient-password-hash). The value is a plaintext password that the spec syncs into Shopware and types into the storefront login, so a stronger hash would still tie it to the administrator secret. It is now 32 random bytes in hex, drawn per run and seeded before every sign-in; the administrator password only reaches the OAuth token request. A unit test pins that the synced and the typed password are the same random value. 🎯 Fix: 95 % 💥 Break: 3 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: 100 % 🏆 Score: 92 🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 --- .../files/playwright/test-design.js | 2 +- .../files/playwright/test-design.test.js | 72 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 tests/unit/javascript/roles/web-app-shopware/files/playwright/test-design.test.js diff --git a/roles/web-app-shopware/files/playwright/test-design.js b/roles/web-app-shopware/files/playwright/test-design.js index ec2aa35729..ce51388113 100644 --- a/roles/web-app-shopware/files/playwright/test-design.js +++ b/roles/web-app-shopware/files/playwright/test-design.js @@ -41,7 +41,7 @@ const SHOWCASE = { { id: "d0000000000000000000000000000013", number: "DESIGN-3", name: "Design showcase table", gross: 476 }, ], customerEmail: `design-showcase@${canonicalDomain}`, - customerPassword: crypto.createHash("sha256").update(`design-showcase:${adminPassword}`).digest("hex"), + customerPassword: crypto.randomBytes(32).toString("hex"), }; const THEME_FIELDS = [ ["sw-color-brand-primary", "--design-primary"], diff --git a/tests/unit/javascript/roles/web-app-shopware/files/playwright/test-design.test.js b/tests/unit/javascript/roles/web-app-shopware/files/playwright/test-design.test.js new file mode 100644 index 0000000000..559d78a9ad --- /dev/null +++ b/tests/unit/javascript/roles/web-app-shopware/files/playwright/test-design.test.js @@ -0,0 +1,72 @@ +const test = require("node:test"); +const assert = require("node:assert/strict"); +const crypto = require("node:crypto"); +const path = require("node:path"); + +const PROJECT_ROOT = path.resolve(__dirname, "../../../../../../.."); +const { loadInternals } = require(path.join(PROJECT_ROOT, "tests/unit/javascript/utils/internals.js")); + +const BASE = "https://shop.example"; +const DOTENV = { + APP_BASE_URL: BASE, + ADMIN_USERNAME: "administrator", + ADMIN_PASSWORD: "administrator-secret", + CANONICAL_DOMAIN: "shop.example", +}; +const RESPONSES = { + "/api/oauth/token": { access_token: "token" }, + "/api/search/sales-channel": { data: [{ id: "channel", domains: [{ url: BASE }] }] }, + "/api/search/tax": { data: [{ id: "tax", taxRate: 19 }] }, + "/api/search/theme": { data: [{ id: "theme" }] }, + "/api/search/salutation": { data: [{ id: "salutation" }] }, + "/api/_action/sync": {}, +}; +const passes = new Proxy( + {}, + { + get: (_, matcher) => { + if (matcher === "then") return undefined; + return matcher === "not" ? passes : async () => undefined; + }, + }, +); + +const synced = []; +const { seedShowcase, signInCustomer } = loadInternals( + path.join(PROJECT_ROOT, "roles/web-app-shopware/files/playwright/test-design.js"), + ["seedShowcase", "signInCustomer"], + { + "node:crypto": { ...crypto, randomBytes: (size) => Buffer.alloc(size, 0x5a) }, + "@playwright/test": { test: () => undefined, expect: () => passes }, + "./personas": { + apiFetchOnion: async (_request, url, options) => { + const route = url.slice(BASE.length); + if (route === "/api/_action/sync") synced.push(options.data); + return { status: () => 200, json: async () => RESPONSES[route] }; + }, + decodeDotenvQuotedValue: (value) => value, + gotoOnion: async () => undefined, + normalizeBaseUrl: (value) => value, + requireDotenvValue: (_value, name) => DOTENV[name], + }, + "./timeouts": { resolveTimeout: (ms) => ms }, + }, + {}, +); + +test("the showcase customer signs in with a password drawn from node:crypto, not derived from the administrator's", async () => { + await seedShowcase({}); + const filled = {}; + const locator = (selector) => ({ + fill: async (value) => { + filled[selector] = value; + }, + locator, + press: async () => undefined, + }); + await signInCustomer({ locator }); + + const seeded = synced[0]["design-showcase-customer"].payload[0].password; + assert.match(seeded, /^(?:5a){16,}$/); + assert.equal(filled["input[name='password']"], seeded); +});