Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Prevent navigation out of initial origin #436

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend/main.development.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ app.on('ready', () => {
mainWindow.openDevTools();
}

// prevent navigation out of HTTP_URL
// see https://electronjs.org/docs/api/web-contents#event-will-navigate
mainWindow.webContents.on('will-navigate', (event, url) => {
if (!url.startsWith(HTTP_URL)) event.preventDefault();
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

mainWindow.on('closed', () => {
mainWindow = null;
});
Expand Down
14 changes: 12 additions & 2 deletions backend/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,21 @@ export default class Servers {
server.use(restify.queryParser());
server.use(restify.bodyParser({mapParams: true}));
server.pre(function (request, response, next) {
Logger.log(`Request: ${request.href()}`, 2);
const href = request.href();
const skip =
href.startsWith('/settings/urls') ||
href.startsWith('/static') ||
href.startsWith('/images');
if (!skip) Logger.log(`Request: ${href}`, 2);
next();
});
server.use(function (request, response, next) {
Logger.log(`Response: ${request.href()}`, 2);
const href = request.href();
const skip =
href.startsWith('/settings/urls') ||
href.startsWith('/static') ||
href.startsWith('/images');
if (!skip) Logger.log(`Response: ${href}`, 2);
next();
});

Expand Down