Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeviceDetector->isMobile() should not rely on ClientHints when isBot() is true #7990

Open
juongithub opened this issue Feb 8, 2025 · 0 comments

Comments

@juongithub
Copy link

juongithub commented Feb 8, 2025

Since a bot could pretend to be a mobile device using HTTP headers, isMobile() should not return true if isBot() is true.
I propose the following change in DeviceDetector.php:

From:

    public function isMobile(): bool
    {
        // Client hints indicate a mobile device
        if ($this->clientHints instanceof ClientHints && $this->clientHints->isMobile()) {
            return true;
        }
        ...

        return !$this->isBot() && !$this->isDesktop();
    }

To:

    public function isMobile(): bool
    {
        if ($this->isBot()) {
    	    return false;
        }

        // Client hints indicate a mobile device
        if ($this->clientHints instanceof ClientHints && $this->clientHints->isMobile()) {
            return true;
        }
        ...

        return  !$this->isDesktop();
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant