[object Object]

← back to Madagascarwallpaper

fix: safeImg allow same-origin /img/ proxy urls (vendor-neutral image proxy 2026-06-03) — product cards were falling back to hero-bg (images all wrong)

82b9cc24cf08f88f0c111e8b772650882b7ec7e4 · 2026-06-18 09:04:27 -0700 · Steve Abrams

Files touched

Diff

commit 82b9cc24cf08f88f0c111e8b772650882b7ec7e4
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Thu Jun 18 09:04:27 2026 -0700

    fix: safeImg allow same-origin /img/ proxy urls (vendor-neutral image proxy 2026-06-03) — product cards were falling back to hero-bg (images all wrong)
---
 public/index.html |  6 ++++--
 server.js         | 45 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/public/index.html b/public/index.html
index 44cf02b..1819b58 100644
--- a/public/index.html
+++ b/public/index.html
@@ -589,8 +589,10 @@ function cleanSku(s){
   var V=/(?:^|-)(versace|kravet|fentucci|sandberg|harlequin|blithfield|westport|thibaut|koroseal|schumacher|scalamandre|fromental|dedar|carnegie|marburg|fabricut|coordonne|nina-campbell|lee-jofa(?:-modern)?|clarke(?:-and)?-clarke|clarke|brunschwig(?:-and)?(?:-fils)?|designers-guild|graham-(?:and-)?brown|andrew-martin|candice-olson|ronald-redding|jeffrey-stevens|sister-parish|arte-international|wolf-gordon|phillip-jeffries|cole-(?:and-)?son|maya-romanoff|g-p-j-baker|les-ensembliers|breegan(?:-jane)?)(?:-\d+)?(?=-|$)/gi;
   return String(s||'').replace(V,'').replace(/--+/g,'-').replace(/^-+|-+$/g,'');
 }
-// Image-URL allowlist: only DW Shopify CDN + designerwallcoverings.com (defends against XSS via crafted products.json)
-function safeImg(u) { return /^https:\/\/(?:cdn\.shopify\.com|designerwallcoverings\.com)\//.test(u || '') ? u : '/hero-bg.jpg'; }
+// Image-URL allowlist: same-origin proxied /img/ (vendor-neutral image proxy, 2026-06-03) +
+// DW Shopify CDN + designerwallcoverings.com (defends against XSS via crafted products.json).
+// /img/ is server-controlled same-origin (not protocol-relative, not a javascript: URI) so it's safe.
+function safeImg(u) { u = u || ''; return (/^\/img\//.test(u) || /^https:\/\/(?:cdn\.shopify\.com|designerwallcoverings\.com)\//.test(u)) ? u : '/hero-bg.jpg'; }
 function cardHTML(p) {
   const eager = state.page === 1;
   return '<img loading="' + (eager ? 'eager' : 'lazy') + '"' + (eager ? ' fetchpriority="high"' : '') + ' src="' + escAttr(safeImg(p.image_url)) + '" alt="' + escAttr(p.title) + '">'
diff --git a/server.js b/server.js
index 19c500b..20264d3 100644
--- a/server.js
+++ b/server.js
@@ -23,6 +23,51 @@ const siteCfg = JSON.parse(fs.readFileSync(path.join(__dirname, 'site.config.jso
 const SITE_SLUG = siteCfg.slug || __SITE;
 const SITE_RAILS = Array.isArray(siteCfg.rails) ? siteCfg.rails : [];
 
+// Read-time rail membership: a product belongs to a rail if its `aesthetic` OR
+// any `tag` equals the rail key (or a declared synonym). Sister-site catalogs
+// have a degenerate `aesthetic` (mostly "all"), so naive
+// `p.aesthetic === key` matching collapses every rail to empty — the richer
+// signal lives in `tags`. Prefer the shared matcher on dev; fall back to a
+// self-contained copy on prod where the _shared/ tree isn't deployed.
+let railMatch;
+try {
+  railMatch = require('../_shared/rail-match');
+} catch (e) {
+  const norm = s => String(s == null ? '' : s).trim().toLowerCase();
+  const productInRail = (p, key, syn) => {
+    const vals = [norm(key)].concat((syn && Array.isArray(syn[key]) ? syn[key] : []).map(norm));
+    if (vals.includes(norm(p && p.aesthetic))) return true;
+    const tags = p && Array.isArray(p.tags) ? p.tags : [];
+    return tags.some(t => vals.includes(norm(t)));
+  };
+  railMatch = {
+    productInRail,
+    buildRails(products, railKeys, opts) {
+      opts = opts || {}; const syn = opts.synonyms || null;
+      const minShare = opts.minShare != null ? opts.minShare : 0.08;
+      const minItems = opts.minItems != null ? opts.minItems : 4;
+      const perRail = opts.perRail != null ? opts.perRail : 12;
+      const maxShare = opts.maxShare != null ? opts.maxShare : 0.99;
+      const list = Array.isArray(products) ? products : []; const N = list.length || 1; const out = [];
+      for (const key of (railKeys || [])) {
+        const m = list.filter(p => productInRail(p, key, syn)); const c = m.length;
+        if (c >= minItems && c / N >= minShare && c / N <= maxShare) out.push({ key, aesthetic: key, count: c, items: m.slice(0, perRail) });
+      }
+      return out;
+    },
+    railFacets(products, railKeys, syn) {
+      const list = Array.isArray(products) ? products : []; const f = {};
+      for (const key of (railKeys || [])) f[key] = list.filter(p => productInRail(p, key, syn || null)).length;
+      return f;
+    }
+  };
+}
+const { productInRail, buildRails, railFacets } = railMatch;
+// Synonyms come from the site's own config (prod-safe); the shared default map
+// is a dev-only convenience when _shared/ is present.
+let RAIL_SYN = siteCfg.railSynonyms || {};
+if (!siteCfg.railSynonyms) { try { RAIL_SYN = require('../_shared/rail-synonyms.json'); } catch (e) {} }
+
 function isJunk(p) {
   if (!p.image_url || !p.image_url.trim()) return true;
   if (!p.handle && !p.sku) return true;

← 556f8d5 Recompute aesthetic from tags via classifyAesthetic (was deg  ·  back to Madagascarwallpaper  ·  Mount new-arrivals promo strip (Tier B): require ../_shared/ 491029f →