Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
passwords-handbook
Manage
Activity
Members
Labels
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nextcloud
passwords-handbook
Commits
b6927253
Verified
Commit
b6927253
authored
9 months ago
by
Marius David Wieschollek
Browse files
Options
Downloads
Patches
Plain Diff
Fix host issue
parent
d74ea054
Branches
testing
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/Controller/HandbookController.php
+62
-7
62 additions, 7 deletions
src/lib/Controller/HandbookController.php
with
62 additions
and
7 deletions
src/lib/Controller/HandbookController.php
+
62
−
7
View file @
b6927253
...
...
@@ -13,30 +13,32 @@ namespace OCA\PasswordsHandbook\Controller;
use
JetBrains\PhpStorm\Pure
;
use
OC\App\AppManager
;
use
OC\AppFramework\Http\Request
;
use
OCA\PasswordsHandbook\AppInfo\Application
;
use
OCA\PasswordsHandbook\Service\FeaturesService
;
use
OCP\App\AppPathNotFoundException
;
use
OCP\AppFramework\Controller
;
use
OCP\AppFramework\Http
;
use
OCP\AppFramework\Http\Attribute\NoAdminRequired
;
use
OCP\AppFramework\Http\Attribute\NoCSRFRequired
;
use
OCP\AppFramework\Http\Attribute\NoTwoFactorRequired
;
use
OCP\AppFramework\Http\Attribute\PublicPage
;
use
OCP\AppFramework\Http\DataDisplayResponse
;
use
OCP\AppFramework\Http\NotFoundResponse
;
use
OCP\AppFramework\Http\Response
;
use
OCP\IConfig
;
use
OCP\IRequest
;
use
OCP\AppFramework\Http\Attribute\NoCSRFRequired
;
use
OCP\AppFramework\Http\Attribute\PublicPage
;
use
OCP\AppFramework\Http\Attribute\NoAdminRequired
;
use
OCP\AppFramework\Http\Attribute\NoTwoFactorRequired
;
class
HandbookController
extends
Controller
{
/**
* @param $appName
* @param IRequest $request
* @param IConfig $config
* @param AppManager $appManager
* @param FeaturesService $featuresService
*/
#
[
Pure
]
public
function
__construct
(
$appName
,
IRequest
$request
,
protected
AppManager
$appManager
,
protected
FeaturesService
$featuresService
)
{
#
[
Pure
]
public
function
__construct
(
$appName
,
IRequest
$request
,
protected
IConfig
$config
,
protected
AppManager
$appManager
,
protected
FeaturesService
$featuresService
)
{
parent
::
__construct
(
$appName
,
$request
);
}
...
...
@@ -119,8 +121,61 @@ class HandbookController extends Controller {
}
protected
function
getHeaders
(
mixed
$mime
):
array
{
$requestUri
=
'https://'
.
$this
->
request
->
getServerHost
();
$origin
=
$this
->
request
->
getHeader
(
'origin'
);
$allowOrigin
=
'https://'
.
$this
->
getTrustedDomainFromURl
(
$origin
);
return
[
'content-type'
=>
$mime
,
'Access-Control-Allow-Origin'
=>
$allowOrigin
];
}
/**
* Mostly taken from \OC\Security\TrustedDomainHelper::isTrustedDomain
* except we don't check the overwritehost setting.
*/
public
function
getTrustedDomainFromURl
(
string
$url
):
string
{
$parsedUrl
=
parse_url
(
$url
);
if
(
empty
(
$parsedUrl
[
'host'
]))
{
return
$this
->
request
->
getServerHost
();
}
$domain
=
$parsedUrl
[
'host'
];
$domainWithPort
=
$domain
.
(
$parsedUrl
[
'port'
]
?
':'
.
$parsedUrl
[
'port'
]
:
''
);
// Read trusted domains from config
$trustedList
=
$this
->
config
->
getSystemValue
(
'trusted_domains'
,
[]);
if
(
!
is_array
(
$trustedList
))
{
return
$this
->
request
->
getServerHost
();
}
// Always allow access from localhost
if
(
preg_match
(
Request
::
REGEX_LOCALHOST
,
$domain
)
===
1
)
{
return
$domain
;
}
// Reject malformed domains in any case
if
(
str_starts_with
(
$domain
,
'-'
)
||
str_contains
(
$domain
,
'..'
))
{
return
$this
->
request
->
getServerHost
();
}
// Match, allowing for * wildcards
foreach
(
$trustedList
as
$trusted
)
{
if
(
gettype
(
$trusted
)
!==
'string'
)
{
break
;
}
$regex
=
'/^'
.
implode
(
'[-\.a-zA-Z0-9]*'
,
array_map
(
function
(
$v
)
{
return
preg_quote
(
$v
,
'/'
);
},
explode
(
'*'
,
$trusted
)
)
)
.
'$/i'
;
if
(
preg_match
(
$regex
,
$domain
)
||
preg_match
(
$regex
,
$domainWithPort
))
{
return
$domain
;
}
}
return
[
'content-type'
=>
$mime
,
'Access-Control-Allow-Origin'
=>
$requestUri
]
;
return
$this
->
request
->
getServerHost
()
;
}
}
\ No newline at end of file
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