Skip to content

Commit 6cfdcb6

Browse files
committed
Trust by host instead of origin, and fix persistence for ws:// and wss://
Closes TurboWarp#1044
1 parent 639a018 commit 6cfdcb6

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/containers/tw-security-manager.jsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ const isTrustedExtension = url => (
3434
);
3535

3636
/**
37-
* Set of fetch resource origins that were manually trusted by the user.
37+
* Set of fetch resource hosts that were manually trusted by the user.
3838
* @type {Set<string>}
3939
*/
40-
const fetchOriginsTrustedByUser = new Set();
40+
const fetchHostsTrustedByUser = new Set();
4141

4242
/**
43-
* Set of origins manually trusted by the user for embedding.
43+
* Set of hosts manually trusted by the user for embedding.
4444
* @type {Set<string>}
4545
*/
46-
const embedOriginsTrustedByUser = new Set();
46+
const embedHostsTrustedByUser = new Set();
4747

4848
/**
4949
* @param {URL} parsed Parsed URL object
@@ -293,16 +293,21 @@ class TWSecurityManagerComponent extends React.Component {
293293
return true;
294294
}
295295
const {showModal, releaseLock} = await this.acquireModalLock();
296-
const origin = (parsed.protocol === 'http:' || parsed.protocol === 'https:') ? parsed.origin : null;
297-
if (origin && fetchOriginsTrustedByUser.has(origin)) {
296+
const host = (
297+
parsed.protocol === 'http:' ||
298+
parsed.protocol === 'https:' ||
299+
parsed.protocol === 'ws:' ||
300+
parsed.protocol === 'wss:'
301+
) ? parsed.host : null;
302+
if (host && fetchHostsTrustedByUser.has(host)) {
298303
releaseLock();
299304
return true;
300305
}
301306
const allowed = await showModal(SecurityModals.Fetch, {
302307
url
303308
});
304-
if (origin && allowed) {
305-
fetchOriginsTrustedByUser.add(origin);
309+
if (host && allowed) {
310+
fetchHostsTrustedByUser.add(host);
306311
}
307312
return allowed;
308313
}
@@ -401,15 +406,15 @@ class TWSecurityManagerComponent extends React.Component {
401406
if (!parsed) {
402407
return false;
403408
}
404-
const origin = (parsed.protocol === 'http:' || parsed.protocol === 'https:') ? parsed.origin : null;
409+
const host = (parsed.protocol === 'http:' || parsed.protocol === 'https:') ? parsed.host : null;
405410
const {showModal, releaseLock} = await this.acquireModalLock();
406-
if (origin && embedOriginsTrustedByUser.has(origin)) {
411+
if (host && embedHostsTrustedByUser.has(host)) {
407412
releaseLock();
408413
return true;
409414
}
410415
const allowed = await showModal(SecurityModals.Embed, {url});
411-
if (origin && allowed) {
412-
embedOriginsTrustedByUser.add(origin);
416+
if (host && allowed) {
417+
embedHostsTrustedByUser.add(host);
413418
}
414419
return allowed;
415420
}

0 commit comments

Comments
 (0)