diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-03-26 21:45:30 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-03-26 21:45:30 +0100 |
commit | 4c00be49613fe14a03e996dd0768bcb7ef2795ab (patch) | |
tree | 4cfcfabfa404384c14f9b58713febb9f6c001c4f /lib | |
parent | 7bff0681feea57c1eb2f81015d574063b848b616 (diff) | |
parent | 8ebe667202e0bbccc458a5b0ef8e3f2c8d53c829 (diff) | |
download | nextcloud-server-4c00be49613fe14a03e996dd0768bcb7ef2795ab.tar.gz nextcloud-server-4c00be49613fe14a03e996dd0768bcb7ef2795ab.zip |
Merge pull request #14488 from owncloud/enhancement/security/inline-disposition
Serve all files with a Content-Disposition of 'attachment' via WebDAV
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/connector/sabre/filesplugin.php | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/private/connector/sabre/filesplugin.php b/lib/private/connector/sabre/filesplugin.php index acd0eb6014c..3c79f5a7a2a 100644 --- a/lib/private/connector/sabre/filesplugin.php +++ b/lib/private/connector/sabre/filesplugin.php @@ -24,6 +24,7 @@ namespace OC\Connector\Sabre; +use Sabre\DAV\IFile; use \Sabre\DAV\PropFind; use \Sabre\DAV\PropPatch; use \Sabre\HTTP\RequestInterface; @@ -52,6 +53,9 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin { */ private $tree; + /** + * @param \Sabre\DAV\Tree $tree + */ public function __construct(\Sabre\DAV\Tree $tree) { $this->tree = $tree; } @@ -84,6 +88,21 @@ class FilesPlugin extends \Sabre\DAV\ServerPlugin { $this->server->on('propPatch', array($this, 'handleUpdateProperties')); $this->server->on('afterBind', array($this, 'sendFileIdHeader')); $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader')); + $this->server->on('afterMethod:GET', [$this,'httpGet']); + } + + /** + * Plugin that adds a 'Content-Disposition: attachment' header to all files + * delivered by SabreDAV. + * @param RequestInterface $request + * @param ResponseInterface $response + */ + function httpGet(RequestInterface $request, ResponseInterface $response) { + // Only handle valid files + $node = $this->tree->getNodeForPath($request->getPath()); + if (!($node instanceof IFile)) return; + + $response->addHeader('Content-Disposition', 'attachment'); } /** |