refactor: replace insecure custom downloader with Down::NetHttp#260
Merged
Conversation
- drop ftp support - Harden repository copy path (OntologySubmission.copy_file_repository) - Normalize src (accept Tempfile or String path) - Sanitize destination filename (strip control/unsafe chars, trim/collapse spaces, remove leading dots, 255-char cap)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #260 +/- ##
===========================================
+ Coverage 80.96% 81.36% +0.40%
===========================================
Files 101 101
Lines 6892 6848 -44
===========================================
- Hits 5580 5572 -8
+ Misses 1312 1276 -36
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…ace Thin in tests - Remove all FTP download logic (check_ftp_file, URI::FTP branch, net-ftp dependency) - Move remote_file_exists? to LinkedData::Utils::FileHelpers and reimplement using Down::NetHttp - Update download_file to use max_redirects keyword for consistency - Remove Thin dependency and add Webrick for test environment
The atomic temp-write refactor renamed dst to dst_final/dst_tmp but two
error-path messages still interpolated #{dst}, which would raise NameError
and mask the real failure in both the rescue branch and the post-copy
sanity check.
File.basename raises ArgumentError on a NUL byte, so sanitize_filename crashed when given a name containing a control byte (reachable via an HTTP Content-Disposition filename). Strip control chars before calling File.basename so the helper sanitizes rather than raises. Add dedicated unit tests in test/util/test_file_helpers.rb covering normal names, unnamed fallback, path/traversal stripping, control and unsafe char removal, whitespace collapsing, and the 255-char cap.
Down::NetHttp.download returns the tempfile already opened at offset 0 (ensure_tempfile finishes with tempfile.open), so the explicit rewind was a no-op.
Replace the hardcoded 512 MB cap with a download_max_file_size setting (default 2 GB) so ops can raise the limit without a code change. The keyword arg still overrides per-call; falls back to the setting when nil.
Down's original_filename already parses Content-Disposition and falls back to the post-redirect URL path basename, and sanitize_filename maps nil/empty to "unnamed". The old || chain's last_iri_fragment branch was unreachable (File.basename never returns nil), so collapse it to a single sanitize_filename(tmpfile.original_filename) call.
…load-and-copy # Conflicts: # Gemfile # Gemfile.lock # lib/ontologies_linked_data/models/ontology_submission.rb # lib/ontologies_linked_data/utils/file.rb # test/models/test_ontology_submission.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
refactor: replace insecure custom downloader with Down::NetHttp
Downloading
download_max_file_sizesetting(default 2 GB), enforced by Down; previously unbounded
Filename hardening
remove leading dots, trim/collapse spaces, 255-char cap, fallback to "unnamed"
Repository copy path (OntologySubmission.copy_file_repository)
Dependencies
down; removenet-ftprack-testfrom a runtime to a development dependencythinwithwebrickfor the test Rack server