-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: test access to host context, window.[top|parent], window.frameElement.ownerDocument.defaultView #1
Comments
Thanks for the suggestion! Very good points.
But with |
Yes indeed. Advance warning: sorry for the long blurb below, but I've just discovered your work at https://github.com/johnfactotum/foliate (which is great!), so I thought you'd be interested in the nitty-gritty details :) So, from experience, I know that Reading System "engines" like EPUB.js, Readium, etc. can be integrated in native apps (typically iOS and Android, but also Linux / Windows / Mac desktop application wrappers), in which case a native When developing for Readium (several years ago now), we found that the More recently, we used Electron APIs to solve this problem, notably a subsystem to handle custom URL protocols, with IPC to communicate across the isolated process boundaries, and Electron's Ideally the Reading System would exchange information with We experimented with this on the "server side" (either a proper HTTP server running in a local app, or a custom URL protocol handler), via Service Workers on the client side (which requires HTTPS and imposes lifecycle and Finally, there is one additional aspect related to security: when publication resources are served from the same web origin (i.e. same localhost IP + HTTP port), they inherit identical privileges / credentials to origin-scoped APIs such as |
Thanks for the detailed reply. What I've done recently in Foliate is to add |
Examples of how a malicious ebook could hijack the context that hosts publication documents' frames:
window.parent.document.body.innerHTML = "<a href="http://evil.com">click me</a>";
window.frameElement.ownerDocument.defaultView.location = "http://evil.com";
window.top.document.querySelectorAll("a").forEach((el) => {el.setAttribute("href", "http://evil.com")} );
(a real-world use case would of course be more sophisticated, for example storing/exploiting data in
localStorage
, installing persistent behaviours like keyboard event listeners, etc.)So, my suggestion is to add tests in https://github.com/johnfactotum/epub-test/blob/master/epub-test/EPUB/section1.xhtml such as: making sure that
window.[top|parent]
is not equal towindow
/window.self
, and then see if the host context can be hijacked by injecting "foreign" content (as per the trivial examples above, or something that fits better with the existing testing pattern / methodology).Note that reading systems can effectively protect themselves against this kind of attack by using proper
iframe
sandboxing in addition to setting up adequate Content Security Policy, however overridingwindow.parent = window.self; window.top = window.self;
usually doesn't work because the properties are read-only, and also becausewindow.frameElement.ownerDocument.defaultView
remains a totally open attack vector anyway.The text was updated successfully, but these errors were encountered: