-
Notifications
You must be signed in to change notification settings - Fork 41
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
Proposal: Send battery level to JS #48
base: main
Are you sure you want to change the base?
Conversation
I know you are working on a JS API, and I'm not expecting this to be merged. I'm simply proposing that receiving battery level information is part of this API, and this PR is one way of fetching this. To read the battery-level, the used web page need to define a `window.SEB = {}`, and then poll window.SEB.battery with a reasonable interval to see if battery data has been received.
Hi Martin, I first should focus on finalizing the WKWebView implementation, releasing the iOS version (as there some other issues addressed) and merging the code into the macOS version. But I will definitely implement such a battery level feature (maybe in addition als a callback function, so polling wouldn't be necessary). Here the info for the iOS beta (which you probably already got): New in build 12917:
New in build 12865:
Cheers, Daniel |
Thank you for the feedback and I'm glad to hear of the new additions. I looked quickly at the code and some small questions/comments:
|
I'm really a looser when it comes to JS. I actually did some internet search and trial-and-error to achieve what I wanted (until it worked somehow). But I was inspired by the Smarter Balanced (SB) exam consortium's Secure Browser API (which I would like to support in a later version of SEB as well). I kinda like that they expose a global object SecureBrowser and use such namespaces (or however that would be called in JS) like .security. I would for example imagine to use something like
Thanks for your input, that's highly appreciated! |
There are definitely many different ways to achieve the same thing in JS, and it really doesn't matter except for the developer (only you in this case). The simplest way to achieve what I think you're after is something like the following: window.SafeExamBrowser = {
version: 'app-version',
system: {
batteryLevel: 'value that is updated, or some callback based solution to avoid polling'
},
security: {
browserExamKey: 'value',
configKey: 'value',
lockDown: function (enable, onSuccess, onError) {
// pass message to SEB and read response, and trigger correct callback
}
}
} Then the web app can call But of course, if there is a standard to follow, you should conform to that. |
For the XSS question, XHR doesn't have to be involved. If the exam portal page has an XSS vulnerability (which is of course their responsibility to prevent), then a student could read the BEK and CK and even post to themselves inside of the system (or send away using XHR), but of course if the URL or config file is unique to the session, it probably doesn't do any harm. |
Your JS code definitely looks cleaner, I will try it like that, although I thought that I tried it similarly and that it didn't work (maybe the injection into the WKWebView behaves differently as if it would be part of the webpage code?). I guess I didn't understand that XSS attack scenario fully. The thing is: You cannot derive the original BEK/CK values by just getting the hashes which are exposed in a webpage. Those are the hashes of the BEK/CK sha256 with the page URL. You cannot derive the original value of one component of a hashed value even if you have the other component (the URL). You could only generate fake values for SafeExamBrowser.security.browserExamKey and SafeExamBrowser.security.configKey |
I had to change the API methods for reading the Browser Exam and Config Keys, as I wasn't able to inject the hash values into web pages so they could be read reliably while the page is loaded (after some changes it worked on the first load of the page, but not when reloading the page). The reason was that the injection from the native code with evaluateJavaScript() is asynchronous. Therefore now first a function must be called and the values can be read in a callback function (see description below). I hope that this will work in real web applications. I already found out that it seems to be quite complicated to call JS/read JS objects from PHP code, I will discuss how feasible this is for example in the SEB Moodle plugin. New in build 12996:
|
I know you are working on a JS API, and I'm not expecting this to be merged. I'm simply proposing that receiving battery level information will be part of this API, and this PR is one way of fetching this.
To read the battery-level, the used web page need to define a
window.SEB = {}
, and then poll window.SEB.battery with a reasonable interval to see if battery data has been received.