Skip to content

Commit 02d2d7e

Browse files
committed
Handle missing bridge port and path mapping
Main: add a guard that logs and returns if the bridge port is unavailable, avoiding attempts to load the renderer URL with an undefined port. Bridge module: when a route isn't mapped, join the requested pathname with the server cwd and normalize it (instead of always resolving) before the isUnderRootAsync check. This ensures paths are handled consistently and prevents incorrect resolution/permissions checks that could allow escapes from the expected root.
1 parent 243e392 commit 02d2d7e

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

www/nodejs/main.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,10 @@ const initElectronWindow = async () => {
719719
console.error('❌ Bridge ready error:', err)
720720
return
721721
}
722+
if (!port) {
723+
console.error('❌ Bridge port unavailable, cannot load renderer')
724+
return
725+
}
722726
console.log('🌉 Bridge ready, loading URL on port:', port)
723727
window.loadURL('http://127.0.0.1:'+ port +'/renderer/electron.html', { userAgent: renderer.ui.ua })
724728
window.setAlwaysOnTop(true) // trick to take focus

www/nodejs/modules/bridge/bridge.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ class BridgeServer extends EventEmitter {
131131
if (typeof (this.map[pathname]) != 'undefined') {
132132
pathname = this.map[pathname]
133133
mapped = true
134+
} else {
135+
pathname = path.join(paths.cwd, pathname)
134136
}
135-
pathname = path.resolve(paths.cwd, pathname)
137+
pathname = path.normalize(pathname)
136138
if (!pathname || (!mapped && !await isUnderRootAsync(pathname, paths.cwd))) {
137139
response.statusCode = 403;
138140
response.end();

0 commit comments

Comments
 (0)