Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
4ec1da30
Commit
4ec1da30
authored
Dec 5, 2014
by
Morris Jobke
Browse files
Options
Downloads
Plain Diff
Merge pull request #12583 from owncloud/trim-port
Trim port from domain
parents
e81c2a49
81541c56
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/private/request.php
+24
-9
24 additions, 9 deletions
lib/private/request.php
lib/private/setup.php
+1
-1
1 addition, 1 deletion
lib/private/setup.php
tests/lib/request.php
+17
-0
17 additions, 0 deletions
tests/lib/request.php
with
42 additions
and
10 deletions
lib/private/request.php
+
24
−
9
View file @
4ec1da30
...
...
@@ -65,24 +65,34 @@ class OC_Request {
or
(
$type
!==
'protocol'
and
OC_Config
::
getValue
(
'forcessl'
,
false
));
}
/**
* Strips a potential port from a domain (in format domain:port)
* @param $host
* @return string $host without appended port
*/
public
static
function
getDomainWithoutPort
(
$host
)
{
$pos
=
strrpos
(
$host
,
':'
);
if
(
$pos
!==
false
)
{
$port
=
substr
(
$host
,
$pos
+
1
);
if
(
is_numeric
(
$port
))
{
$host
=
substr
(
$host
,
0
,
$pos
);
}
}
return
$host
;
}
/**
* Checks whether a domain is considered as trusted from the list
* of trusted domains. If no trusted domains have been configured, returns
* true.
* This is used to prevent Host Header Poisoning.
* @param string $domain
* @param string $domain
WithPort
* @return bool true if the given domain is trusted or if no trusted domains
* have been configured
*/
public
static
function
isTrustedDomain
(
$domain
)
{
public
static
function
isTrustedDomain
(
$domain
WithPort
)
{
// Extract port from domain if needed
$pos
=
strrpos
(
$domain
,
':'
);
if
(
$pos
!==
false
)
{
$port
=
substr
(
$domain
,
$pos
+
1
);
if
(
is_numeric
(
$port
))
{
$domain
=
substr
(
$domain
,
0
,
$pos
);
}
}
$domain
=
self
::
getDomainWithoutPort
(
$domainWithPort
);
// FIXME: Empty config array defaults to true for now. - Deprecate this behaviour with ownCloud 8.
$trustedList
=
\OC
::
$server
->
getConfig
()
->
getSystemValue
(
'trusted_domains'
,
array
());
...
...
@@ -90,6 +100,11 @@ class OC_Request {
return
true
;
}
// FIXME: Workaround for older instances still with port applied. Remove for ownCloud 9.
if
(
in_array
(
$domainWithPort
,
$trustedList
))
{
return
true
;
}
// Always allow access from localhost
if
(
preg_match
(
self
::
REGEX_LOCALHOST
,
$domain
)
===
1
)
{
return
true
;
...
...
This diff is collapsed.
Click to expand it.
lib/private/setup.php
+
1
−
1
View file @
4ec1da30
...
...
@@ -162,7 +162,7 @@ class OC_Setup {
&&
is_array
(
$options
[
'trusted_domains'
]))
{
$trustedDomains
=
$options
[
'trusted_domains'
];
}
else
{
$trustedDomains
=
array
(
OC_Request
::
serverHost
());
$trustedDomains
=
array
(
\OC_Request
::
getDomainWithoutPort
(
\
OC_Request
::
serverHost
())
)
;
}
if
(
OC_Util
::
runningOnWindows
())
{
...
...
This diff is collapsed.
Click to expand it.
tests/lib/request.php
+
17
−
0
View file @
4ec1da30
...
...
@@ -228,6 +228,23 @@ class Test_Request extends \Test\TestCase {
OC_Config
::
deleteKey
(
'overwritehost'
);
}
public
function
hostWithPortProvider
()
{
return
array
(
array
(
'localhost:500'
,
'localhost'
),
array
(
'foo.com'
,
'foo.com'
),
array
(
'[1fff:0:a88:85a3::ac1f]:801'
,
'[1fff:0:a88:85a3::ac1f]'
),
array
(
'[1fff:0:a88:85a3::ac1f]'
,
'[1fff:0:a88:85a3::ac1f]'
)
);
}
/**
* @dataProvider hostWithPortProvider
*/
public
function
testGetDomainWithoutPort
(
$hostWithPort
,
$host
)
{
$this
->
assertEquals
(
$host
,
OC_Request
::
getDomainWithoutPort
(
$hostWithPort
));
}
/**
* @dataProvider trustedDomainDataProvider
*/
...
...
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