react/iframe-missing-sandbox
Require a valid sandbox attribute on iframe elements
Without sandbox, the page inside an iframe can run scripts, submit forms, open popups, and navigate your page away. sandbox="" turns all of that off, and each allow-* word turns one thing back on.
The rule reports:
- an
iframethat has nosandboxattribute - a word in
sandboxthat isn't a known permission, such as a typo allow-scriptstogether withallow-same-origin. With both, a page from your own origin can remove thesandboxattribute from its owniframe.
It checks <iframe> and React.createElement("iframe", ...). It skips a value that isn't a string literal, such as sandbox={permissions}.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"react/iframe-missing-sandbox" = "error" # or "warn"Examples#
example.jsx3 problems
const map = <iframe src="https://maps.example.com" />An iframe element is missing a sandbox attribute;
const video = <iframe src="https://video.example.com" sandbox="allow-everything" />An iframe element defines a sandbox attribute with invalid value allow-everything;
const widget = <iframe src="/widget" sandbox="allow-scripts allow-same-origin" />An iframe element defines a sandbox attribute with both allow-scripts and allow-same-origin which is invalid;example.jsx1 problem
import React from "react";
const map = React.createElement("iframe", { src: "https://maps.example.com" })An iframe element is missing a sandbox attribute;example.jsxNo problems
const map = <iframe src="https://maps.example.com" sandbox="" />;
const video = <iframe src="https://video.example.com" sandbox="allow-scripts allow-popups" />;
const widget = <iframe src="/widget" sandbox={permissions} />;