6c1b7e8cb87b181f3220efc0ed86dbb1ceea713e
braney
Thu Apr 16 10:36:16 2026 -0700
hgTracks: harden Change Track Color dialog against XSS and invalid input, refs #20460
In response to findings from the nightly code review:
inject hub-controlled shortLabel via .text() instead of HTML concatenation,
validate the free-text color input with a hex regex before writing to the
cart, and fold the duplicated Apply/Ok handlers into a shared closure.
diff --git src/hg/js/hgTracks.js src/hg/js/hgTracks.js
index aa2e4624c7f..20c825d4e0e 100644
--- src/hg/js/hgTracks.js
+++ src/hg/js/hgTracks.js
@@ -2761,87 +2761,91 @@
// seen in FireFox 3.X, which occurred b/c FF doesn't actually fetch the image until
// the menu is being shown.
return "";
},
showColorPicker: function (trackName)
{ // Show a small dialog with a spectrum color picker for changing track color
var rec = hgTracks.trackDb[trackName];
if (!rec || !rec.defaultColor)
return;
var currentColor = (rec.colorOverrideOn && rec.colorOverride) ?
rec.colorOverride : rec.defaultColor;
var dialogId = "trackColorDialog";
$("#" + dialogId).remove();
- $("body").append(
- "
" +
- "
Pick a new color for " + rec.shortLabel + ":
" +
- "" +
+ // Build with static template + data injected via .text()/.val()/.prop() so that
+ // hub-provided shortLabel cannot inject HTML.
+ var $dlg = $("