Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browser specific iframe sandbox tokens support #2514

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/components/custom-widget/ko/runtime/customWidget.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as ko from "knockout";
import { Component, RuntimeComponent, OnMounted, OnDestroyed, Param } from "@paperbits/common/ko/decorators";
import { Environment } from "@azure/api-management-custom-widgets-tools";
import { iframeAllows, iframeSandboxAllows } from "../../../../constants";
import { iframeAllows, iframeSandboxAllows, iframeSandboxAllowsBrowserSpecific } from "../../../../constants";
import { widgetRuntimeSelector } from "../../constants";
import template from "./customWidget.html";

Expand All @@ -14,13 +14,19 @@ import template from "./customWidget.html";
})
export class CustomWidget {
public readonly iframeAllows: string = iframeAllows;
public readonly iframeSandboxAllows: string = iframeSandboxAllows;
public iframeSandboxAllows: string = iframeSandboxAllows;
private windowRef = window;

constructor() {
this.src = ko.observable();
this.name = ko.observable();
this.instanceId = ko.observable();

const iframe = document.getElementsByTagName("iframe")[0];
this.iframeSandboxAllows = `${iframeSandboxAllows} ${iframeSandboxAllowsBrowserSpecific}`
.split(" ")
.filter(token=> iframe?.sandbox.supports(token))
.join(" ");
}

@Param()
Expand Down
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ export const iframeAllows = "clipboard-read; clipboard-write; camera; microphone
/**
* List of allowed attributes for a sandboxed iframe.
*/
export const iframeSandboxAllows = "allow-same-origin allow-scripts allow-modals allow-forms allow-popups allow-popups-to-escape-sandbox allow-top-navigation allow-pointer-lock";
export const iframeSandboxAllows = "allow-scripts allow-modals allow-forms allow-popups allow-popups-to-escape-sandbox allow-top-navigation allow-pointer-lock";
export const iframeSandboxAllowsBrowserSpecific = "allow-downloads allow-presentation allow-orientation-lock";
JMach1 marked this conversation as resolved.
Show resolved Hide resolved

/**
* List of downloadable content types
Expand Down
Loading