@mcpjam/widget-react 0.1.7 → 0.1.8
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.
- package/dist/index.d.ts +23 -0
- package/dist/index.js +33 -8
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,23 @@ type ResolvedHostCapabilities = Omit<McpUiHostCapabilities, "sandbox">;
|
|
|
56
56
|
type ResolvedHostInfo = Record<string, unknown> | undefined;
|
|
57
57
|
/** Required form of the OpenAI Apps compat surface. */
|
|
58
58
|
type ResolvedOpenAiAppsCapabilities = Required<OpenAiAppsCapabilities>;
|
|
59
|
+
type McpAppsCspConnectDomains = {
|
|
60
|
+
fetch?: boolean;
|
|
61
|
+
xhr?: boolean;
|
|
62
|
+
websocket?: boolean;
|
|
63
|
+
};
|
|
64
|
+
type McpAppsCspResourceDomains = {
|
|
65
|
+
script?: boolean;
|
|
66
|
+
stylesheet?: boolean;
|
|
67
|
+
image?: boolean;
|
|
68
|
+
font?: boolean;
|
|
69
|
+
media?: boolean;
|
|
70
|
+
};
|
|
71
|
+
type CspSubtypePolicy = {
|
|
72
|
+
cspConnectDomains?: McpAppsCspConnectDomains;
|
|
73
|
+
cspResourceDomains?: McpAppsCspResourceDomains;
|
|
74
|
+
};
|
|
75
|
+
type CspSubtype = keyof McpAppsCspConnectDomains | keyof McpAppsCspResourceDomains;
|
|
59
76
|
/** resolveEffectiveCompatRuntime result. */
|
|
60
77
|
type EffectiveCompatRuntime = {
|
|
61
78
|
injected: false;
|
|
@@ -80,6 +97,8 @@ type ResolvedMcpAppsCapabilities = {
|
|
|
80
97
|
sandboxPermissions: boolean;
|
|
81
98
|
cspFrameDomains: boolean;
|
|
82
99
|
cspBaseUriDomains: boolean;
|
|
100
|
+
cspConnectDomains?: McpAppsCspConnectDomains;
|
|
101
|
+
cspResourceDomains?: McpAppsCspResourceDomains;
|
|
83
102
|
resourcePrefersBorder: boolean;
|
|
84
103
|
downloadFile: boolean;
|
|
85
104
|
requestTeardown: boolean;
|
|
@@ -145,6 +164,7 @@ interface CspViolation {
|
|
|
145
164
|
lineNumber?: number | null;
|
|
146
165
|
columnNumber?: number | null;
|
|
147
166
|
timestamp: number;
|
|
167
|
+
subtype?: CspSubtype;
|
|
148
168
|
}
|
|
149
169
|
interface WidgetLifecycleEvent {
|
|
150
170
|
kind: "sandbox-proxy-ready" | "widget-content-requested" | "widget-content-ready" | "widget-content-error" | "widget-content-invalid-mimetype" | "bridge-connect-start" | "bridge-connect-ready" | "bridge-connect-error" | "bridge-connect-skipped" | "app-initialized";
|
|
@@ -156,6 +176,7 @@ interface WidgetSandboxApplied {
|
|
|
156
176
|
sandboxAttrs?: string[];
|
|
157
177
|
allowFeatures?: Record<string, string>;
|
|
158
178
|
cspDirectives?: Record<string, string[]>;
|
|
179
|
+
cspSubtypePolicy?: CspSubtypePolicy;
|
|
159
180
|
permissive: boolean;
|
|
160
181
|
hostPolicyApplied: boolean;
|
|
161
182
|
restrictTo?: {
|
|
@@ -776,6 +797,8 @@ interface SandboxedIframeProps {
|
|
|
776
797
|
* (`["'unsafe-eval'", "'wasm-unsafe-eval'"]`).
|
|
777
798
|
*/
|
|
778
799
|
cspDirectives?: Record<string, string[]>;
|
|
800
|
+
/** Probe-derived host policy for individual CSP-backed browser APIs. */
|
|
801
|
+
cspSubtypePolicy?: CspSubtypePolicy;
|
|
779
802
|
/** Skip CSP injection entirely (for permissive/testing mode) */
|
|
780
803
|
permissive?: boolean;
|
|
781
804
|
/**
|
package/dist/index.js
CHANGED
|
@@ -831,6 +831,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
831
831
|
sandboxAttrs,
|
|
832
832
|
allowFeatures,
|
|
833
833
|
cspDirectives,
|
|
834
|
+
cspSubtypePolicy,
|
|
834
835
|
permissive,
|
|
835
836
|
recordMode,
|
|
836
837
|
onProxyReady,
|
|
@@ -945,6 +946,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
945
946
|
() => stableStringifyJson({
|
|
946
947
|
csp: csp ?? null,
|
|
947
948
|
cspDirectives: cspDirectives ?? null,
|
|
949
|
+
cspSubtypePolicy: cspSubtypePolicy ?? null,
|
|
948
950
|
html: html ?? null,
|
|
949
951
|
permissive: permissive ?? null,
|
|
950
952
|
permissions: permissions ?? null,
|
|
@@ -957,6 +959,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
957
959
|
[
|
|
958
960
|
csp,
|
|
959
961
|
cspDirectives,
|
|
962
|
+
cspSubtypePolicy,
|
|
960
963
|
html,
|
|
961
964
|
permissive,
|
|
962
965
|
permissions,
|
|
@@ -991,6 +994,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
991
994
|
// can't accidentally widen the inner grant by reading a stale
|
|
992
995
|
// field.
|
|
993
996
|
cspDirectives,
|
|
997
|
+
cspSubtypePolicy,
|
|
994
998
|
permissive,
|
|
995
999
|
colorScheme,
|
|
996
1000
|
recordMode,
|
|
@@ -1050,6 +1054,7 @@ function McpAppsModal({
|
|
|
1050
1054
|
widgetSandboxAttrs,
|
|
1051
1055
|
widgetAllowFeatures,
|
|
1052
1056
|
widgetCspDirectives,
|
|
1057
|
+
widgetCspSubtypePolicy,
|
|
1053
1058
|
hostContextRef,
|
|
1054
1059
|
serverId,
|
|
1055
1060
|
resourceUri,
|
|
@@ -1276,6 +1281,7 @@ function McpAppsModal({
|
|
|
1276
1281
|
sandboxAttrs: widgetSandboxAttrs,
|
|
1277
1282
|
allowFeatures: widgetAllowFeatures,
|
|
1278
1283
|
cspDirectives: widgetCspDirectives,
|
|
1284
|
+
cspSubtypePolicy: widgetCspSubtypePolicy,
|
|
1279
1285
|
colorScheme: modalColorScheme,
|
|
1280
1286
|
onMessage: handleModalMessage,
|
|
1281
1287
|
title: `MCP App Modal: ${title}`,
|
|
@@ -2851,6 +2857,14 @@ function MCPAppsRendererSurface({
|
|
|
2851
2857
|
return Object.keys(out).length > 0 ? out : void 0;
|
|
2852
2858
|
}, [cspDirectivesPolicy]);
|
|
2853
2859
|
const effectiveSandbox = useMemo(() => {
|
|
2860
|
+
const cspSubtypePolicy = earlyEffectiveMcpAppsCapabilities.cspConnectDomains || earlyEffectiveMcpAppsCapabilities.cspResourceDomains ? {
|
|
2861
|
+
cspConnectDomains: earlyEffectiveMcpAppsCapabilities.cspConnectDomains,
|
|
2862
|
+
cspResourceDomains: earlyEffectiveMcpAppsCapabilities.cspResourceDomains
|
|
2863
|
+
} : void 0;
|
|
2864
|
+
const cspSubtypePolicyRestricts = !!cspSubtypePolicy && [
|
|
2865
|
+
...Object.values(cspSubtypePolicy.cspConnectDomains ?? {}),
|
|
2866
|
+
...Object.values(cspSubtypePolicy.cspResourceDomains ?? {})
|
|
2867
|
+
].some((allowed) => allowed === false);
|
|
2854
2868
|
const restrictToConfigured = sandboxCspPolicy?.restrictTo !== void 0 && Object.values(sandboxCspPolicy.restrictTo).some(
|
|
2855
2869
|
(list) => Array.isArray(list) && list.length > 0
|
|
2856
2870
|
);
|
|
@@ -2897,7 +2911,8 @@ function MCPAppsRendererSurface({
|
|
|
2897
2911
|
hostPolicyApplied: !!resolvedPermissions2,
|
|
2898
2912
|
sandboxAttrs: sandboxAttrsPolicy,
|
|
2899
2913
|
allowFeatures: allowFeaturesPolicy,
|
|
2900
|
-
cspDirectives: cspDirectivesEffective
|
|
2914
|
+
cspDirectives: cspDirectivesEffective,
|
|
2915
|
+
cspSubtypePolicy: void 0
|
|
2901
2916
|
};
|
|
2902
2917
|
}
|
|
2903
2918
|
const isPureRelaxedCsp = sandboxCspPolicy?.mode === "relaxed" && !restrictToConfigured && !cspDirectivesConfigured && !host.surface.hostedMode;
|
|
@@ -2969,7 +2984,9 @@ function MCPAppsRendererSurface({
|
|
|
2969
2984
|
}
|
|
2970
2985
|
resolvedPermissions = out;
|
|
2971
2986
|
}
|
|
2972
|
-
const
|
|
2987
|
+
const effectiveCspSubtypePolicy = isPureRelaxedCsp ? void 0 : cspSubtypePolicy;
|
|
2988
|
+
const cspSubtypeRestrictionApplies = !isPureRelaxedCsp && cspSubtypePolicyRestricts;
|
|
2989
|
+
const hostPolicyApplied = !!resolvedCsp || !!resolvedPermissions || isPureRelaxedCsp || cspSubtypeRestrictionApplies;
|
|
2973
2990
|
return {
|
|
2974
2991
|
// Pure relaxed → no CSP at all (caller's `permissive: true` below
|
|
2975
2992
|
// tells SandboxedIframe to skip CSP injection). Otherwise pass
|
|
@@ -2979,7 +2996,7 @@ function MCPAppsRendererSurface({
|
|
|
2979
2996
|
// Copilot host whose matrix turns frameDomains off doesn't
|
|
2980
2997
|
// accidentally pass the un-gated value to the iframe via the
|
|
2981
2998
|
// `?? widgetCsp` branch.
|
|
2982
|
-
csp: isPureRelaxedCsp ? void 0 : resolvedCsp ?? (widgetPermissive ? void 0 : matrixGatedWidgetCsp),
|
|
2999
|
+
csp: isPureRelaxedCsp ? void 0 : resolvedCsp ?? (widgetPermissive && !cspSubtypeRestrictionApplies ? void 0 : matrixGatedWidgetCsp),
|
|
2983
3000
|
permissions: resolvedPermissions ?? matrixGatedWidgetPermissions,
|
|
2984
3001
|
// A host-applied CSP MUST be honored at the browser layer. When
|
|
2985
3002
|
// a restrictive host policy is in force, force `permissive: false`
|
|
@@ -2997,11 +3014,12 @@ function MCPAppsRendererSurface({
|
|
|
2997
3014
|
// — silently breaking network access for permissive widgets.
|
|
2998
3015
|
// Permissions and CSP are orthogonal user-facing knobs; tweaking
|
|
2999
3016
|
// one must not reshape the other.
|
|
3000
|
-
permissive: isPureRelaxedCsp ? true : resolvedCsp ? false : widgetPermissive,
|
|
3017
|
+
permissive: isPureRelaxedCsp ? true : resolvedCsp || cspSubtypeRestrictionApplies ? false : widgetPermissive,
|
|
3001
3018
|
hostPolicyApplied,
|
|
3002
3019
|
sandboxAttrs: sandboxAttrsPolicy,
|
|
3003
3020
|
allowFeatures: allowFeaturesPolicy,
|
|
3004
|
-
cspDirectives: cspDirectivesEffective
|
|
3021
|
+
cspDirectives: cspDirectivesEffective,
|
|
3022
|
+
cspSubtypePolicy: effectiveCspSubtypePolicy
|
|
3005
3023
|
};
|
|
3006
3024
|
}, [
|
|
3007
3025
|
cspMode,
|
|
@@ -3015,7 +3033,9 @@ function MCPAppsRendererSurface({
|
|
|
3015
3033
|
widgetPermissive,
|
|
3016
3034
|
sandboxAttrsPolicy,
|
|
3017
3035
|
allowFeaturesPolicy,
|
|
3018
|
-
cspDirectivesEffective
|
|
3036
|
+
cspDirectivesEffective,
|
|
3037
|
+
earlyEffectiveMcpAppsCapabilities.cspConnectDomains,
|
|
3038
|
+
earlyEffectiveMcpAppsCapabilities.cspResourceDomains
|
|
3019
3039
|
]);
|
|
3020
3040
|
const effectiveSandboxKey = useMemo(
|
|
3021
3041
|
() => stableStringifyJson(effectiveSandbox),
|
|
@@ -3057,6 +3077,7 @@ function MCPAppsRendererSurface({
|
|
|
3057
3077
|
sandboxAttrs: effectiveSandbox.sandboxAttrs,
|
|
3058
3078
|
allowFeatures: effectiveSandbox.allowFeatures,
|
|
3059
3079
|
cspDirectives: effectiveSandbox.cspDirectives,
|
|
3080
|
+
cspSubtypePolicy: effectiveSandbox.cspSubtypePolicy,
|
|
3060
3081
|
permissive: effectiveSandbox.permissive,
|
|
3061
3082
|
hostPolicyApplied: effectiveSandbox.hostPolicyApplied,
|
|
3062
3083
|
restrictTo: sandboxCspPolicy?.restrictTo,
|
|
@@ -3554,7 +3575,8 @@ function MCPAppsRendererSurface({
|
|
|
3554
3575
|
lineNumber,
|
|
3555
3576
|
columnNumber,
|
|
3556
3577
|
effectiveDirective,
|
|
3557
|
-
timestamp
|
|
3578
|
+
timestamp,
|
|
3579
|
+
subtype
|
|
3558
3580
|
} = data;
|
|
3559
3581
|
logUiEvent({
|
|
3560
3582
|
widgetId: toolCallId,
|
|
@@ -3571,7 +3593,8 @@ function MCPAppsRendererSurface({
|
|
|
3571
3593
|
sourceFile,
|
|
3572
3594
|
lineNumber,
|
|
3573
3595
|
columnNumber,
|
|
3574
|
-
timestamp: timestamp || Date.now()
|
|
3596
|
+
timestamp: timestamp || Date.now(),
|
|
3597
|
+
subtype
|
|
3575
3598
|
});
|
|
3576
3599
|
setFirstCspBlock(
|
|
3577
3600
|
(prev) => prev ?? {
|
|
@@ -3859,6 +3882,7 @@ function MCPAppsRendererSurface({
|
|
|
3859
3882
|
sandboxAttrs: effectiveSandbox.sandboxAttrs,
|
|
3860
3883
|
allowFeatures: effectiveSandbox.allowFeatures,
|
|
3861
3884
|
cspDirectives: effectiveSandbox.cspDirectives,
|
|
3885
|
+
cspSubtypePolicy: effectiveSandbox.cspSubtypePolicy,
|
|
3862
3886
|
colorScheme: resolvedTheme,
|
|
3863
3887
|
recordMode,
|
|
3864
3888
|
onProxyReady: () => {
|
|
@@ -4008,6 +4032,7 @@ function MCPAppsRendererSurface({
|
|
|
4008
4032
|
widgetSandboxAttrs: effectiveSandbox.sandboxAttrs,
|
|
4009
4033
|
widgetAllowFeatures: effectiveSandbox.allowFeatures,
|
|
4010
4034
|
widgetCspDirectives: effectiveSandbox.cspDirectives,
|
|
4035
|
+
widgetCspSubtypePolicy: effectiveSandbox.cspSubtypePolicy,
|
|
4011
4036
|
hostContextRef,
|
|
4012
4037
|
serverId,
|
|
4013
4038
|
resourceUri,
|