react/iframe-missing-sandbox 可疑
功能
強制 iframe 元素上的 sandbox 屬性
為什麼這不好?
sandbox 屬性為 iframe 中的內容啟用額外的限制。使用 sandbox 屬性被認為是一種良好的安全實踐。要了解更多關於沙箱化的資訊,請參閱 MDN 上關於 sandbox
屬性的文件。
此規則檢查所有 React <iframe>
元素,並驗證是否存在 sandbox
屬性,以及其值是否有效。此外,它還會回報同時包含 allow-scripts
和 allow-same-origin
屬性的情況,因為這種組合允許嵌入式文件移除 sandbox 屬性並繞過限制。
範例
此規則的 不正確 程式碼範例
jsx
<iframe />;
<iframe sandbox="invalid-value" />;
<iframe sandbox="allow-same-origin allow-scripts" />;
此規則的 正確 程式碼範例
jsx
<iframe sandbox="" />;
<iframe sandbox="allow-origin" />;