diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2015-02-02 19:54:56 +0100 |
---|---|---|
committer | Joas Schilling <nickvergessen@owncloud.com> | 2015-03-11 15:23:59 +0100 |
commit | 625bb3c4d5f383437235d1fb9e7eaf3c190613c3 (patch) | |
tree | 8b590d7d9ef916f008fb952465a9d14eea406f07 /lib/private | |
parent | 8db687a1cddd13c2a6fb6b16038d20275bd31e17 (diff) | |
download | nextcloud-server-625bb3c4d5f383437235d1fb9e7eaf3c190613c3.tar.gz nextcloud-server-625bb3c4d5f383437235d1fb9e7eaf3c190613c3.zip |
Extract the remote host from user input in share dropdown
Fix #13678
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/share/helper.php | 30 | ||||
-rw-r--r-- | lib/private/share/share.php | 2 |
2 files changed, 31 insertions, 1 deletions
diff --git a/lib/private/share/helper.php b/lib/private/share/helper.php index 6059af0196d..55b71ceeeac 100644 --- a/lib/private/share/helper.php +++ b/lib/private/share/helper.php @@ -221,4 +221,34 @@ class Helper extends \OC\Share\Constants { return $expires; } + + /** + * Extracts the necessary remote name from a given link + * + * Strips away a potential file name, to allow + * - user + * - user@localhost + * - user@http://localhost + * - user@http://localhost/ + * - user@http://localhost/index.php + * - user@http://localhost/index.php/s/{shareToken} + * + * @param string $shareWith + * @return string + */ + public static function fixRemoteURLInShareWith($shareWith) { + if (strpos($shareWith, '@')) { + list($user, $remote) = explode('@', $shareWith, 2); + + $remote = str_replace('\\', '/', $remote); + if ($fileNamePosition = strpos($remote, '/index.php')) { + $remote = substr($remote, 0, $fileNamePosition); + } + $remote = rtrim($remote, '/'); + + $shareWith = $user . '@' . $remote; + } + + return rtrim($shareWith, '/'); + } } diff --git a/lib/private/share/share.php b/lib/private/share/share.php index 9c3c6a2d3af..9af567278a1 100644 --- a/lib/private/share/share.php +++ b/lib/private/share/share.php @@ -724,7 +724,7 @@ class Share extends \OC\Share\Constants { $token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(self::TOKEN_LENGTH, \OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_UPPER . \OCP\Security\ISecureRandom::CHAR_DIGITS); - $shareWith = rtrim($shareWith, '/'); + $shareWith = Helper::fixRemoteURLInShareWith($shareWith); $shareId = self::put($itemType, $itemSource, $shareType, $shareWith, $uidOwner, $permissions, null, $token, $itemSourceName); $send = false; |