-
Notifications
You must be signed in to change notification settings - Fork 309
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
refactor: Drop submission validation via libmagic #6500
Merged
Merged
Conversation
This file contains 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
The mime check distinguished us-ascii from UTF-8, but as far as I can tell the code relying on it treated both as equally valid.
Codecov Report
@@ Coverage Diff @@
## main #6500 +/- ##
==========================================
- Coverage 88.70% 88.70% -0.01%
==========================================
Files 290 290
Lines 40440 40429 -11
==========================================
- Hits 35874 35862 -12
- Misses 4566 4567 +1
|
rjsparks
approved these changes
Oct 23, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This drops content type detection that ultimately depends on the system's libmagic to guess the content type of an uploaded submission. This has proven unreliable on some platforms (notably production). Instead, this relies on the text / XML parsers to reject files that do not conform to their formats.
The detection had a side effect of guessing the character encoding used by the uploaded file, which was used to determine whether the file was "us-ascii" or UTF-8. As far as I can tell, the two were handled separately only to account for libmagic's preference to report "us-ascii" when possible. I've implemented a validator that rejects submissions that include invalid UTF-8 encodings, reporting the first problematic byte and its position in the file back to the user.
At least some invalid files that were previously screened out by the content type detection cause
xml2rfc
to raise anXMLSyntaxError
exception that was unhandled. These changes catch that exception and turn it into an error message hinting that the wrong file format may have been submitted. In particular, attempting to upload a text-format draft where the form expects XML hits this.