Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2021-04-26 14:56:01 +0300
committerGitHub <noreply@github.com>2021-04-26 14:56:01 +0300
commitaa651fd629534e96432492c1a74e979b28222ce2 (patch)
tree63191b834673e30a9544ed589a2afba02ef54299 /lib/private
parente1a3000cbed2e0bfa29e53b8bbcb858604540da2 (diff)
parentd80cc76ee7f3f1f347fc54cc300e5e38ba7d6e19 (diff)
Merge pull request #26259 from nextcloud/feature/noid/validate-website-to-be-valid
Validate the website field input to be a valid URL
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Accounts/AccountManager.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/private/Accounts/AccountManager.php b/lib/private/Accounts/AccountManager.php
index d5df6557c8f..53792c70d27 100644
--- a/lib/private/Accounts/AccountManager.php
+++ b/lib/private/Accounts/AccountManager.php
@@ -121,6 +121,25 @@ class AccountManager implements IAccountManager {
}
/**
+ *
+ * @param string $input
+ * @return string
+ * @throws \InvalidArgumentException When the website did not have http(s) as protocol or the host name was empty
+ */
+ protected function parseWebsite(string $input): string {
+ $parts = parse_url($input);
+ if (!isset($parts['scheme']) || ($parts['scheme'] !== 'https' && $parts['scheme'] !== 'http')) {
+ throw new \InvalidArgumentException(self::PROPERTY_WEBSITE);
+ }
+
+ if (!isset($parts['host']) || $parts['host'] === '') {
+ throw new \InvalidArgumentException(self::PROPERTY_WEBSITE);
+ }
+
+ return $input;
+ }
+
+ /**
* update user record
*
* @param IUser $user
@@ -158,6 +177,17 @@ class AccountManager implements IAccountManager {
}
}
+ if (isset($data[self::PROPERTY_WEBSITE]) && $data[self::PROPERTY_WEBSITE]['value'] !== '') {
+ try {
+ $data[self::PROPERTY_WEBSITE]['value'] = $this->parseWebsite($data[self::PROPERTY_WEBSITE]['value']);
+ } catch (\InvalidArgumentException $e) {
+ if ($throwOnData) {
+ throw $e;
+ }
+ $data[self::PROPERTY_WEBSITE]['value'] = '';
+ }
+ }
+
$allowedScopes = [
self::SCOPE_PRIVATE,
self::SCOPE_LOCAL,