Skip to content

Bugfix/ftpserver harden control permission - #4758

Open
TranceLove wants to merge 6 commits into
hotfix/3.11.4from
bugfix/ftpserver-harden-control-permission
Open

TranceLove wants to merge 6 commits into
hotfix/3.11.4from
bugfix/ftpserver-harden-control-permission

Conversation

@TranceLove

@TranceLove TranceLove commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Hardening fixes

  • Shareable content URIs, for filesystem level access. Those beyond userland filesystem boundaries will be copied to app's cache, then emits shareable content URIs for external apps.
  • FTP server start/stop hardened to allow only apps signed by Amaze to control via Intents with parameters. For external app integrations, there are still new Actions com.amaze.filemanager.action.EXTERNAL_START_FTP and com.amaze.filemanager.action.EXTERNAL_STOP_FTP which takes no arguments - just start and stop signals.

Courtesy of report by Zhang Jinshan 2831737873a@gmail.com thanks!

Automatic tests

  • Added unit tests for specific individual functions
  • Added headless tests for new app functionality

Manual tests

  • Done

  • Device:

  • OS:

Build tasks success

Successfully running following tasks on local:

  • ./gradlew assembledebug
  • ./gradlew spotlessCheck

Generative code

  • This PR used generative code tools (GenAI, LLMs, etc.)

  • Model: Claude Sonnet

  • Version: 5.5

  • Provider: Github Copilot

Follow-up to the FileProvider root-path / pre-grant hardening. With
root-path narrowed to storage/ and mnt/media_rw/, files elsewhere (eg.
/data, root-only files) no longer get a provider URI, so opening,
sharing, picking and installing them would throw.

Changes:
- Add FileUtils.getShareableUri(): returns the provider URI when the
  path is covered, otherwise copies the file into cache/open_with/<uuid>/
  and returns the URI of the copy. Root-only files are read through
  SuFileInputStream and written by the app itself, so the copy carries
  the app's own SELinux label/ownership (no root cp/chmod). Copies older
  than 24 hours are purged.
- Add getShareableUriAsync() (RxJava Maybe): copying runs on the IO
  scheduler, shows the "Copying" toast, result delivered on main thread.
- Add ShareCopyException; copy failures show copy_error toast, files
  that cannot be shared at all keep showing no_app_found.
- Use the async helper in openFile, openWith(File), shareFiles,
  installApk and MainFragment.returnIntentResults (picker).
- fromContentUri() maps storage_root/ -> /storage/ and
  media_rw_root/ -> /mnt/media_rw/, keeping legacy URI fallback; the
  database viewer path extra now uses it.
- Tests in FileUtilsTest for URI mapping, cache copy, name collisions,
  async scheduling/toast and root copy failure cleanup.

Grants stay READ-only everywhere, so external editors cannot write back
to the original file; this is intentional (strictest, per the report).
@TranceLove
TranceLove force-pushed the bugfix/ftpserver-harden-control-permission branch 2 times, most recently from 720fdfc to 844a1a9 Compare November 6, 2026 11:48
Make CONTROL_FTP_SERVER signature-only and add CONTROL_FTP_SERVER_SIMPLE
(dangerous) guarding a new FtpExternalControlReceiver that only starts or
stops the server with saved settings and never forwards intent extras.
@TranceLove
TranceLove force-pushed the bugfix/ftpserver-harden-control-permission branch from 844a1a9 to 8c96a75 Compare November 6, 2026 12:16
@TranceLove
TranceLove marked this pull request as ready for review November 6, 2026 12:22
@TranceLove
TranceLove requested review from EmmanuelMess, VishalNehra and VishnuSanal and a balanced review from Copilot November 6, 2026 12:23

Copilot AI 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.

🟡 Changes recommended

Worker-thread toasts crash file operations, while temporary-copy URIs prevent the internal editor from saving changes to original files.

5 open issues
What changed in this PR

This PR hardens Amaze’s file sharing and FTP server controls by narrowing exposed filesystem paths and separating trusted, parameterized FTP commands from third-party start/stop signals.

Changes:

  • Restricts FileProvider roots and adds asynchronous cache-copy fallbacks for files outside them.
  • Protects legacy FTP controls with a signature permission and adds permission-gated external actions that ignore extras.
  • Removes blanket URI grants, adds regression tests, and raises CI inotify limits.
File Description
app/​src/​test/​java/​com/​amaze/​filemanager/​utils/​UtilsTest.java Updates the expected storage URI.
app/​src/​test/​java/​com/​amaze/​filemanager/​filesystem/​files/​FileUtilsTest.kt Tests URI mapping, cache copies, failures, and read-only intent flags.
app/​src/​test/​java/​com/​amaze/​filemanager/​asynchronous/​services/​ftp/​FtpExternalControlReceiverTest.kt Tests external actions, ignored extras, and manifest permissions.
app/​src/​main/​res/​xml/​provider_paths.xml Narrows filesystem exposure and adds the sharing cache root.
app/​src/​main/​res/​values/​strings.xml Describes the external FTP control permission.
app/​src/​main/​java/​com/​amaze/​filemanager/​utils/​Utils.java Uses shareable URIs for local and root files.
app/​src/​main/​java/​com/​amaze/​filemanager/​ui/​fragments/​MainFragment.java Resolves picker result URIs in the background.
app/​src/​main/​java/​com/​amaze/​filemanager/​ui/​dialogs/​OpenFileDialogFragment.kt Removes blanket read/write grants to matching apps.
app/​src/​main/​java/​com/​amaze/​filemanager/​filesystem/​files/​FileUtils.java Adds cache-backed sharing, asynchronous preparation, and URI mapping.
app/​src/​main/​java/​com/​amaze/​filemanager/​asynchronous/​services/​ftp/​FtpService.kt Defines external FTP action constants and reformats existing code.
app/​src/​main/​java/​com/​amaze/​filemanager/​asynchronous/​services/​ftp/​FtpReceiver.kt Refactors legacy action handling and logging.
app/​src/​main/​java/​com/​amaze/​filemanager/​asynchronous/​services/​ftp/​FtpExternalControlReceiver.kt Handles external start/stop signals without forwarding extras.
app/​src/​main/​AndroidManifest.xml Declares separate FTP permissions and registers the external receiver.
.github/​workflows/​android-main.yml Raises inotify limits for unit tests.
.github/​workflows/​android-feature.yml Raises inotify limits for unit tests.

Review effort: Balanced

}
return uris;
})
.subscribeOn(Schedulers.io())
-->
<root-path path="." name="storage_root" />
</paths> No newline at end of file
<root-path path="storage/" name="storage_root" />
@TranceLove
TranceLove force-pushed the bugfix/ftpserver-harden-control-permission branch from e42fe94 to a7c5236 Compare November 6, 2026 14:42
@TranceLove
TranceLove requested a balanced review from Copilot November 13, 2026 01:21

Copilot AI 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.

🟡 Changes recommended

Chooser and open-as flows still lose original file URIs, causing editor saves to modify cache copies instead of source files, while synchronous log copying can freeze the UI.

6 open issues
3 resolved since last review

Review effort: Balanced

VishnuSanal and others added 3 commits November 30, 2026 00:38
Signed-off-by: VishnuSanal <t.v.s10123@gmail.com>
- Preserved original URIs through Open As and chooser app launches
- Moved About log sharing to asynchronous cache preparation
- Added async email-intent construction and updated feedback/crash-report flows
@TranceLove
TranceLove force-pushed the bugfix/ftpserver-harden-control-permission branch from 5000baf to fa121f3 Compare December 1, 2026 10:43
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.

3 participants