Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify mime type checking #7605

Merged
merged 2 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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