Skip to content

Commit

Permalink
fix: removed unnecessary protocol.registerSchemesAsPrivileged(), only…
Browse files Browse the repository at this point in the history
… needed for electron.session.defaultSession and r2-navigator-js.getWebSession() for the special r2https and thoriumhttps custom URL schemes. Added code comments for pdfjs-extract filex and store custom URL schemes to highlight potential filesystem security access (safe, as cannot be accessed via Electron webview that hosts EPUB scripted documents)
  • Loading branch information
danielweck committed Jan 8, 2025
1 parent e9193ba commit 0739830
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 56 deletions.
6 changes: 3 additions & 3 deletions src/main/redux/sagas/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export function* init() {
debug(urlPathDecoded);
const filePathUrl = pathToFileURL(urlPathDecoded).toString();
debug(filePathUrl);
return net.fetch(filePathUrl);
return net.fetch(filePathUrl); // potential security hole: local filesystem access (mitigated by URL scheme not .registerSchemesAsPrivileged() and not .handle() or .registerXXXProtocol() on r2-navigator-js.getWebViewSession().protocol or Electron.session.defaultSession.protocol)
};
protocol.handle("filex", protocolHandler_FILEX);
// protocol.unhandle("filex");
Expand Down Expand Up @@ -174,7 +174,7 @@ export function* init() {
debug(filePath);
const filePathUrl = pathToFileURL(filePath).toString();
debug(filePathUrl);
return net.fetch(filePathUrl);
return net.fetch(filePathUrl); // potential security hole: local filesystem access (mitigated by URL scheme not .registerSchemesAsPrivileged() and not .handle() or .registerXXXProtocol() on r2-navigator-js.getWebViewSession().protocol or Electron.session.defaultSession.protocol)
};
protocol.handle("store", protocolHandler_Store);
// protocol.unhandle("store");
Expand All @@ -197,7 +197,7 @@ export function* init() {
debug(urlPathDecoded);
const filePathUrl = pathToFileURL(urlPathDecoded).toString();
debug(filePathUrl);
return net.fetch(filePathUrl);
return net.fetch(filePathUrl); // potential security hole: local filesystem access (mitigated by URL scheme not .registerSchemesAsPrivileged() and not .handle() or .registerXXXProtocol() on r2-navigator-js.getWebViewSession().protocol or Electron.session.defaultSession.protocol)
};
protocol.handle("pdfjs-extract", protocolHandler_PDF);
// protocol.unhandle("pdfjs-extract");
Expand Down
106 changes: 53 additions & 53 deletions src/main/streamer/streamerNoHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
computeReadiumCssJsonMessageInStreamer, MATHJAX_FILE_PATH, MATHJAX_URL_PATH,
READIUMCSS_FILE_PATH, setupMathJaxTransformer,
} from "./streamerCommon";
import { OPDS_MEDIA_SCHEME } from "readium-desktop/main/redux/sagas/getEventChannel";
// import { OPDS_MEDIA_SCHEME } from "readium-desktop/main/redux/sagas/getEventChannel";
import { THORIUM_READIUM2_ELECTRON_HTTP_PROTOCOL } from "readium-desktop/common/streamerProtocol";
import { findMimeTypeWithExtension } from "readium-desktop/utils/mimeTypes";

Expand Down Expand Up @@ -1139,58 +1139,58 @@ export function initSessions() {
protocol.registerSchemesAsPrivileged([
// HACK!! TODO: FIXME (Electron lifecycle requires this before app.ready, and called only once!)
// see src/main/redux/sagas/getEventChannel.ts
{
privileges: {
allowServiceWorkers: false, // Default false
bypassCSP: false, // Default false
corsEnabled: false, // Default false
secure: true, // Default false
stream: true, // Default false
supportFetchAPI: false, // Default false
standard: false, // Default false
codeCache: false, // Default false (only works with standard=true)
},
scheme: "store",
},
{
privileges: {
allowServiceWorkers: false, // Default false
bypassCSP: true, // Default false
corsEnabled: false, // Default false
secure: true, // Default false
stream: true, // Default false
supportFetchAPI: true, // Default false
standard: true, // Default false
codeCache: false, // Default false (only works with standard=true)
},
scheme: "filex",
},
{
privileges: {
allowServiceWorkers: false, // Default false
bypassCSP: false, // Default false
corsEnabled: false, // Default false
secure: true, // Default false
stream: true, // Default false
supportFetchAPI: false, // Default false
standard: false, // Default false
codeCache: false, // Default false (only works with standard=true)
},
scheme: "pdfjs-extract",
},
{
privileges: {
allowServiceWorkers: false, // Default false
bypassCSP: true, // Default false
corsEnabled: false, // Default false
secure: true, // Default false
stream: true, // Default false
supportFetchAPI: false, // Default false
standard: false, // Default false
codeCache: false, // Default false (only works with standard=true)
},
scheme: OPDS_MEDIA_SCHEME,
},
// {
// privileges: {
// allowServiceWorkers: false, // Default false
// bypassCSP: false, // Default false
// corsEnabled: false, // Default false
// secure: false, // Default false
// stream: false, // Default false
// supportFetchAPI: false, // Default false
// standard: false, // Default false
// codeCache: false, // Default false (only works with standard=true)
// },
// scheme: "store",
// },
// {
// privileges: {
// allowServiceWorkers: false, // Default false
// bypassCSP: false, // Default false
// corsEnabled: false, // Default false
// secure: false, // Default false
// stream: false, // Default false
// supportFetchAPI: false, // Default false
// standard: false, // Default false
// codeCache: false, // Default false (only works with standard=true)
// },
// scheme: "filex",
// },
// {
// privileges: {
// allowServiceWorkers: false, // Default false
// bypassCSP: false, // Default false
// corsEnabled: false, // Default false
// secure: false, // Default false
// stream: false, // Default false
// supportFetchAPI: false, // Default false
// standard: false, // Default false
// codeCache: false, // Default false (only works with standard=true)
// },
// scheme: "pdfjs-extract",
// },
// {
// privileges: {
// allowServiceWorkers: false, // Default false
// bypassCSP: false, // Default false
// corsEnabled: false, // Default false
// secure: false, // Default false
// stream: false, // Default false
// supportFetchAPI: false, // Default false
// standard: false, // Default false
// codeCache: false, // Default false (only works with standard=true)
// },
// scheme: OPDS_MEDIA_SCHEME, // TODO: what about OPDS_AUTH_SCHEME?
// },
{
privileges: {
allowServiceWorkers: false,
Expand Down

0 comments on commit 0739830

Please sign in to comment.