source: Klonkt/src/views/pages/paid-passkey.ejs@ e685f55

main
Last change on this file since e685f55 was e685f55, checked in by Robin <roboburr@…>, 7 weeks ago

Fix: paid client scripts were blocked by CSP (garbage nonce)

The paid-* views wrote nonce="<%= cspNonce %>" on their <script> tags, but
cspNonce is not a real value in the template: renderPage's default is a
function, so it rendered as nonce="() =&gt; ". injectCspNonce only adds
the real nonce to <script> tags that have NO nonce attribute yet, so these
tags kept the garbage nonce. Under our strict-dynamic CSP (no unsafe-inline,
no host sources, 'self' ignored) that blocked every one of them:

  • the vendored SimpleWebAuthnBrowser lib never loaded
  • the passkey-creation script (slice 3) never ran
  • the per-post unlock script (slice 4) never ran
  • the paid-price toggle in the editor (slice 2) never ran

Tests never caught it: the WebAuthn ceremony only runs in a real browser,
so nothing exercised these inline scripts. The convention everywhere else
is a plain <script> with no nonce; injectCspNonce fills in the real one.
Drop the hand-written nonce attribute so that happens.

Changed files:
src/views/pages/paid-gate.ejs

  • drop nonce attr on the vendored lib + unlock scripts

src/views/pages/paid-passkey.ejs

  • drop nonce attr on the vendored lib + registration scripts

src/views/pages/post-edit.ejs

  • drop nonce attr on the paid-price toggle script

-robo
Co-Authored-By: Claude Opus 4.8 <noreply@…>

  • Property mode set to 100644
File size: 2.7 KB
Line 
1<section class="pk">
2 <div class="pk-card">
3 <div class="pk-ic">🔑</div>
4 <h1 class="pk-h1">Je bent supporter, mooi.</h1>
5 <p class="pk-sub">
6 Maak nu een passkey aan. Die wordt je sleutel voor betaalde posts, zonder
7 account en zonder cookie. We bewaren geen naam of e-mailadres.
8 </p>
9 <button type="button" id="pk-go" class="pk-btn">Maak passkey</button>
10 <p id="pk-status" class="pk-status" hidden></p>
11 </div>
12</section>
13
14<script src="/assets/vendor/simplewebauthn-browser.umd.min.js"></script>
15<script>
16(function () {
17 var options = <%- optionsJson %>;
18 var blob = "<%= regBlob %>";
19 var postUrl = "<%= (typeof siteUrlBase !== 'undefined' && siteUrlBase ? siteUrlBase : '') %>/<%= postSlug %>";
20 var btn = document.getElementById('pk-go');
21 var status = document.getElementById('pk-status');
22 function say(msg, err) { status.hidden = false; status.textContent = msg; status.classList.toggle('is-err', !!err); }
23
24 if (!window.SimpleWebAuthnBrowser || !window.PublicKeyCredential) {
25 btn.disabled = true;
26 say('Passkeys worden niet ondersteund in deze browser.', true);
27 return;
28 }
29 btn.addEventListener('click', function () {
30 btn.disabled = true;
31 say('Volg de vraag van je apparaat…');
32 window.SimpleWebAuthnBrowser.startRegistration({ optionsJSON: options })
33 .then(function (response) {
34 return fetch('/paid/register', {
35 method: 'POST', headers: { 'Content-Type': 'application/json' },
36 body: JSON.stringify({ response: response, blob: blob }),
37 });
38 })
39 .then(function (r) { return r.json(); })
40 .then(function (j) {
41 if (j && j.ok) { say('Gelukt. Je passkey is aangemaakt.'); setTimeout(function () { location.href = postUrl; }, 900); }
42 else { btn.disabled = false; say('Aanmaken mislukt (' + ((j && j.error) || 'onbekend') + '). Probeer opnieuw.', true); }
43 })
44 .catch(function (e) { btn.disabled = false; say(e && e.name === 'NotAllowedError' ? 'Geannuleerd.' : 'Er ging iets mis. Probeer opnieuw.', true); });
45 });
46})();
47</script>
48
49<style>
50 .pk { max-width: 480px; margin: 0 auto; padding: 56px 18px; text-align: center; }
51 .pk-card { border: 1px solid color-mix(in srgb, var(--ink,#000) 16%, transparent); border-radius: 18px; padding: 34px 26px; }
52 .pk-ic { font-size: 40px; margin-bottom: 8px; }
53 .pk-h1 { font-size: 24px; margin: 0 0 6px; }
54 .pk-sub { opacity: .85; line-height: 1.6; margin: 0 0 20px; }
55 .pk-btn { padding: 12px 24px; border: none; border-radius: 10px; background: var(--accent,#6b8f71); color: #fff; font-weight: 600; font: inherit; font-weight: 600; cursor: pointer; }
56 .pk-btn:disabled { opacity: .6; cursor: default; }
57 .pk-status { margin: 14px 0 0; opacity: .9; }
58 .pk-status.is-err { color: #c0392b; }
59</style>
Note: See TracBrowser for help on using the repository browser.