-
Notifications
You must be signed in to change notification settings - Fork 0
🔒 [security fix] Use FileProvider to share diagnostic report #199
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -572,10 +572,21 @@ private fun Context.copyText(label: String, text: String) { | |||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| private fun Context.shareText(text: String): Boolean = | ||||||||||||||||||||||||||||||
| runCatching { | ||||||||||||||||||||||||||||||
| val cachePath = java.io.File(cacheDir, "diagnostics").apply { mkdirs() } | ||||||||||||||||||||||||||||||
| val file = java.io.File(cachePath, "diagnostic_report.txt") | ||||||||||||||||||||||||||||||
| file.writeText(text) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| val uri = androidx.core.content.FileProvider.getUriForFile( | ||||||||||||||||||||||||||||||
| this, | ||||||||||||||||||||||||||||||
| "${packageName}.fileprovider", | ||||||||||||||||||||||||||||||
| file | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| val intent = Intent(Intent.ACTION_SEND).apply { | ||||||||||||||||||||||||||||||
| type = "text/plain" | ||||||||||||||||||||||||||||||
| putExtra(Intent.EXTRA_SUBJECT, "CLHS Score 診斷包") | ||||||||||||||||||||||||||||||
| putExtra(Intent.EXTRA_TEXT, text) | ||||||||||||||||||||||||||||||
| putExtra(Intent.EXTRA_STREAM, uri) | ||||||||||||||||||||||||||||||
| addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
585
to
590
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When sharing a file URI via
Suggested change
|
||||||||||||||||||||||||||||||
| startActivity(Intent.createChooser(intent, "分享診斷包")) | ||||||||||||||||||||||||||||||
| }.isSuccess | ||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <paths> | ||
| <cache-path name="shared_diagnostics" path="diagnostics/" /> | ||
| </paths> |
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.
Because every share overwrites the same
diagnostic_report.txt, any app that was previously chosen for a diagnostic share can keep its temporary read grant to this stable FileProvider URI while its receive/share activity remains alive, and then read the contents of a later report that the user shares to someone else. This only affects users who generate/share multiple diagnostic reports before the earlier grant is revoked, but it undermines the intended per-share consent boundary; create a unique file/URI per report and clean up old files instead of reusing this filename.Useful? React with 👍 / 👎.