swagger-editor 5.0.0-alpha.72 → 5.0.0-alpha.74

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.
@@ -0,0 +1,123 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <!-- <meta http-equiv="Content-Security-Policy" content="
5
+ default-src 'none';
6
+ child-src 'self' data: blob:;
7
+ script-src 'self' 'unsafe-eval' 'sha256-/r7rqQ+yrxt57sxLuQ6AMYcy/lUpvAIzHjIJt/OeLWU=' https:;
8
+ connect-src 'self' https: wss: http://localhost:* http://127.0.0.1:* ws://localhost:* ws://127.0.0.1:*;"/> -->
9
+ </head>
10
+ <body>
11
+ <script>
12
+ (function() {
13
+ const searchParams = new URL(document.location.href).searchParams;
14
+ const vscodeWebWorkerExtHostId = searchParams.get('vscodeWebWorkerExtHostId') || '';
15
+ const name = searchParams.get('debugged') ? 'DebugWorkerExtensionHost' : 'WorkerExtensionHost';
16
+ const parentOrigin = searchParams.get('parentOrigin') || window.origin;
17
+ const salt = searchParams.get('salt');
18
+ const vscodeExtHostWorkerSrc = searchParams.get('vscodeExtHostWorkerSrc');
19
+ const vscodeExtHostWorkerOptions = JSON.parse(searchParams.get('vscodeExtHostWorkerOptions') ?? '{}');
20
+
21
+ (async function() {
22
+ const hostnameValidationMarker = 'v--';
23
+ const hostname = location.hostname;
24
+ if (!hostname.startsWith(hostnameValidationMarker)) {
25
+ // validation not requested
26
+ return start();
27
+ }
28
+ if (!crypto.subtle) {
29
+ // cannot validate, not running in a secure context
30
+ return sendError(new Error(`Cannot validate in current context!`));
31
+ }
32
+
33
+ // Here the `parentOriginHash()` function from `src/vs/workbench/common/webview.ts` is inlined
34
+ // compute a sha-256 composed of `parentOrigin` and `salt` converted to base 32
35
+ let parentOriginHash;
36
+ try {
37
+ const strData = JSON.stringify({ parentOrigin, salt });
38
+ const encoder = new TextEncoder();
39
+ const arrData = encoder.encode(strData);
40
+ const hash = await crypto.subtle.digest('sha-256', arrData);
41
+ const hashArray = Array.from(new Uint8Array(hash));
42
+ const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
43
+ // sha256 has 256 bits, so we need at most ceil(lg(2^256-1)/lg(32)) = 52 chars to represent it in base 32
44
+ parentOriginHash = BigInt(`0x${hashHex}`).toString(32).padStart(52, '0');
45
+ } catch(err) {
46
+ return sendError(err instanceof Error ? err : new Error(String(err)));
47
+ }
48
+
49
+ const requiredSubdomain = `${hostnameValidationMarker}${parentOriginHash}.`;
50
+ if (hostname.substring(0, requiredSubdomain.length) === requiredSubdomain) {
51
+ // validation succeeded!
52
+ return start();
53
+ }
54
+
55
+ return sendError(new Error(`Expected '${requiredSubdomain}' as subdomain!`));
56
+ })();
57
+
58
+ function sendError(error) {
59
+ window.parent.postMessage({
60
+ vscodeWebWorkerExtHostId,
61
+ error: {
62
+ name: error ? error.name : '',
63
+ message: error ? error.message : '',
64
+ stack: error ? error.stack : []
65
+ }
66
+ }, '*');
67
+ }
68
+
69
+ function start() {
70
+ try {
71
+ let workerUrl = vscodeExtHostWorkerSrc
72
+ if(globalThis.crossOriginIsolated) {
73
+ workerUrl += '?vscode-coi=2'; // COEP
74
+ }
75
+
76
+ const worker = new Worker(workerUrl, Object.assign({ name }, vscodeExtHostWorkerOptions));
77
+ const nestedWorkers = new Map();
78
+
79
+ worker.onmessage = (event) => {
80
+ const { data } = event;
81
+
82
+ if (data?.type === '_newWorker') {
83
+ const { id, port, url, options } = data;
84
+ const newWorker = new Worker(url, options);
85
+ newWorker.postMessage(port, [port]);
86
+ worker.onerror = console.error.bind(console);
87
+ nestedWorkers.set(id, newWorker);
88
+
89
+ } else if (data?.type === '_terminateWorker') {
90
+ const { id } = data;
91
+ if(nestedWorkers.has(id)) {
92
+ nestedWorkers.get(id).terminate();
93
+ nestedWorkers.delete(id);
94
+ }
95
+ } else {
96
+ worker.onerror = console.error.bind(console);
97
+ window.parent.postMessage({
98
+ vscodeWebWorkerExtHostId,
99
+ data
100
+ }, parentOrigin, [data]);
101
+ }
102
+ };
103
+
104
+ worker.onerror = (event) => {
105
+ console.error(event.message, event.error);
106
+ sendError(event.error);
107
+ };
108
+
109
+ self.onmessage = (event) => {
110
+ if (event.origin !== parentOrigin) {
111
+ return;
112
+ }
113
+ worker.postMessage(event.data, event.ports);
114
+ }
115
+ } catch(err) {
116
+ console.error(err);
117
+ sendError(err);
118
+ }
119
+ }
120
+ })();
121
+ </script>
122
+ </body>
123
+ </html>