Skip to content

Commit

Permalink
Allow slash and colon characters in cloud id
Browse files Browse the repository at this point in the history
Signed-off-by: Sandro Mesterheide <[email protected]>
  • Loading branch information
smesterheide committed Dec 12, 2022
1 parent 9612819 commit a283542
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
31 changes: 18 additions & 13 deletions lib/private/Federation/CloudIdManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ public function handleCardEvent(Event $event): void {

/**
* @param string $cloudId
* @param bool $isUserHint
* @return ICloudId
* @throws \InvalidArgumentException
*/
public function resolveCloudId(string $cloudId): ICloudId {
public function resolveCloudId(string $cloudId, ?bool $isUserHint = null): ICloudId {
// TODO magic here to get the url and user instead of just splitting on @

if (!$this->isValidCloudId($cloudId)) {
Expand All @@ -107,21 +108,25 @@ public function resolveCloudId(string $cloudId): ICloudId {

// Find the first character that is not allowed in user names
$id = $this->fixRemoteURL($cloudId);
$posSlash = strpos($id, '/');
$posColon = strpos($id, ':');

if ($posSlash === false && $posColon === false) {
$invalidPos = \strlen($id);
} elseif ($posSlash === false) {
$invalidPos = $posColon;
} elseif ($posColon === false) {
$invalidPos = $posSlash;
if (is_null($isUserHint) || $isUserHint === true) {
$posSlash = strpos($id, '/');
$posColon = strpos($id, ':');

if ($posSlash === false && $posColon === false) {
$invalidPos = \strlen($id);
} elseif ($posSlash === false) {
$invalidPos = $posColon;
} elseif ($posColon === false) {
$invalidPos = $posSlash;
} else {
$invalidPos = min($posSlash, $posColon);
}

$lastValidAtPos = strrpos($id, '@', $invalidPos - strlen($id));
} else {
$invalidPos = min($posSlash, $posColon);
$lastValidAtPos = strrpos($id, '@');
}

$lastValidAtPos = strrpos($id, '@', $invalidPos - strlen($id));

if ($lastValidAtPos !== false) {
$user = substr($id, 0, $lastValidAtPos);
$remote = substr($id, $lastValidAtPos + 1);
Expand Down
3 changes: 2 additions & 1 deletion lib/public/Federation/ICloudIdManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@
interface ICloudIdManager {
/**
* @param string $cloudId
* @param bool $isUserHint cloudId is known to refer to a user as hint for validation
* @return ICloudId
* @throws \InvalidArgumentException
*
* @since 12.0.0
*/
public function resolveCloudId(string $cloudId): ICloudId;
public function resolveCloudId(string $cloudId, ?bool $isUserHint = null): ICloudId;

/**
* Get the cloud id for a remote user
Expand Down

0 comments on commit a283542

Please sign in to comment.