-
Notifications
You must be signed in to change notification settings - Fork 2
Rework mime type white list #2198
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
Open
Tschuppi81
wants to merge
60
commits into
master
Choose a base branch
from
feature/ogc-2738-pentest-arbitrary-file-upload
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
60 commits
Select commit
Hold shift + click to select a range
8699bc1
Rework mime type white list
Tschuppi81 66ac404
Ensure mime type validator for file fields in formcode
Tschuppi81 5ebe0fb
Adds mime type validator by default
Tschuppi81 9416abf
Merge branch 'master' into feature/ogc-2738-pentest-arbitrary-file-up…
Tschuppi81 7eed62a
Fix wrongly attached validators
Tschuppi81 4ab42df
Revert
Tschuppi81 cf252e2
improve tests and fix linter issues
Tschuppi81 6e9afd6
Rework tests
Tschuppi81 3f718d2
Fix file size validator and align
Tschuppi81 5572020
Set mime types for all upload fields
Tschuppi81 a6bd385
Merge branch 'master' into feature/ogc-2738-pentest-arbitrary-file-up…
Tschuppi81 1293c8e
Fix missing validator
Tschuppi81 af685f5
Cleanup unused import
Tschuppi81 a50f6f0
Add fixme
Tschuppi81 458a82d
Fix linting errors
Tschuppi81 8d99429
Extend test
Tschuppi81 c31d0e3
Fix more linter issues
Tschuppi81 eee980c
Remove validators from field list
Tschuppi81 248819a
Add old ms office doc types
Tschuppi81 5621994
Remove non-standard svg type
Tschuppi81 21274d1
Update supported image mime type
Tschuppi81 c4a1eef
Remove unused json validator
Tschuppi81 e77bc49
Pass validators only to FieldList and introduce allowed mime types
Tschuppi81 9a6a187
Adjust tests
Tschuppi81 d122951
Fix wrong default value for UploadField
Tschuppi81 1e7b28b
Fix linter issues
Tschuppi81 427563e
Limit event import to excel kind of files
Tschuppi81 fa438e0
Improve validator type
Tschuppi81 0f7b210
Verify file type for file collection upload
Tschuppi81 e5552d6
Adjust tests
Tschuppi81 a545477
Set default mime type white list for translator directory as well
Tschuppi81 5f7bcb2
Revert "Verify file type for file collection upload"
Tschuppi81 5c54c06
Make unsupported media type error visible on files view
Tschuppi81 f839024
Align upload columns with already uploaded files
Tschuppi81 ef4b1fe
Merge branch 'master' into feature/ogc-2738-pentest-arbitrary-file-up…
Tschuppi81 789e503
Ensure required value error is shown for multiple upload widget
Tschuppi81 f6f9d7c
Extend tests with required upload field
Tschuppi81 c170834
Fix syntax error
Tschuppi81 00b1614
Extend tests
Tschuppi81 0e9c164
Merge master
Tschuppi81 a7a000f
Let's simplify this again, since it doesn't need to work on a FieldLi…
Tschuppi81 2511b0b
Revert changing mimetypes for PIL
Tschuppi81 9d9a819
Merge branch 'feature/ogc-2738-pentest-arbitrary-file-upload' of gith…
Tschuppi81 15d752d
Change back to StrictFileDict for UploadField
Tschuppi81 44c347b
Extend FileSizeLimit for UploadMultipleField
Tschuppi81 03aa665
Move mimetype validation into post validation step
Tschuppi81 8a8b6d0
Fix mimtypes type
Tschuppi81 e313a24
Fix mimtypes type
Tschuppi81 d4eabb6
Adjust for election day and swissvotes
Tschuppi81 5b4cfa5
Minor changes and cleanup
Tschuppi81 85084a5
Fix wrong mimetypes
Tschuppi81 7be6af8
Move swissvotes post validation to a later point
Tschuppi81 01b0af2
Fix some linter issues
Tschuppi81 0b047e1
Linter: Revert back to Collection, remove obsolete post validate
Tschuppi81 20b5c85
Revert "Fix some linter issues"
Tschuppi81 f92840a
Fixes most linter issues
Tschuppi81 39b3ce0
Fix wrong type
Tschuppi81 4b21d7d
Fix more linter issues
Tschuppi81 e6422d5
Resolves rest of linter issues
Tschuppi81 0ca7d5a
Resolve linter issues in tests
Tschuppi81 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,7 @@ | |
| from onegov.file.utils import IMAGE_MIME_TYPES_AND_SVG | ||
| from onegov.form import log, _ | ||
| from onegov.form.utils import path_to_filename | ||
| from onegov.form.validators import ValidPhoneNumber | ||
| from onegov.form.validators import ValidPhoneNumber, WhitelistedMimeType | ||
| from onegov.form.widgets import ChosenSelectWidget | ||
| from onegov.form.widgets import LinkPanelWidget | ||
| from onegov.form.widgets import DurationInput | ||
|
|
@@ -260,6 +260,7 @@ class UploadField(FileField): | |
| action: Literal['keep', 'replace', 'delete'] | ||
| file: IO[bytes] | None | ||
| filename: str | None | ||
| validators = [WhitelistedMimeType()] | ||
Tschuppi81 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if TYPE_CHECKING: | ||
| def __init__( | ||
|
|
@@ -448,6 +449,7 @@ def _add_entry(self, d: _MultiDictLikeWithGetlist, /) -> UploadField: | |
|
|
||
| upload_field_class: type[UploadField] = UploadField | ||
| upload_widget: Widget[UploadField] = UploadWidget() | ||
| validators = [WhitelistedMimeType()] | ||
|
||
|
|
||
| def __init__( | ||
| self, | ||
|
|
@@ -479,11 +481,11 @@ def __init__( | |
|
|
||
| # a lot of the arguments we just pass through to the subfield | ||
| unbound_field = self.upload_field_class( | ||
| validators=validators, # type:ignore[arg-type] | ||
| filters=filters, | ||
| description=description, | ||
| widget=upload_widget, | ||
| render_kw=render_kw, | ||
| validators=validators, # type:ignore[arg-type] | ||
| **extra_arguments | ||
| ) | ||
| super().__init__( | ||
|
|
@@ -496,6 +498,7 @@ def __init__( | |
| widget=widget, # type:ignore[arg-type] | ||
| render_kw=render_kw, | ||
| name=name, | ||
| validators=validators, | ||
Tschuppi81 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _form=_form, | ||
| _prefix=_prefix, | ||
| _translations=_translations, | ||
|
|
||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.