Make the autocomplete's onselect handler work without eval

オープン
#1,948 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Ritesh17rb がすでに取り組んでいます。

2026年11月20日 から。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
java, javascript
領域
frontend, security

調査の方向性

Read wicket-autocomplete.js and AbstractAutoCompleteRenderer.getOnSelectJavaScriptExpression, then inspect the autocomplete example in wicket-examples and its tests. First propose an approach in an issue comment, as requested. Done means selecting a choice works with Wicket's default CSP in the example and the method's Javadoc explains the CSP requirement.

索引モデルが issue の本文から書いたものです。

説明

good first issue

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:
    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 (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 for building and testing.

主要言語
Java
スター
800
フォーク
437
平均マージ
21時間 36分
マージ済み PR(30日)
167

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/wicket のほかの issue

apache/wicket の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。