Skip to content

🔒 [security fix] Use FileProvider to share diagnostic report - #199

Closed
alvin000009238 wants to merge 1 commit into
mainfrom
jules-6987226353436743643-1c7f9ac5
Closed

🔒 [security fix] Use FileProvider to share diagnostic report#199
alvin000009238 wants to merge 1 commit into
mainfrom
jules-6987226353436743643-1c7f9ac5

Conversation

@alvin000009238

Copy link
Copy Markdown
Owner

🎯 What
Updated DeveloperSettingsScreen.kt to share the diagnostic report via a FileProvider using Intent.EXTRA_STREAM and FLAG_GRANT_READ_URI_PERMISSION, instead of passing the plain text in Intent.EXTRA_TEXT.

⚠️ Risk
Previously, the sensitive diagnostic text was passed directly within the intent's EXTRA_TEXT field. Because this was a broad implicit intent (ACTION_SEND with text/plain), any application on the user's device could register a receiver for this intent and potentially intercept the potentially sensitive diagnostic data silently in the background without user consent.

🛡️ Solution
The diagnostic report is now written to a temporary file in the application's internal cache directory (cacheDir/diagnostics). This file is then shared via a FileProvider. By doing so, the Android OS ensures that only the single application the user explicitly selects in the Chooser receives a temporary, revocable FLAG_GRANT_READ_URI_PERMISSION to read the file. This completely eliminates the risk of interception by passive background applications, while fully preserving the user's ability to share the report to any app they choose.


PR created automatically by Jules for task 6987226353436743643 started by @alvin000009238

Co-authored-by: alvin000009238 <107313913+alvin000009238@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings June 17, 2026 15:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the diagnostic sharing feature on Android by writing the diagnostic text to a temporary file and sharing it as a file stream using a FileProvider, rather than passing it as raw text. Feedback was provided to explicitly set the URI in the intent's clipData to ensure that the receiving application is reliably granted read permissions across different Android versions.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines 585 to 590
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)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When sharing a file URI via Intent.ACTION_SEND and Intent.EXTRA_STREAM, setting FLAG_GRANT_READ_URI_PERMISSION alone is often not sufficient on many Android versions. The system grants URI permissions automatically only to the URI in the intent's data field or its clipData. Since ACTION_SEND uses EXTRA_STREAM instead of data, you should explicitly set the URI in clipData to ensure the receiving application is granted read permissions properly.

Suggested change
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)
}
val intent = Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_SUBJECT, "CLHS Score 診斷包")
putExtra(Intent.EXTRA_STREAM, uri)
clipData = ClipData.newRawUri("", uri)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 25360d4db4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +576 to +577
val file = java.io.File(cachePath, "diagnostic_report.txt")
file.writeText(text)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use unique URIs for each diagnostic report

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 👍 / 👎.

@alvin000009238
alvin000009238 deleted the jules-6987226353436743643-1c7f9ac5 branch June 18, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants