@openpeepshq/common 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -50,11 +50,11 @@ export declare const isExternalLink: (href: string, origin?: string) => boolean;
|
|
|
50
50
|
/** Convert a same-origin path or URL to a `goto:` deep-link for RN navigation. */
|
|
51
51
|
export declare const toGotoUrl: (url: string, origin: string) => string;
|
|
52
52
|
/**
|
|
53
|
-
* Tags, attrs and
|
|
53
|
+
* Tags, attrs and forits shared by both the web (DOMPurify config) and
|
|
54
54
|
* RN (custom HTML token renderers) so both platforms apply the same policy.
|
|
55
55
|
*/
|
|
56
56
|
export declare const MARKDOWN_HTML_ALLOWED_TAGS: readonly ["b", "i", "em", "strong", "a", "p", "br", "ul", "ol", "li", "blockquote", "code", "pre", "h1", "h2", "h3", "h4", "h5", "h6", "hr", "img", "iframe", "video", "source", "picture", "figcaption"];
|
|
57
|
-
export declare const MARKDOWN_HTML_ALLOWED_ATTRS: readonly ["href", "src", "title", "alt", "target", "rel", "width", "height", "loading", "sandbox", "frameborder", "allowfullscreen", "referrerpolicy", "style"];
|
|
57
|
+
export declare const MARKDOWN_HTML_ALLOWED_ATTRS: readonly ["href", "src", "title", "alt", "target", "rel", "width", "height", "loading", "sandbox", "frameborder", "allowfullscreen", "referrerpolicy", "allow", "style"];
|
|
58
58
|
export declare const MARKDOWN_HTML_FORBIDDEN_TAGS: readonly ["script", "style", "form", "object", "embed"];
|
|
59
59
|
export declare const MARKDOWN_HTML_FORBIDDEN_ATTRS: readonly ["onload", "onerror", "onclick", "onmouseover"];
|
|
60
60
|
/** Extract all iframe `src` URLs found in an HTML string. */
|
|
@@ -63,5 +63,11 @@ export declare const extractIframeSrcs: (html: string) => string[];
|
|
|
63
63
|
* Inject safety attributes onto `<iframe>` tags so they can't break out of
|
|
64
64
|
* their container or execute script navigation. Runs after sanitization
|
|
65
65
|
* (so attackers can't smuggle attributes through), before DOM injection.
|
|
66
|
+
*
|
|
67
|
+
* We grant a broad Permissions Policy (`allow`) covering autoplay, encrypted
|
|
68
|
+
* media, and picture-in-picture, plus `allow-popups-to-escape-sandbox` in the
|
|
69
|
+
* sandbox itself. Without these, embedded players (YouTube, Vimeo, etc.)
|
|
70
|
+
* report Error 153 (autoplay blocked) because the browser denies the
|
|
71
|
+
* Permissions Policy the player requests.
|
|
66
72
|
*/
|
|
67
73
|
export declare const injectIframeSafetyAttrs: (html: string) => string;
|
|
@@ -173,7 +173,7 @@ export const toGotoUrl = (url, origin) => {
|
|
|
173
173
|
/* HTML sanitization helpers (shared allowlist + iframe safety) */
|
|
174
174
|
/* ------------------------------------------------------------------ */
|
|
175
175
|
/**
|
|
176
|
-
* Tags, attrs and
|
|
176
|
+
* Tags, attrs and forits shared by both the web (DOMPurify config) and
|
|
177
177
|
* RN (custom HTML token renderers) so both platforms apply the same policy.
|
|
178
178
|
*/
|
|
179
179
|
export const MARKDOWN_HTML_ALLOWED_TAGS = [
|
|
@@ -218,6 +218,7 @@ export const MARKDOWN_HTML_ALLOWED_ATTRS = [
|
|
|
218
218
|
'frameborder',
|
|
219
219
|
'allowfullscreen',
|
|
220
220
|
'referrerpolicy',
|
|
221
|
+
'allow',
|
|
221
222
|
'style',
|
|
222
223
|
];
|
|
223
224
|
export const MARKDOWN_HTML_FORBIDDEN_TAGS = [
|
|
@@ -248,6 +249,12 @@ export const extractIframeSrcs = (html) => {
|
|
|
248
249
|
* Inject safety attributes onto `<iframe>` tags so they can't break out of
|
|
249
250
|
* their container or execute script navigation. Runs after sanitization
|
|
250
251
|
* (so attackers can't smuggle attributes through), before DOM injection.
|
|
252
|
+
*
|
|
253
|
+
* We grant a broad Permissions Policy (`allow`) covering autoplay, encrypted
|
|
254
|
+
* media, and picture-in-picture, plus `allow-popups-to-escape-sandbox` in the
|
|
255
|
+
* sandbox itself. Without these, embedded players (YouTube, Vimeo, etc.)
|
|
256
|
+
* report Error 153 (autoplay blocked) because the browser denies the
|
|
257
|
+
* Permissions Policy the player requests.
|
|
251
258
|
*/
|
|
252
259
|
export const injectIframeSafetyAttrs = (html) => {
|
|
253
260
|
return html.replace(/<iframe([^>]*?)>/gi, (match, attrs) => {
|
|
@@ -257,7 +264,7 @@ export const injectIframeSafetyAttrs = (html) => {
|
|
|
257
264
|
}
|
|
258
265
|
if (!/sandbox\s*=/.test(safeAttrs)) {
|
|
259
266
|
safeAttrs +=
|
|
260
|
-
' sandbox="allow-scripts allow-same-origin allow-popups allow-presentation"';
|
|
267
|
+
' sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox allow-presentation"';
|
|
261
268
|
}
|
|
262
269
|
if (!/referrerpolicy\s*=/.test(safeAttrs)) {
|
|
263
270
|
safeAttrs += ' referrerpolicy="no-referrer"';
|
|
@@ -265,6 +272,9 @@ export const injectIframeSafetyAttrs = (html) => {
|
|
|
265
272
|
if (!/style\s*=/.test(safeAttrs)) {
|
|
266
273
|
safeAttrs += ' style="max-width:100%;width:100%;border:0;display:block;"';
|
|
267
274
|
}
|
|
275
|
+
if (!/\ballow\s*=/.test(safeAttrs)) {
|
|
276
|
+
safeAttrs += ' allow="autoplay; encrypted-media; picture-in-picture"';
|
|
277
|
+
}
|
|
268
278
|
return `<iframe${safeAttrs}>`;
|
|
269
279
|
});
|
|
270
280
|
};
|
package/package.json
CHANGED
|
@@ -228,7 +228,7 @@ export const toGotoUrl = (url: string, origin: string): string => {
|
|
|
228
228
|
/* ------------------------------------------------------------------ */
|
|
229
229
|
|
|
230
230
|
/**
|
|
231
|
-
* Tags, attrs and
|
|
231
|
+
* Tags, attrs and forits shared by both the web (DOMPurify config) and
|
|
232
232
|
* RN (custom HTML token renderers) so both platforms apply the same policy.
|
|
233
233
|
*/
|
|
234
234
|
export const MARKDOWN_HTML_ALLOWED_TAGS = [
|
|
@@ -274,6 +274,7 @@ export const MARKDOWN_HTML_ALLOWED_ATTRS = [
|
|
|
274
274
|
'frameborder',
|
|
275
275
|
'allowfullscreen',
|
|
276
276
|
'referrerpolicy',
|
|
277
|
+
'allow',
|
|
277
278
|
'style',
|
|
278
279
|
] as const;
|
|
279
280
|
|
|
@@ -310,6 +311,12 @@ export const extractIframeSrcs = (html: string): string[] => {
|
|
|
310
311
|
* Inject safety attributes onto `<iframe>` tags so they can't break out of
|
|
311
312
|
* their container or execute script navigation. Runs after sanitization
|
|
312
313
|
* (so attackers can't smuggle attributes through), before DOM injection.
|
|
314
|
+
*
|
|
315
|
+
* We grant a broad Permissions Policy (`allow`) covering autoplay, encrypted
|
|
316
|
+
* media, and picture-in-picture, plus `allow-popups-to-escape-sandbox` in the
|
|
317
|
+
* sandbox itself. Without these, embedded players (YouTube, Vimeo, etc.)
|
|
318
|
+
* report Error 153 (autoplay blocked) because the browser denies the
|
|
319
|
+
* Permissions Policy the player requests.
|
|
313
320
|
*/
|
|
314
321
|
export const injectIframeSafetyAttrs = (html: string): string => {
|
|
315
322
|
return html.replace(/<iframe([^>]*?)>/gi, (match, attrs: string) => {
|
|
@@ -319,7 +326,7 @@ export const injectIframeSafetyAttrs = (html: string): string => {
|
|
|
319
326
|
}
|
|
320
327
|
if (!/sandbox\s*=/.test(safeAttrs)) {
|
|
321
328
|
safeAttrs +=
|
|
322
|
-
' sandbox="allow-scripts allow-same-origin allow-popups allow-presentation"';
|
|
329
|
+
' sandbox="allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox allow-presentation"';
|
|
323
330
|
}
|
|
324
331
|
if (!/referrerpolicy\s*=/.test(safeAttrs)) {
|
|
325
332
|
safeAttrs += ' referrerpolicy="no-referrer"';
|
|
@@ -327,6 +334,9 @@ export const injectIframeSafetyAttrs = (html: string): string => {
|
|
|
327
334
|
if (!/style\s*=/.test(safeAttrs)) {
|
|
328
335
|
safeAttrs += ' style="max-width:100%;width:100%;border:0;display:block;"';
|
|
329
336
|
}
|
|
337
|
+
if (!/\ballow\s*=/.test(safeAttrs)) {
|
|
338
|
+
safeAttrs += ' allow="autoplay; encrypted-media; picture-in-picture"';
|
|
339
|
+
}
|
|
330
340
|
return `<iframe${safeAttrs}>`;
|
|
331
341
|
});
|
|
332
342
|
};
|