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
Commits
e7588ceb
Commit
e7588ceb
authored
3 years ago
by
Stein Magne Bjorklund
Browse files
Options
Downloads
Patches
Plain Diff
Issue 6 Refactor to StaticModule::validateDirectory()
parent
6216e485
No related branches found
No related tags found
1 merge request
!5
add check for static dir and static/img
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
classes/modules/staticModule.php
+24
-14
24 additions, 14 deletions
classes/modules/staticModule.php
with
24 additions
and
14 deletions
classes/modules/staticModule.php
+
24
−
14
View file @
e7588ceb
...
...
@@ -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();//
}
}
}
?>
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