Skip to content

[Medium] 代码质量 - 减少 innerHTML 使用,改用 DOM API #10

Description

@Qixuan112

问题描述

多处使用 innerHTML 拼接模板字符串,虽然有转义函数,但仍存在 XSS 风险。

影响的文件

  • frontend/store.html:220-257
  • frontend/plugin-detail.html:288-398

风险

  • 模板字符串拼接容易遗漏转义
  • 嵌套转义可能失效
  • 代码可维护性差

修复建议

使用 DOM API 替代 innerHTML:

不推荐

container.innerHTML = `<h1>${esc(name)}</h1>`;

推荐

const h1 = document.createElement('h1');
h1.textContent = name;  // textContent 自动转义
container.appendChild(h1);

或考虑使用前端框架(Vue/React)提供更安全的模板系统。

优先级

Medium - 提升代码安全性和可维护性

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions