Refractoring Stage 3 Completed the mail-service refactoring stage and started IPC hardening

This commit is contained in:
2026-10-16 16:57:07 +03:00
parent e398bc4e1a
commit da543d5059
18 changed files with 1344 additions and 520 deletions
+31
View File
@@ -0,0 +1,31 @@
const path = require('node:path');
const { fileURLToPath } = require('node:url');
function isTrustedApplicationUrl(rawUrl, expectedFile) {
let actualFile;
try {
const url = new URL(rawUrl);
if (url.protocol !== 'file:' || url.search || url.hash) {
return false;
}
actualFile = fileURLToPath(url);
} catch {
return false;
}
const expected = path.resolve(expectedFile);
const actual = path.resolve(actualFile);
return process.platform === 'win32'
? actual.toLowerCase() === expected.toLowerCase()
: actual === expected;
}
function assertTrustedIpcSender(event, expectedFile) {
const frame = event?.senderFrame;
if (!frame || !event?.sender || frame !== event.sender.mainFrame ||
!isTrustedApplicationUrl(frame.url, expectedFile)) {
throw new Error('This request must come from the application window.');
}
}
module.exports = { assertTrustedIpcSender, isTrustedApplicationUrl };