Repository navigation
feat: read event data property paths without compiling them - #26916
Conversation
The client reads event data such as event.detail.value by walking the properties of the event or the element instead of compiling the expression with new Function, so it works under a Content Security Policy without unsafe-eval. The server no longer reports such paths as JavaScript sent as a string. The expression stays the key of the value in the event data sent to the server. Part of #26152
Document which event data and filters work without unsafe-eval, and cover paths with another root in the strict mode tests.
Type of change
Test coverage
|
Paths such as event.detail?.value are read without compiling them too, and return undefined when an optional segment is read from null or undefined, as the compiled expression does.
The navigation, refresh and web component connect events carry data that client code builds and sends with sendEventMessage, so their @eventdata values are keys and are never compiled. Mark these events with the internal @PrebuiltEventData and add their keys without a CSP report, so a UI starts in the strict mode.
vaadin-review-bot
left a comment
There was a problem hiding this comment.
Reviewed the changes — collected 1 finding below that could not be attached to the diff.
| Finding | |
|---|---|
| 📝 | The STRICT note now contradicts this PR: it still says click listener event data throws and that the mode can't be used yet. |
📝 The STRICT note now contradicts this PR: it still says click listener event data throws and that the mode can't be used yet.
The note says Vaadin's own event data and filter expressions, "such as those of a click listener", still throw, so the mode "is not yet usable for applications". After this change every @EventData of ClickEvent and KeyDownEvent is a property path and is no longer reported. The PR description also says a UI now starts in strict mode. Please narrow the note to what still throws, such as filters like the double-click event.detail == 2.
CspMode.java:59 · documentation
|
Updated the |
|
Property paths skip both the server's CSP report and the client's sequenceDiagram
participant R as DomListenerRegistration addEventData or setFilter
participant M as ElementListenerMap isCompiledByClient
participant C as CspViolationReporter
participant G as getOrCreateExpression client
participant P as PropertyPathExpression createPropertyPathExpression
R->>M: registers expression, e.g. event.detail.value
M->>M: isPropertyPath(expression) (new check)
alt expression is a property path
Note over M: no longer reported (new)
else expression needs compiling
M->>C: reportStringJavaScript()
end
G->>P: try createPropertyPathExpression(expression) (new, tried first)
alt matches event or element path
P-->>G: reader function, no compile
else
G->>G: new Function(event, element, expression)
end
The figure shows the one mechanism the pull request adds on both sides of the wire: Diagram Bot draws the mechanism this pull request touches; it does not review the change. Verify it against the diff.
|
vaadin-review-bot
left a comment
There was a problem hiding this comment.
✅ Nothing to flag — the changes look good.
|
|
One of these findings is real and comes from this PR: the server's property-path pattern uses a repeated group, which Java's regex engine matches recursively, so a very long path (e.g. The other findings stay as they are:
|




Part of #26152
Behavior deviation · flow-client, flow-server · apps running with a Content Security Policy without
unsafe-eval, or with the strict CSP modeBackground — event data expressions. A DOM listener can ask the browser to send values with the event, written as JavaScript expressions such as
event.detail.value. The browser compiled each one withnew Function, which a Content Security Policy withoutunsafe-evalblocks.Event data and filters that are plain property paths, like
event.detail,element.valueorevent.detail?.value, are now read in the browser without compiling anything. They work withoutunsafe-evaland are no longer reported in the warn and strict CSP modes. Together with the built-in navigation events no longer being reported, a UI now starts in strict mode.Risks:
✅ No API change, no protocol change: the expression string stays the key of the value sent to the server. Same values as the compiled expression: a
.namesegment read fromnull/undefinedthrows aTypeError, and a?.namesegment makes the whole pathundefined.Added a client resolver for
eventorelementfollowed by.nameor?.namesegments, tried beforenew Functionfor listener event data, filters, mapped elements and@EventDataof template event handlers.The server uses the same pattern for event data, mapped elements (
addEventDataElement) andsetFilter.The UI navigation, refresh and web component connect events no longer report their
@EventDatavalues, which are keys of data that client code builds and sends withsendEventMessage, never compiled expressions. They are marked with the internal@PrebuiltEventData. An application@DomEventwith such a key is still reported.Updated the Javadoc of
addEventData(String),addEventData(List)andsetFilter(String).Added client tests for the resolver and for reading paths with
new Functionblocked, and strict mode tests for paths and look-alike non-paths.Fixes #26152