Skip to content

enable strict CSP with nonces, eliminate all inline event handlers - #346

Open
24c02 wants to merge 1 commit into
mainfrom
csp-and-data-attributes
Open

24c02 wants to merge 1 commit into
mainfrom
csp-and-data-attributes

Conversation

@24c02

@24c02 24c02 commented Oct 20, 2026

Copy link
Copy Markdown
Member

what

strict Content-Security-Policy with nonces. zero inline event handlers remain in ERB or Phlex.

follows up on the stored XSS fix in 6ba7897 — this eliminates the entire class of JS-context XSS from inline handlers, so even if another unescaped interpolation slips through, CSP blocks execution.

CSP policy

  • script-src 'self' + nonces (no unsafe-inline in any env)
  • style-src 'self' (+ unsafe-inline in dev for vite HMR)
  • allowlisted external domains: jsdelivr (fonts), googleapis (maps), hackclub CDNs (images), are-we-there-yet (iframe)
  • vite dev server host allowlisted for scripts + websocket in development

inline handler migration

every onclick, onsubmit, onerror, onload attribute across all ERB views and Phlex components converted to data-* attributes with delegated addEventListener handlers in nonced <script> blocks.

views: backend/identities, backend/verifications, backend/static_pages, backend/verification_cases, backend/shared/_review_document_files, identities/new, developer_apps/show, docs/show, static_pages/slack_id, error pages, layouts/backend

components: backup_codes_display, window, code_input, sidebar, banner

verification

$ grep -rE 'onclick=|onsubmit=|onerror=|onload=' app/views/ app/components/
(no results)

@24c02
24c02 force-pushed the csp-and-data-attributes branch 6 times, most recently from 16d19f9 to 2308994 Compare October 20, 2026 21:21
- activate Content-Security-Policy with nonces for scripts/styles
- allowlist external domains: jsdelivr (fonts), googleapis (maps),
  hackclub CDNs (images), are-we-there-yet (iframe)
- no unsafe-inline for scripts in any environment
- dev: unsafe-inline for styles (vite HMR), vite host for scripts/ws

convert every onclick/onsubmit/onerror attribute in ERB and Phlex to
data-* attributes with delegated addEventListener handlers:

  views: backend/identities, backend/verifications, backend/static_pages,
    backend/verification_cases, backend/shared/_review_document_files,
    identities/new, developer_apps/show, docs/show, static_pages/slack_id,
    error pages, layouts/backend

  components: backup_codes_display, window, code_input, sidebar, banner

add nonce to all inline <script> blocks in layouts and the google
maps helper. zero inline event handlers remain in ERB or Phlex.
@24c02
24c02 force-pushed the csp-and-data-attributes branch from 2308994 to 94d40f0 Compare October 20, 2026 21:31
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​alpinejs/​csp@​3.17.5991007495100

View full report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant