Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marcus Eibrink-Lunzenauer
Stud.IP
Commits
dc259559
Commit
dc259559
authored
2 years ago
by
Jan-Hendrik Willms
Browse files
Options
Downloads
Patches
Plain Diff
refine blacklisted content detection when downloading files, fixes #1205
Closes #1205 Merge request
studip/studip!715
parent
cf373d64
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/functions.php
+15
-5
15 additions, 5 deletions
lib/functions.php
public/sendfile.php
+2
-9
2 additions, 9 deletions
public/sendfile.php
with
17 additions
and
14 deletions
lib/functions.php
+
15
−
5
View file @
dc259559
...
...
@@ -1702,12 +1702,9 @@ function rmdirr($dirname){
/**
* Determines an appropriate MIME type for a file based on the
* extension of the file name.
*
* @param string $filename file name to check
* Returns the mapping of extensions to supported MIME types.
*/
function
get_mime_type
(
$filename
)
function
get_mime_type
s
()
{
static
$mime_types
=
[
// archive types
...
...
@@ -1761,6 +1758,19 @@ function get_mime_type($filename)
'webm'
=>
'video/webm'
,
];
return
$mime_types
;
}
/**
* Determines an appropriate MIME type for a file based on the
* extension of the file name.
*
* @param string $filename file name to check
*/
function
get_mime_type
(
$filename
)
{
$mime_types
=
get_mime_types
();
$extension
=
mb_strtolower
(
pathinfo
(
$filename
,
PATHINFO_EXTENSION
));
if
(
isset
(
$mime_types
[
$extension
]))
{
...
...
This diff is collapsed.
Click to expand it.
public/sendfile.php
+
2
−
9
View file @
dc259559
...
...
@@ -186,16 +186,9 @@ if (!file_exists($path_file)) {
throw
new
Exception
(
_
(
'Fehler beim Laden der Inhalte der Datei'
));
}
$content_blacklisted
=
function
(
$mime
)
{
foreach
([
'html'
,
'javascript'
,
'svg'
,
'xml'
]
as
$check
)
{
if
(
stripos
(
$mime
,
$check
)
!==
false
)
{
return
true
;
}
}
return
false
;
};
$allowed_mime_types
=
get_mime_types
();
if
(
$content_blacklisted
(
$content
_type
))
{
if
(
!
in_array
(
$content_type
,
$allowed_mime
_type
s
))
{
$content_type
=
'application/octet-stream'
;
}
if
(
Request
::
int
(
'force_download'
)
||
$content_type
==
"application/octet-stream"
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment