我对一个用 VueJs 编写的应用程序运行了 veracode 扫描。扫描返回一个与跨站点攻击有关的中等缺陷“网页中与脚本相关的 HTML 标签的不当中和(基本 XSS)。”
它指向代码中可能发生注入攻击的区域(参见下面的代码片段)。
模板部分
<v-list-item @click="selectNotListedHandler(searchString)">
<v-list-item
v-if="searchString !== null && error === '' && !isBusy"
>
<v-list-item-title
class="text-wrap"
style="word-break: break-word"
>My <b>{{ searchString }}</b> and is not
listed</v-list-item-title
>
</v-list-item>
</v-list-item>
脚本部分
const searchString: Ref<string> = ref("");
看过 OWASP 备忘单后,我不知道我应该做什么来解决这个问题。我尝试添加一个警报,就像这样想,如果我在这里添加它,它将适用于任何引用 searchString 的地方:
const alert(searchString: Ref<string> = ref(""));
但是无论我把'()放在哪里,这都会立即引发错误。'
我发现我可以在此处添加它而不会引发错误,但我无法在其他任何地方应用它:
if (alert(searchString.value) == null || searchString.value === "") {