dashorst opened a new issue, #1948:
URL: https://github.com/apache/wicket/issues/1948

   Under a Content Security Policy without `'unsafe-eval'`, the autocomplete 
shows its choices but selecting one fails: `wicket-autocomplete.js` evaluates 
the choice's `onselect` attribute with `eval`, which CSP blocks.
   
   ## Where
   
   - 
`wicket-extensions/src/main/java/org/apache/wicket/extensions/ajax/markup/html/autocomplete/wicket-autocomplete.js`,
 function `handleSelection`:
     ```js
     const attr = getSelectableElement(selected).attributes.onselect;
     return attr ? eval(attr.value) : input;
     ```
   - The attribute is written by `AbstractAutoCompleteRenderer` in the same 
package, from `getOnSelectJavaScriptExpression(T item)`, which returns a 
JavaScript expression that subclasses can override.
   
   ## Done when
   
   This one needs an approach agreed before coding, because the hook is a 
JavaScript *expression* produced on the server, and anything that executes such 
a string (including `new Function`) is still blocked by CSP. Possible 
directions: when no `onselect` expression is set (the default), never reach 
`eval`; offer a data-based alternative (for example a `data-` attribute with 
the value to use) for the common case of replacing the input value; and 
document that overriding `getOnSelectJavaScriptExpression` requires 
`'unsafe-eval'`. Propose the approach in a comment first.
   
   - Selecting a choice works with Wicket's default CSP in the autocomplete 
example (`wicket-examples`, `AutoCompletePage`, started from `StartExamples` in 
`wicket-examples/src/test/java`).
   - The Javadoc of `getOnSelectJavaScriptExpression` says what it requires 
from the CSP.
   
   ## Background
   
   Originally reported as 
[WICKET-6938](https://issues.apache.org/jira/browse/WICKET-6938) (Wicket 9.6). 
The reporter worked around it in their application.
   
   ---
   
   Part of #1945. This issue is meant for a first contribution to Wicket. To 
work on it, leave a comment so others know; a claim without a pull request 
lapses after two weeks. Questions are welcome, here on the issue or on 
[email protected]. Start your branch from `master`, and see [Send a pull 
request to 
Wicket](https://wicket.apache.org/contribute/wicket-pull-request.html) for 
building and testing.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to