Text panel v2: HTML mode autocomplete suggests `on*` event handler attributes
In HTML mode, attribute autocomplete offers onblur, onclick, onunload, onload and about 20 other event handler attributes. With the default config, sanitizeTextPanelContent strips all of them, so picking one silently does nothing.
This is not a security issue. Autocomplete only inserts text the user could type anyway, and whether handlers run depends on disable_sanitize_html, not on the editor. It's a misleading suggestion.
Steps to reproduce
- Add a text panel (v2) and set the mode to HTML.
- Type
<div on. - The completion list shows
onblur,onclick, and so on.
Cause
@codemirror/lang-html adds these event attributes to its global attribute schema. loadHtml in packages/grafana-ui/src/components/CodeMirror/languageLoader.ts calls plain html(). The library has no option to remove attributes: extraGlobalAttributes can only add them. Markdown mode is not affected, because it completes tag names only.
Proposed fix
For the text panel, build the HTML LanguageSupport from htmlLanguage, autoCloseTags, and a wrapper around htmlCompletionSource that drops completions whose label starts with on. Scope it to the text panel if its editor can take a language override. That way other CodeMirror HTML editors in Grafana don't change. If it can't, add an option to the shared loader.
Acceptance criteria
- HTML mode autocomplete offers no
on*attributes. - Other HTML attribute and tag completions still work.
- Other consumers of the shared CodeMirror HTML language behave as before.
- A unit test checks that the completion list has no
on*entries.
Source: grafana/grafana