Skip to content

Commit a97eb1f

Browse files
Merge pull request #3 from moveyourdigital/fix-sandbox-iframe-youtube
Remove sandbox property from embed block
2 parents a87305f + de2d81a commit a97eb1f

File tree

4 files changed

+58
-19
lines changed

4 files changed

+58
-19
lines changed

README.md

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,13 @@ However, each renderer supports a set of props, including `className` which can
7070
className: "article-hr"
7171
},
7272
embed: {
73-
className: "styled-iframe",
74-
rel: "nofollower",
75-
sandbox: "allow-fullscreen"
73+
className: "styled-iframe"
7674
}
7775
header: {
7876
className: "lead"
7977
},
8078
image: {
81-
className: "img-fluid",
82-
actionsClassNames: {
83-
stretched: 'image-block--stretched',
84-
withBorder: 'image-block--with-border',
85-
withBackground: 'image-block--with-background',
86-
}
79+
className: "img-fluid"
8780
},
8881
list: {
8982
className: "unstyled-list"
@@ -92,18 +85,57 @@ However, each renderer supports a set of props, including `className` which can
9285
className: "lead"
9386
},
9487
quote: {
95-
className: "block-quote",
96-
actionsClassNames: {
97-
alignment: 'text-align-{alignment}', // This is a substitution placeholder: left or center.
98-
}
88+
className: "block-quote"
9989
},
10090
table: {
10191
className: "table"
10292
}
10393
}} />
10494
```
10595

106-
Above you have all allowed properties for each renderer.
96+
Below are the defaults for each renderer:
97+
98+
```js
99+
const defaultConfigs = {
100+
code: {
101+
className: ""
102+
},
103+
delimiter: {
104+
className: ""
105+
},
106+
embed: {
107+
className: "styled-iframe",
108+
rel: "noreferer nofollower external", // Generates an <a> if not able to receive an "embed" property
109+
sandbox: undefined
110+
}
111+
header: {
112+
className: ""
113+
},
114+
image: {
115+
className: "",
116+
actionsClassNames: {
117+
stretched: "image-block--stretched",
118+
withBorder: "image-block--with-border",
119+
withBackground: "image-block--with-background",
120+
}
121+
},
122+
list: {
123+
className: ""
124+
},
125+
paragraph: {
126+
className: ""
127+
},
128+
quote: {
129+
className: "",
130+
actionsClassNames: {
131+
alignment: "text-align-{alignment}", // This is a substitution placeholder: left or center.
132+
}
133+
},
134+
table: {
135+
className: "table"
136+
}
137+
}
138+
```
107139

108140
So, in theory, any CSS framework (such as Bootstrap) can work seamlessly with this library as long as you pass the correct properties.
109141

@@ -137,6 +169,11 @@ export default () => <Blocks data={dataFromEditor} renderers={{
137169
}} />
138170
```
139171

172+
## Security optimization
173+
174+
For `embed` block, you can pass a string of Feature-Policy directives for `sandbox` to optimize for security. Take into account that services such as YouTube won't work properly if you set those settings.
175+
176+
140177
## Inspiration
141178

142179
- [EditorJS-React-Renderer](https://github.com/BomdiZane/EditorJS-React-Renderer) but without opinated inline styles.

src/__snapshots__/index.test.tsx.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ Array [
6767
data-src="https://www.youtube.com/watch?v=yDiD8F9ItX0"
6868
frameBorder="0"
6969
height="320"
70-
sandbox=""
7170
src="https://www.youtube.com/embed/yDiD8F9ItX0"
7271
width="580"
7372
/>

src/renderers/embed/__snapshots__/index.test.tsx.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ exports[`<Embed /> when receives a Embed block with actions renders a <figure> b
77
data-src="https://www.youtube.com/watch?v=yDiD8F9ItX0"
88
frameBorder="0"
99
height="320"
10-
sandbox=""
1110
src="https://www.youtube.com/embed/yDiD8F9ItX0"
1211
width="580"
1312
/>

src/renderers/embed/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ const Embed = ({
1414
data,
1515
className = '',
1616
rel = 'noreferer nofollower external',
17-
sandbox = '',
17+
sandbox,
1818
}: {
1919
data: EmbedBlockData;
2020
className?: string;
2121
rel?: string;
22-
sandbox?: string;
22+
sandbox?: string | null;
2323
}) => {
2424
const classNames: string[] = [];
2525
if (className) classNames.push(className);
@@ -41,10 +41,14 @@ const Embed = ({
4141
figureprops.height = data.height.toString();
4242
}
4343

44+
if (sandbox) {
45+
figureprops.sandbox = sandbox.toString();
46+
}
47+
4448
return (
4549
<figure>
4650
{data.embed ? (
47-
<iframe src={data.embed} {...figureprops} frameBorder="0" sandbox={sandbox} data-src={data.source}></iframe>
51+
<iframe src={data.embed} {...figureprops} frameBorder="0" data-src={data.source}></iframe>
4852
) : (
4953
<a href={data.source} target="_blank" rel={rel}>
5054
{data.source}

0 commit comments

Comments
 (0)