Changeset 73abbfd in Klonkt for src/middleware
- Timestamp:
- 06/28/2026 01:55:31 PM (2 months ago)
- Branches:
- main
- Children:
- be5d86c
- Parents:
- 9910ba1
- File:
-
- 1 edited
-
src/middleware/render.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/middleware/render.js
r9910ba1 r73abbfd 21 21 import ActivityPubService from '../services/ActivityPubService.js'; 22 22 import { audioEnabled as audioFeatureEnabled } from '../config/features.js'; 23 24 // Add the per-request CSP nonce to every <script> tag that doesn't already have one, so the 25 // strict script-src (nonce + 'strict-dynamic') allows them — including scripts in htmx 26 // partials. HTML-escaped "<script" in rendered content (e.g. sanitized post bodies) won't 27 // match, so this only touches real tags. 28 function injectCspNonce(html, nonce) { 29 if (!html || !nonce) return html; 30 return String(html).replace(/<script(?![^>]*\snonce=)/gi, () => `<script nonce="${nonce}"`); 31 } 23 32 import { PLATFORMS as PLATFORMS_CATALOG } from '../services/PlatformIcons.js'; 24 33 import { t as i18nT, resolveLang, SUPPORTED as LANGS, LANG_NAMES } from '../services/i18n.js'; … … 204 213 ); 205 214 } catch (e) { /* skip chrome OOB */ } 206 return res.send( pageContent + oobChrome);215 return res.send(injectCspNonce(pageContent + oobChrome, res.locals.cspNonce)); 207 216 } 208 217 209 // Full: wrap content in shell 218 // Full: wrap content in shell (rendered to a string so we can inject the CSP nonce). 210 219 locals.pageContent = pageContent; 211 res.render('shell', locals); 220 const shellHtml = await ejs.renderFile(path.join(VIEWS_DIR, 'shell.ejs'), locals, { async: false }); 221 res.send(injectCspNonce(shellHtml, res.locals.cspNonce)); 212 222 } catch (err) { 213 223 console.error('[renderPage] Error rendering', viewName, err);
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)