Skip to content

fix(csp): support MemberExpression assignments in evaluator#4807

Merged
calebporzio merged 2 commits intoalpinejs:mainfrom
dasm:fix/csp-member-expression-assignment
Apr 10, 2026
Merged

fix(csp): support MemberExpression assignments in evaluator#4807
calebporzio merged 2 commits intoalpinejs:mainfrom
dasm:fix/csp-member-expression-assignment

Conversation

@dasm
Copy link
Copy Markdown
Contributor

@dasm dasm commented Apr 9, 2026

Replace the blanket "Property assignments are prohibited" throw with targeted logic that resolves the object and property, blocks DOM node writes (instanceof Node), and performs the assignment. The UpdateExpression MemberExpression path was missing both guards; align it with AssignmentExpression to correctly guard against DOM node writes and prototype pollution.

Fixes #4722
Ref: #4671 (sections 3.1.6, 3.2.5)

Replace the blanket "Property assignments are prohibited" throw with
targeted logic that resolves the object and property, blocks DOM node
writes (instanceof Node), and performs the assignment. The
UpdateExpression MemberExpression path was missing both guards; align
it with AssignmentExpression to correctly guard against DOM node writes
and prototype pollution.

Fixes alpinejs#4722
Ref: alpinejs#4671 (sections 3.1.6, 3.2.5)
@dasm dasm force-pushed the fix/csp-member-expression-assignment branch from 7af94c0 to 21e0a67 Compare April 9, 2026 23:17
- Add setAttribute, setAttributeNS, setAttributeNode, setAttributeNodeNS
  to the dangerous keywords blocklist to prevent XSS via event handler
  attribute injection (e.g. $el.setAttribute('onclick', 'evil'))

- Widen instanceof Node check to also cover CSSStyleDeclaration,
  DOMStringMap, DOMTokenList, and NamedNodeMap to prevent property
  assignments on DOM-adjacent objects (e.g. $el.style.cssText, $el.dataset)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@calebporzio calebporzio merged commit a0450cc into alpinejs:main Apr 10, 2026
1 check passed
@dasm dasm deleted the fix/csp-member-expression-assignment branch April 10, 2026 16:51
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.

2 participants