-
Notifications
You must be signed in to change notification settings - Fork 748
fix: prevent mixed content in SFTP/FTP cached files #1815
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
base: main
Are you sure you want to change the base?
fix: prevent mixed content in SFTP/FTP cached files #1815
Conversation
- Improve hashCode() to produce 48-char hex (192-bit) output using FNV-1a inspired multi-pass algorithm - SFTP: Use "wt" mode in openOutputStream() to truncate before write - FTP: Explicitly delete cache file before writing new content - FTP: Refactor to try-with-resources for proper stream handling Fixes Acode-Foundation#1436 , Acode-Foundation#1470 , Acode-Foundation#1740
Greptile OverviewGreptile SummaryThis PR addresses mixed content issues in FTP/SFTP cached files through three main changes: Hash Algorithm EnhancementThe SFTP Cache TruncationThe SFTP plugin now uses FTP Resource Management & Cache ClearingThe FTP plugin was refactored to use try-with-resources for proper stream handling in both Confidence Score: 2/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant JS as JavaScript (FTP/SFTP)
participant Hash as String.hashCode()
participant Java as FTP/SFTP Plugin
participant Cache as Cache Storage
participant Remote as FTP/SFTP Server
User->>JS: Open remote file
JS->>Hash: Generate cache filename from URL
Note over Hash: OLD: 32-bit hash<br/>NEW: 192-bit (48-char hex)
Hash-->>JS: Cache filename
alt FTP Download
JS->>Java: downloadFile(remoteFile, cacheFile)
Java->>Cache: Delete existing cache file
Java->>Remote: retrieveFileStream(path)
Remote-->>Java: InputStream
Java->>Java: NEW: try-with-resources<br/>opens FileOutputStream
Java->>Cache: Write to cache file
Java->>Remote: completePendingCommand()
Java-->>JS: Success
else SFTP Download
JS->>Java: getFile(remoteFile, cacheFile)
Java->>Remote: getInputStream(filename)
Remote-->>Java: InputStream
Java->>Cache: NEW: openOutputStream(uri, "wt")<br/>truncates before write
Java->>Cache: Write to cache file
Java-->>JS: Success
end
JS-->>User: Display file content from cache
|
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
|
Preview Release for this, has been built. |
|
Apk is available , test it out and let me know |
This comment was marked as resolved.
This comment was marked as resolved.
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.
4 files reviewed, 4 comments
| if (inputStream == null) { | ||
| Log.d( | ||
| "FTP", | ||
| "FTPClient (" + ftpId + ") path: " + path + " - not found" | ||
| ); | ||
| callback.error("File not found."); | ||
| return; | ||
| } |
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.
When inputStream is null, the method returns early without calling ftp.completePendingCommand(). According to Apache Commons Net FTP documentation, completePendingCommand() must be called after using streaming methods like retrieveFileStream() to complete the FTP transaction, even if the stream is null.
Without calling completePendingCommand(), the FTP connection may be left in an inconsistent state, potentially causing subsequent FTP operations to fail or hang.
Consider checking for null before entering the try-with-resources block, or calling completePendingCommand() in a finally block to ensure it always executes.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugins/ftp/src/android/com/foxdebug/ftp/Ftp.java
Line: 606:613
Comment:
When `inputStream` is null, the method returns early without calling `ftp.completePendingCommand()`. According to Apache Commons Net FTP documentation, `completePendingCommand()` must be called after using streaming methods like `retrieveFileStream()` to complete the FTP transaction, even if the stream is null.
Without calling `completePendingCommand()`, the FTP connection may be left in an inconsistent state, potentially causing subsequent FTP operations to fail or hang.
Consider checking for null before entering the try-with-resources block, or calling `completePendingCommand()` in a finally block to ensure it always executes.
How can I resolve this? If you propose a fix, please make it concise.| if (outputStream == null) { | ||
| callback.error("File not found."); | ||
| return; | ||
| } |
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.
When outputStream is null, the method returns early without calling ftp.completePendingCommand(). According to Apache Commons Net FTP documentation, completePendingCommand() must be called after using streaming methods like storeFileStream() to complete the FTP transaction.
Without calling completePendingCommand(), the FTP connection may be left in an inconsistent state, potentially causing subsequent FTP operations to fail or hang.
Consider checking for null before entering the try-with-resources block, or ensuring completePendingCommand() is called in a finally block.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/plugins/ftp/src/android/com/foxdebug/ftp/Ftp.java
Line: 692:695
Comment:
When `outputStream` is null, the method returns early without calling `ftp.completePendingCommand()`. According to Apache Commons Net FTP documentation, `completePendingCommand()` must be called after using streaming methods like `storeFileStream()` to complete the FTP transaction.
Without calling `completePendingCommand()`, the FTP connection may be left in an inconsistent state, potentially causing subsequent FTP operations to fail or hang.
Consider checking for null before entering the try-with-resources block, or ensuring `completePendingCommand()` is called in a finally block.
How can I resolve this? If you propose a fix, please make it concise.
Fixes #1436 , #1470 , #1740 , #1735