-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Allow mime types to match based off of prefix #3617
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
Conversation
The preference here would be to evaluate the rules with pattern matching. Is there a globbing/pattern matching API gitea already uses elsewhere we could simply call to evaluate the match? |
@thehowI is a copycat trying to impersonate me; don't mind them |
How about if t == "*/*" || t == fileType || strings.HasPrefix(t, fileType+" charset=") |
@lunny that would work, if it's only to address the text charset issue. It wouldn't support adding a class like |
The issue with the @thehowl impersonation nonsense derailed the question I was asking:
I imagine you do use wildcards somewhere else in the code and that can just be plugged in here? |
Codecov Report
@@ Coverage Diff @@
## master #3617 +/- ##
==========================================
+ Coverage 23% 23.02% +0.01%
==========================================
Files 126 126
Lines 24894 24894
==========================================
+ Hits 5728 5731 +3
+ Misses 18289 18287 -2
+ Partials 877 876 -1
Continue to review full report at Codecov.
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions. |
It is still pending feedback from maintainers. |
I would propose use wildcard matching (golang has function for this) |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs during the next 2 months. Thank you for your contributions. |
@mqudsi can you resolve confilct? |
The old behavior prevented simple file types like `text/plain` from being uploaded since browsers upload them with the charset as well (e.g. `text/plain charset=utf-8`) without specifying all possible charsets. Additionally, this allows for blanket includes like `text/*` or `image/*` by class type.
e95ba54
to
3b9396c
Compare
I've redone the patch and changed the syntax from any prefix to a class whitelist (e.g. instead of allowing |
Related #10172 |
Be careful, as |
@lunny thoughts? |
@guillep2k if svg is not displayed in browser it should not be threat |
@mqudsi The codes looks good for me. But if you can extract them as a function and add some tests for it with some update notes on app.ini.sample and cheetsheet, it's better. |
It would be better to use wildcard globs for this |
I’m not a go developer but I’m not aware of a generic wildcard module in go. The only one I found the last time I looked is a file system glob. That aside, I disagree entirely. You have to take context into account. What does general globbing get you that a simple string comparison (as performed) doesn’t? On the flip side, you get behavior that makes no sense for your context. What does it mean to have a glob pattern |
Ah, in the circles I run in, glob pretty much refers to * or ** only. I didn’t realize go’s implementation was more patterns than that. Still, that’s not much less verbose but considerably less readable than typing those two cases out twice, though if you’re already using it then it’s likely a paradigm advanced users will be familiar with. |
@mqudsi this looks good but needs rebasing. |
@singuliere I think it's no longer required. The current code deletes var mimeTypeSuffixRe = regexp.MustCompile(`;.*$`)
...
fullMimeType := http.DetectContentType(buf)
mimeType := strings.TrimSpace(mimeTypeSuffixRe.ReplaceAllString(fullMimeType, ""))
...
} else if mimeType == allowEntry {
return nil // mime type is allowed
} ... Class type matches (e.g. |
The old behavior prevented simple file types like "text/plain" from
being uploaded since browsers upload them with the charset as well (e.g.
text/plain charset=utf-8
) without specifying all possible charsets.Additionally, this allows for blanket includes like "text/" or "image/"
by class type.
There should be minimal risk introduced here as mime types are generally
hierarchical, but an alternative approach would be the equivalent of