Update renderer.js

This commit is contained in:
Anirudh Sevugan 2025-02-27 21:57:13 +05:30 committed by GitHub
parent 0304d68187
commit 3b6be1434b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,8 +1,3 @@
// Listen for media file URL from main process
window.electron.receive("play-media", (fileURL) => {
loadMedia(fileURL);
});
function loadMedia(fileURL) {
dialogOverlay.style.display = 'none';
const mediaElement = document.getElementById("mediaPlayer");
@ -18,3 +13,23 @@ function loadMedia(fileURL) {
};
}
}
// Validate media URL
function isSafeURL(fileURL) {
try {
const url = new URL(fileURL);
return url.protocol === "file:";
} catch (error) {
return false;
}
}
// ✅ Listen for "play-media" event from main process securely
window.electron.receive("play-media", (fileURL) => {
if (isSafeURL(fileURL)) {
loadMedia(fileURL);
} else {
console.warn("Blocked unsafe media URL:", fileURL);
}
});