Skip to content
← Back to rules

react/iframe-missing-sandbox 可疑

An auto-fix is available for this rule.

它做了什么

强制在 iframe 元素上使用 sandbox 属性

为什么这是不好的?

sandbox 属性为 iframe 中的内容启用了额外的一组限制。使用 sandbox 属性被认为是一种良好的安全实践。有关沙箱的更多信息,请参阅 MDN 关于 sandbox 属性的文档

此规则检查所有 React <iframe> 元素,并验证是否存在 sandbox 属性且其值有效。此外,它还会报告同时包含 allow-scriptsallow-same-origin 的情况,因为这种组合允许嵌入的文档移除 sandbox 属性并绕过限制。

示例

此规则的 错误 代码示例:

jsx
<iframe />;
<iframe sandbox="invalid-value" />;
<iframe sandbox="allow-same-origin allow-scripts" />;

此规则的 正确 代码示例:

jsx
<iframe sandbox="" />;
<iframe sandbox="allow-origin" />;

如何使用

要通过配置文件或 CLI 启用 此规则,可以使用:

json
{
  "plugins": ["react"],
  "rules": {
    "react/iframe-missing-sandbox": "error"
  }
}
bash
oxlint --deny react/iframe-missing-sandbox --react-plugin

参考资料