Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
9622fbdf
Commit
9622fbdf
authored
Mar 26, 2015
by
Lukas Reschke
Browse files
Filter potential dangerous characters in path name
We should not allow / or \ in the postfix here.
parent
746be98e
Changes
2
Hide whitespace changes
Inline
Side-by-side
lib/private/tempmanager.php
View file @
9622fbdf
...
...
@@ -54,10 +54,15 @@ class TempManager implements ITempManager {
$this
->
log
=
$logger
;
}
/**
* @param string $postFix
* @return string
*/
protected
function
generatePath
(
$postFix
)
{
if
(
$postFix
)
{
$postFix
=
'.'
.
ltrim
(
$postFix
,
'.'
);
}
$postFix
=
str_replace
([
'\\'
,
'/'
],
''
,
$postFix
);
return
$this
->
tmpBaseDir
.
'/oc_tmp_'
.
md5
(
time
()
.
rand
())
.
$postFix
;
}
...
...
tests/lib/tempmanager.php
View file @
9622fbdf
...
...
@@ -151,4 +151,17 @@ class TempManager extends \Test\TestCase {
->
with
(
$this
->
stringContains
(
'Can not create a temporary folder in directory'
));
$this
->
assertFalse
(
$manager
->
getTemporaryFolder
());
}
public
function
testGeneratePathTraversal
()
{
$logger
=
$this
->
getMock
(
'\Test\NullLogger'
);
$tmpManager
=
\
Test_Helper
::
invokePrivate
(
$this
->
getManager
(
$logger
),
'generatePath'
,
[
'../Traversal\\../FileName'
]
);
$this
->
assertStringEndsNotWith
(
'./Traversal\\../FileName'
,
$tmpManager
);
$this
->
assertStringEndsWith
(
'.Traversal..FileName'
,
$tmpManager
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment