我開發的一個火狐 addon,在上架時總是出現警告,其中不少是與 innerHTML有關:
Unsafe assignment to innerHTML
警告: Due to both security and performance concerns, this may not be set using dynamic values which have not been adequately sanitized. This can lead to security issues or fairly serious performance degradation.
意思就是給innerHTML賦值有安全隱患。
于是我重寫了相關操作:
// temp 必須有一個根節點
export const domFromTemp = (temp) => {
const parser = new DOMParser();
const doc = parser.parseFromString(temp, 'text/html');
return doc.body.firstElementChild;
};
但提示依然沒有消失,一番排查在依賴的 package 中找到痕跡:
lit-html 中
https://github.com/lit/lit/blob/main/packages/lit-html/src/lit-html.ts#L1080
有對innerHTML的賦值行為。
在考慮要不要 fork 一份自己用了……
浙公網安備 33010602011771號