Skip to content

Commit

Permalink
Merge pull request #7605 from owncloud/simplify-mime-type-checking
Browse files Browse the repository at this point in the history
chore: simplify mime type checking
  • Loading branch information
kulmann committed Sep 8, 2022
2 parents fefc2fc + 2f5cd3f commit c763c03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
7 changes: 7 additions & 0 deletions changelog/unreleased/enhancement-simplify-mime-type-checking
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: Simplify mime type checking

We've removed the dependency to GuzzleHttp from our oc10 app package. It was used for mime type checking only. Instead we now rely on a mime type checker that is already bundled with oc10 core.
IMPORTANT: this enhancement is needed to reach compatibility with oc10.11 and maintain backwards compatibility with oc prior to oc10.11. This would not be easily doable when still relying on GuzzleHttp because its major version was updated from 5 to 7 in oc10.11.

https://github.com/owncloud/web/pull/7605
https://github.com/owncloud/web/pull/5933
22 changes: 10 additions & 12 deletions packages/web-integration-oc10/lib/Controller/FilesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@

namespace OCA\Web\Controller;

use GuzzleHttp\Mimetypes;
use OC\AppFramework\Http;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\Response;
use OCP\IConfig;
use OCP\Files\IMimeTypeDetector;
use OCP\IRequest;

/**
Expand All @@ -39,27 +38,27 @@
*/
class FilesController extends Controller {

/**
* @var IConfig
*/
private $config;
/**
* @var IAppManager
*/
private $appManager;
/**
* @var IMimeTypeDetector
*/
private $mimeTypeDetector;

/**
* FilesController constructor.
*
* @param string $appName
* @param IRequest $request
* @param IConfig $config
* @param IAppManager $appManager
* @param IMimeTypeDetector $mimeTypeDetector
*/
public function __construct(string $appName, IRequest $request, IConfig $config, IAppManager $appManager) {
public function __construct(string $appName, IRequest $request, IAppManager $appManager, IMimeTypeDetector $mimeTypeDetector) {
parent::__construct($appName, $request);
$this->config = $config;
$this->appManager = $appManager;
$this->mimeTypeDetector = $mimeTypeDetector;
}

/**
Expand All @@ -78,7 +77,7 @@ public function getFile(string $path): Response {
}

// check if path permitted
$permittedPaths = ["css", "img", "js", "themes", "icons", "index.html", "manifest.json", "oidc-callback.html", "oidc-silent-redirect.html"];
$permittedPaths = ["css", "img", "js", "themes", "icons", "fonts", "index.html", "manifest.json", "oidc-callback.html", "oidc-silent-redirect.html"];
$found = false;
foreach ($permittedPaths as $p) {
if (\strpos($path, $p) === 0) {
Expand Down Expand Up @@ -133,8 +132,7 @@ public function getFile(string $path): Response {
}

private function getMimeType(string $filename): string {
$mimeTypes = Mimetypes::getInstance();
return $mimeTypes->fromFilename($filename);
return $this->mimeTypeDetector->detectPath($filename);
}

private function applyCSPOpenIDConnect(ContentSecurityPolicy $csp): ContentSecurityPolicy {
Expand Down

0 comments on commit c763c03

Please sign in to comment.