Make the autocomplete's onselect handler work without eval

未关闭
#1,948 1 条评论 0 个 reaction 已指派 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 分钟
30 天内合并 PR
167

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/wicket 的其他 Issue

查看 apache/wicket 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。