Skip to content

feat: send click count filters as declared JS snippets - #26952

Merged
mcollovati merged 4 commits into
mainfrom
click-filters-js-snippets
Nov 10, 2026
Merged

mcollovati merged 4 commits into
mainfrom
click-filters-js-snippets

Conversation

@totally-not-ai

Copy link
Copy Markdown
Contributor

Fixes #26667

behavior deviation · flow-server · apps using single-click or double-click listeners under a Content Security Policy without unsafe-eval

Background — event filters. A DOM listener can have a filter that decides in the browser whether an event is sent to the server. A filter written as a string is compiled with new Function, which a Content Security Policy without unsafe-eval blocks. A filter declared in a @JsDefinition interface is in the bundle instead, so nothing is compiled.

Single-click and double-click listeners now use a declared filter, so they work without unsafe-eval and are no longer reported in the warn and strict CSP modes. They accept the same clicks as before.

Risks:

  • ⚠️ Public API: ClickNotifier.ClickFiltersJs is public because nested types of an interface always are. Its Javadoc marks it as internal.
  • ✅ No breaking change, security, memory, serialization, threading, performance or migration concerns.

Context. The other call sites listed in the issue are already covered: preventDefault() and stopPropagation() by #26845, and property paths such as event.detail, event.w and event.h by #26916.

  • Replaced the event.detail == 2 and event.detail <= 1 string filters of addDoubleClickListener and addSingleClickListener with one declared filter, isClickCountBetween(min, max).
  • Moved the double-click case in CspModeTest from the list of violations to the calls that must not report one, and added the single-click case there.
  • Added a case to ImageClickIT for a click fired by the JavaScript click() function, which has a click count of 0.

The single-click and double-click listeners of ClickNotifier no longer
send a filter string that the browser compiles, so they work under a
Content Security Policy without 'unsafe-eval'.

Part of #26667
@totally-not-ai

Copy link
Copy Markdown
Contributor Author

Type of change

  • Internal change

How to test

  1. Open flow-tests/test-default/…/components/ImageClickView.java (route image-click).
  2. Click the image once, double-click it, and click it from the browser console with document.getElementById("image").click().
  3. Single click and double click count as before. With a strict CSP, the click listeners report no violation.
API changes

com.vaadin.flow.component.ClickNotifier

// Added
public interface ClickNotifier.ClickFiltersJs extends Serializable // internal; nested in an interface, so implicitly public
public DomEventFilter isClickCountBetween(int min, int max)

@mcollovati
mcollovati marked this pull request as ready for review November 10, 2026 09:40

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — left 1 comment.

Finding
📐 The new script-click test checks the result right after a server round trip instead of waiting for it.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 1 679 files  ±0   1 769 suites  ±0   2h 13m 3s ⏱️ + 1m 28s
13 390 tests ±0  13 322 ✅ ±0  68 💤 ±0  0 ❌ ±0 
14 024 runs  ±0  13 956 ✅ ±0  68 💤 ±0  0 ❌ ±0 

Results for commit 37dc8a2. ± Comparison against base commit 74bfef5.

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Nothing to flag — the changes look good.

@mcollovati
mcollovati added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 8a056f8 Nov 10, 2026
55 checks passed
@mcollovati
mcollovati deleted the click-filters-js-snippets branch November 10, 2026 11:15
vaadin-bot added a commit to vaadin/docs that referenced this pull request Nov 10, 2026
Remove the "event data of click listeners" example from the csp
property and Content Security Policy page: single and double click
listeners now use a declared filter, so they no longer need eval.

Documents vaadin/flow#26952 (`37dc8a20ea48b0b64507d41dfd9ec43f950c4296`).
@github-actions

Copy link
Copy Markdown
Contributor

Pull request created: #6615

Generated by Documentation Bot · agent · 103.1 AIC · ⊞ 11.7K

@github-actions

Copy link
Copy Markdown
Contributor

Documentation Bot: Draft documentation pull request for this change: #aw_docspr

Files updated:

  • articles/flow/security/protections/content-security-policy.adoc
  • articles/flow/configuration/properties.adoc

It was written from the state of this pull request as you see it now. Please review it and mark it ready for review.

Generated by Documentation Bot for #26952 · agent · 103.1 AIC · ⊞ 11.7K · ◷

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 25.4.0-alpha7.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Declare ClickNotifier and DomListenerRegistration helper expressions as snippets

3 participants