From 420245a0bcc1e9e15363aefe46749c3fae287e6d Mon Sep 17 00:00:00 2001 From: "ilblackdragon@gmail.com" Date: Tue, 24 Mar 2026 23:51:27 -0700 Subject: [PATCH] fix: use event delegation for user action buttons (CSP compliance) Inline onclick handlers are blocked by the Content-Security-Policy (script-src 'self' without 'unsafe-inline'). Switched to data-action attributes with a delegated click listener on the users table. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/channels/web/static/app.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/channels/web/static/app.js b/src/channels/web/static/app.js index ad148143..1438392d 100644 --- a/src/channels/web/static/app.js +++ b/src/channels/web/static/app.js @@ -4371,11 +4371,11 @@ function renderUsersList(users) { var roleLabel = u.role === 'admin' ? 'admin' : 'member'; var actions = ''; if (u.status === 'active') { - actions += ' '; + actions += ' '; } else { - actions += ' '; + actions += ' '; } - actions += ''; + actions += ''; return '' + '' + escapeHtml(u.id.substring(0, 8)) + '…' + '' + escapeHtml(u.display_name) + '' @@ -4425,10 +4425,17 @@ function showTokenBanner(tokenValue) { }); } -// Make functions accessible for delegated event handlers -window.suspendUser = suspendUser; -window.activateUser = activateUser; -window.createTokenForUser = createTokenForUser; +// Delegated click handler for user action buttons (CSP-safe, no inline onclick) +document.getElementById('users-table')?.addEventListener('click', function(e) { + var btn = e.target.closest('[data-action]'); + if (!btn) return; + var action = btn.getAttribute('data-action'); + var userId = btn.getAttribute('data-user-id'); + var userName = btn.getAttribute('data-user-name'); + if (action === 'suspend-user') suspendUser(userId); + else if (action === 'activate-user') activateUser(userId); + else if (action === 'create-token') createTokenForUser(userId, userName || ''); +}); // Wire up Users tab create form document.getElementById('users-create-btn')?.addEventListener('click', function() {