-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: Use media directory as the base url of the CardViewers #16140
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
Conversation
|
Should be good to go now |
not necessary anymore
with file:/ scheme
that makes the baseUrl always the same, so `localStorage` works again also loads media with the `file` scheme by default, which is faster
| } else { | ||
| newChunkedResponse(status, mimeType, ByteArrayInputStream(data)) | ||
| }.apply { | ||
| addHeader("Access-Control-Allow-Origin", "*") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[security] Is it feasible to limit this so other apps on-device can't reasonably access the server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried it once but it didn't work immediately. Since my timeblock was gone and this was the same of what 2.16 did, I left it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you feel we should block this PR on this?
- Historically,
collection.media+collection.anki2were publicly accessible.- After 2.16 & scoped storage, we should lock it down so it matches expectations
- We don't want to be listed on the next article in this series: https://www.bellingcat.com/news/2021/05/28/us-soldiers-expose-nuclear-weapons-secrets-via-flashcard-apps/
If we have MANAGE_EXTERNAL_STORAGE, we must not allow access to files outside collection.media, and I would block on this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've extracted this to: #16230
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a look and since the Reviewer now uses file:/// as base url, origin is null so only * can be used as the value of Access-Control-Allow-Origin.
On a quick assessment, only POST requests are allowed. In the reviewer only getSchedulingStatesWithContext and setSchedulingStates are enabled. So, I don't see any danger right now. Card templates and deck options' custom scheduling already can use those methods but aren't considered a security vulnerability
mikehardy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's do this - thanks @BrayanDSO (and David)
Purpose / Description
Loading files with file:/ scheme in much faster in an Android Webview, and that's what 2.15.6 did by setting the Webview base url to the media directory.
But in 2.16/2.17, in order to enable POST requests to be done, the base url was set to localhost and the files were delivered by the server. After noticing that loading files was slower with the server, a WebViewAssetLoader was used, but it was still slower than file:/. The next alternative was parsing the card's HTML to use file:/ for media sources, but that leads to CORS issues and sometimes HTML parsing issues.
So, here's what I believe that should be the definitive solution, which is to remap POST requests base url, so the Webview base url can be set to the media directory so the 2.15.6 behavior is restored.
Fixes
Approach
In the commits
How Has This Been Tested?
Emulator 34:
Tested by adding console.log("foo"); into Custom scheduling deck option then seeing if it appeared in Logcat
Also checked if media, specially videos and audios, were properly loaded
Checklist
Please, go through these checks before submitting the PR.