Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
marcus-lodspeakr
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
uib-ub
Spesialsamlingene
marcus-lodspeakr
Merge requests
!5
add check for static dir and static/img
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
add check for static dir and static/img
lodspeakr-issue-6
into
master
Overview
2
Commits
5
Pipelines
0
Changes
1
Merged
Oyvind.Gjesdal
requested to merge
lodspeakr-issue-6
into
master
3 years ago
Overview
2
Commits
5
Pipelines
0
Changes
1
Expand
0
0
Merge request reports
Compare
version 2
version 4
d5fe2b0b
3 years ago
version 3
e7588ceb
3 years ago
version 2
6216e485
3 years ago
version 1
4d3e23b7
3 years ago
master (base)
and
version 3
latest version
6e00b2c7
5 commits,
3 years ago
version 4
d5fe2b0b
4 commits,
3 years ago
version 3
e7588ceb
3 commits,
3 years ago
version 2
6216e485
2 commits,
3 years ago
version 1
4d3e23b7
1 commit,
3 years ago
Show latest version
1 file
+
24
−
14
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
classes/modules/staticModule.php
+
24
−
14
Options
@@ -24,17 +24,9 @@ class StaticModule extends abstractModule{
global
$uri
;
global
$acceptContentType
;
global
$endpoints
;
global
$lodspk
;
$staticdir
=
realpath
(
$conf
[
'static'
][
'directory'
]);
$imgdir
=
realpath
(
$conf
[
'static'
][
'directory'
]
.
"img"
);
$resourcepath
=
realpath
(
$conf
[
'static'
][
'directory'
]
.
$file
);
// static resources should be in static or img dir (img may be symlinked, check realpath of img as well)
if
(
strpos
(
$resourcepath
,
$staticdir
)
!==
0
and
strpos
(
$resourcepath
,
$imgdir
)
!==
0
)
{
HTTPStatus
::
send404
(
$file
);
// send404 calls exit();//
}
$filenamearray
=
explode
(
"."
,
$file
);
global
$lodspk
;
$this
->
validateDirectory
(
$conf
,
$file
);
$filenamearray
=
explode
(
"."
,
$file
);
$extension
=
end
(
$filenamearray
);
$ct
=
$this
->
getContentType
(
$extension
);
header
(
"Content-type: "
.
$ct
);
@@ -95,8 +87,26 @@ class StaticModule extends abstractModule{
}
return
""
;
//empty string seems to work fine with browsers
}
/**
* Validate that resource directory is valid and safe to use.
*
* @param array $conf
* Global configuration.
* @param $file
*
* @return void
*/
private
function
validateDirectory
(
array
$conf
,
$file
):
void
{
$staticdir
=
realpath
(
$conf
[
'static'
][
'directory'
]);
$imgdir
=
realpath
(
$conf
[
'static'
][
'directory'
]
.
"img"
);
$resourcepath
=
realpath
(
$conf
[
'static'
][
'directory'
]
.
$file
);
// static resources should be in static or img dir (img may be symlinked, check realpath of img as well)
if
(
strpos
(
$resourcepath
,
$staticdir
)
!==
0
and
strpos
(
$resourcepath
,
$imgdir
)
!==
0
)
{
HTTPStatus
::
send404
(
$file
);
// send404 calls exit();//
}
}
}
?>
Loading