Skip to content

URLs are parsed incorrectly if they don't end with / or /something #1840

@rgavilan

Description

@rgavilan

sysPass Version
3.2.6

Describe the bug
After updating to version 3.2.6 we have detected that some URLs are displayed incorrectly on the search screen. For instance, if we set the URL https://www.google.com in the account, we can see on the search screen the value https%3A%2F%2Fwww.google.com and the link is https://syspass-url/https%3A%2F%2Fwww.google.com

I suppose the problem is related with this function:

    /**
     * @param  string  $url
     *
     * @return string
     */
    public static function getSafeUrl(string $url): string
    {
        if (preg_match('#^((?:https?|ftp|ssh|rdp)://[\w._-]+/)(.*)#', $url, $urlParts)
            && count($urlParts) === 3) {
            return $urlParts[1].urlencode($urlParts[2]);
        }

        return urlencode($url);
    }

The regexp expects the url has 3 parts, and if it doesn't finish with / or /something, it doesn't match.

To Reproduce
Steps to reproduce the behavior:

  1. Set an URL in an account without context path, for instance https://www.google.com
  2. Goto search screen and locate the account
  3. Look at the URL and the link
  4. See error

Expected behavior
URLs should be parsed correctly regardless of whether they end with / or not

Screenshots

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions