From b0d57265a0c6e14b963afdb5743202957b3305a6 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Wed, 7 Aug 2024 10:38:24 -0700 Subject: [PATCH] [LuxMenuBar] Add new unsafe_name property to the menu item object `unsafe_name` works like the existing name property, except that if it contains some arbitrary HTML, it does not escape it. The immediate use case for this behavior is the "Bookmarks (4)" menu item in the catalog, which has a span with a specific class around the number that allows Blacklight's javascript to update it as the user adds/removes bookmarks. This has security implications, since `unsafe_name` bypasses Vue's cross-site scripting protections. I've added documentation about this (as well as other properties on this object that did not yet have this documentation). Interestingly, the `buttons` version of LuxMenuBar was already bypassing cross-site scripting protections for the `name` property. In the interest of consistency and safe defaults, this commit make it match the behavior of the others: you can add arbitrary HTML with `unsafe_name`, not with `name`. Helps with pulibrary/orangelight#4088 --- src/components/LuxMenuBar.vue | 34 +++++++---- src/components/_LuxMenuBarLabel.vue | 30 ++++++++++ .../__snapshots__/luxMenuBar.spec.js.snap | 4 ++ .../unit/specs/components/luxMenuBar.spec.js | 16 ++++- .../specs/components/luxMenuBarLabel.spec.js | 60 +++++++++++++++++++ 5 files changed, 132 insertions(+), 12 deletions(-) create mode 100644 src/components/_LuxMenuBarLabel.vue create mode 100644 tests/unit/specs/components/luxMenuBarLabel.spec.js diff --git a/src/components/LuxMenuBar.vue b/src/components/LuxMenuBar.vue index 4cccbfb..fbc4fe2 100644 --- a/src/components/LuxMenuBar.vue +++ b/src/components/LuxMenuBar.vue @@ -10,8 +10,8 @@ class="lux-has-children lux-nav-item" aria-haspopup="true" @click="menuItemClicked($event, item)" - >{{ item.name }} + > @@ -50,10 +50,11 @@ { 'lux-disabled': item.disabled }, { 'lux-is-child': item.hasOwnProperty('parent') === true }, ]" - v-html="item.name" :disabled="item.disabled" @click="menuItemClicked($event, item)" - > + > + + @@ -88,7 +89,7 @@ :data-method="item.method" @click="setActiveItem(index)" > - {{ item.name }} + @@ -115,7 +116,7 @@ class="lux-nav-item" @click="menuItemClicked(item)" > - {{ item.name }} + @@ -125,6 +126,7 @@ + + ```jsx +