Skip to content

Commit 2a5cec7

Browse files
committed
fix: add necessary iframe attributes for co isolation
1 parent 1579cbc commit 2a5cec7

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

package-lock.json

+24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/backend/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"string-length": "^6.0.0",
6767
"svgo": "^3.0.2",
6868
"tiktoken": "^1.0.11",
69+
"ua-parser-js": "^1.0.38",
6970
"uglify-js": "^3.17.4",
7071
"uuid": "^9.0.0",
7172
"validator": "^13.9.0",

src/backend/src/services/PuterHomepageService.js

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class PuterHomepageService extends BaseService {
109109
short_description: config.short_description,
110110
long_description: config.long_description,
111111
disable_temp_users: config.disable_temp_users,
112+
co_isolation_enabled: req.co_isolation_enabled,
112113
},
113114
}));
114115
}

src/backend/src/services/WebServerService.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,29 @@ class WebServerService extends BaseService {
357357
app.use(helmet.xssFilter());
358358
// app.use(helmet.referrerPolicy());
359359
app.disable('x-powered-by');
360+
361+
const uaParser = require('ua-parser-js');
362+
app.use(function (req, res, next) {
363+
const ua_header = req.headers['user-agent'];
364+
const ua = uaParser(ua_header);
365+
req.ua = ua;
366+
console.log('\x1B[26;1m===== UA =====\x1B[0m', ua);
367+
next();
368+
});
369+
370+
app.use(function (req, res, next) {
371+
req.co_isolation_enabled =
372+
['Chrome', 'Edge'].includes(req.ua.browser.name)
373+
&& (Number(req.ua.browser.major) >= 110);
374+
next();
375+
});
360376

361377
app.use(function (req, res, next) {
362378
const origin = req.headers.origin;
363379

364380
const is_site = req.hostname.endsWith(config.static_hosting_domain);
381+
382+
const co_isolation_okay = is_site || req.co_isolation_enabled;
365383

366384
if ( req.path === '/signup' || req.path === '/login' ) {
367385
res.setHeader('Access-Control-Allow-Origin', origin ?? '*');
@@ -392,7 +410,7 @@ class WebServerService extends BaseService {
392410
// NOTE: This is put behind a configuration flag because we
393411
// need some experimentation to ensure the interface
394412
// between apps and Puter doesn't break.
395-
if ( config.cross_origin_isolation && is_site ) {
413+
if ( config.cross_origin_isolation && co_isolation_okay ) {
396414
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
397415
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
398416
}

src/gui/src/UI/UIWindow.js

+4
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,10 @@ async function UIWindow(options) {
323323
frameborder="0"
324324
${options.iframe_url ? 'src="'+ html_encode(options.iframe_url)+'"' : ''}
325325
${options.iframe_srcdoc ? 'srcdoc="'+ html_encode(options.iframe_srcdoc) +'"' : ''}
326+
${window.co_isolation_enabled
327+
? 'credentialless allow="cross-origin-isolated" '
328+
: ''
329+
}
326330
allow = "accelerometer; camera; encrypted-media; gamepad; display-capture; geolocation; gyroscope; microphone; midi; clipboard-read; clipboard-write; fullscreen;"
327331
allowtransparency="true"
328332
allowpaymentrequest="true"

src/gui/src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ window.gui = async function(options){
5656
window.max_item_name_length = options.max_item_name_length ?? 500;
5757
window.require_email_verification_to_publish_website = options.require_email_verification_to_publish_website ?? true;
5858
window.disable_temp_users = options.disable_temp_users ?? false;
59+
window.co_isolation_enabled = options.co_isolation_enabled;
5960

6061
// DEV: Load the initgui.js file if we are in development mode
6162
if(!window.gui_env || window.gui_env === "dev"){

0 commit comments

Comments
 (0)