Make the autocomplete's onselect handler work without eval

Aperta
#1,948 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Ritesh17rb ci sta già lavorando.

Dal 20/11/2026.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
java, javascript
Ambito
frontend, security

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Java
Stelle
800
Fork
437
Merge medio
21h 36m
PR unite (30g)
167

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/wicket

Tutte le issue di apache/wicket

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.