Replace jenssegers/agent with matomo/device-detector

- Remove unmaintained jenssegers/agent package (no releases since 2021)
- Add matomo/device-detector v6.5 as actively maintained replacement
- Create App\Services\UserAgentService wrapper for drop-in compatibility
- Update UserDevice model and ApiV1Dot1Controller to use new service
pull/6762/head
Your Name 4 weeks ago
parent 16a413aa8b
commit 651f0de74f

@ -48,7 +48,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use Jenssegers\Agent\Agent;
use App\Services\UserAgentService;
use League\Fractal;
use League\Fractal\Serializer\ArraySerializer;
use Mail;
@ -341,7 +341,7 @@ class ApiV1Dot1Controller extends Controller
if (config('pixelfed.bouncer.cloud_ips.ban_signups')) {
abort_if(BouncerService::checkIp($request->ip()), 404);
}
$agent = new Agent;
$agent = new UserAgentService;
$currentIp = $request->ip();
$activity = AccountLog::whereUserId($user->id)

@ -0,0 +1,89 @@
<?php
namespace App\Services;
use DeviceDetector\DeviceDetector;
class UserAgentService
{
protected DeviceDetector $dd;
public function __construct(?string $userAgent = null)
{
$this->dd = new DeviceDetector($userAgent ?? '');
$this->dd->parse();
}
/**
* Set the user agent string and re-parse.
*/
public function setUserAgent(string $userAgent): static
{
$this->dd->setUserAgent($userAgent);
$this->dd->parse();
return $this;
}
/**
* Check if the device is a mobile phone or phablet.
*/
public function isMobile(): bool
{
return ! $this->dd->isDesktop();
}
/**
* Get the device brand and model (e.g. "Apple iPhone", "Samsung Galaxy S21").
* Falls back to the device type name if brand/model aren't available.
*/
public function device(): string
{
$brand = $this->dd->getBrandName();
$model = $this->dd->getModel();
if ($brand && $model) {
return trim("{$brand} {$model}");
}
if ($model) {
return $model;
}
if ($brand) {
return $brand;
}
$deviceName = $this->dd->getDeviceName();
return $deviceName ?: 'Unknown';
}
/**
* Get the browser name (e.g. "Chrome", "Firefox", "Safari").
*/
public function browser(): string
{
$client = $this->dd->getClient();
if (is_array($client) && ! empty($client['name'])) {
return $client['name'];
}
return 'Unknown';
}
/**
* Get the operating system / platform name (e.g. "Windows", "iOS", "Android").
*/
public function platform(): string
{
$os = $this->dd->getOs();
if (is_array($os) && ! empty($os['name'])) {
return $os['name'];
}
return 'Unknown';
}
}

@ -3,7 +3,7 @@
namespace App;
use Illuminate\Database\Eloquent\Model;
use Jenssegers\Agent\Agent;
use App\Services\UserAgentService;
class UserDevice extends Model
{
@ -27,9 +27,7 @@ class UserDevice extends Model
if (! $this->user_agent) {
return 'Unknown';
}
$agent = new Agent;
$agent->setUserAgent($this->user_agent);
return $agent;
return new UserAgentService($this->user_agent);
}
}

@ -18,9 +18,8 @@
"buzz/laravel-h-captcha": "^1.0.4",
"endroid/qr-code": "^6.0",
"guzzlehttp/guzzle": "^7.10",
"intervention/image-laravel": "^1.5",
"intervention/image-driver-vips": "^1.0",
"jenssegers/agent": "^2.6",
"intervention/image-laravel": "^1.5",
"laravel-notification-channels/expo": "^2.0.0",
"laravel-notification-channels/webpush": "^10.2",
"laravel/framework": "^12.0",
@ -34,6 +33,7 @@
"league/iso3166": "^2.1|^4.0",
"league/oauth2-client": "^2.8",
"league/uri": "^7.4",
"matomo/device-detector": "^6.5",
"nesbot/carbon": "^3.10",
"pbmedia/laravel-ffmpeg": "^8.0",
"phpseclib/phpseclib": "~3.0",

322
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "60fdb8d3c202f5dcc511b9900ee76e07",
"content-hash": "c582951f4a2d8e59ccdd3e3774950c8d",
"packages": [
{
"name": "aws/aws-crt-php",
@ -2044,58 +2044,6 @@
],
"time": "2026-03-24T15:10:30+00:00"
},
{
"name": "jaybizzle/crawler-detect",
"version": "v1.4.1",
"source": {
"type": "git",
"url": "https://github.com/JayBizzle/Crawler-Detect.git",
"reference": "770e00e5bcd35054871a6f790f380123cc3b8b0c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/JayBizzle/Crawler-Detect/zipball/770e00e5bcd35054871a6f790f380123cc3b8b0c",
"reference": "770e00e5bcd35054871a6f790f380123cc3b8b0c",
"shasum": ""
},
"require": {
"php": ">=7.2.0"
},
"require-dev": {
"phpunit/phpunit": "^8.5.52|^9.4"
},
"type": "library",
"autoload": {
"psr-4": {
"Jaybizzle\\CrawlerDetect\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Mark Beech",
"email": "m@rkbee.ch",
"role": "Developer"
}
],
"description": "CrawlerDetect is a PHP class for detecting bots/crawlers/spiders via the user agent",
"homepage": "https://github.com/JayBizzle/Crawler-Detect/",
"keywords": [
"crawler",
"crawler detect",
"crawler detector",
"crawlerdetect",
"php crawler detect"
],
"support": {
"issues": "https://github.com/JayBizzle/Crawler-Detect/issues",
"source": "https://github.com/JayBizzle/Crawler-Detect/tree/v1.4.1"
},
"time": "2026-07-10T14:15:38+00:00"
},
{
"name": "jcupitt/vips",
"version": "v2.6.1",
@ -2157,89 +2105,6 @@
},
"time": "2025-12-10T14:03:20+00:00"
},
{
"name": "jenssegers/agent",
"version": "v2.6.4",
"source": {
"type": "git",
"url": "https://github.com/jenssegers/agent.git",
"reference": "daa11c43729510b3700bc34d414664966b03bffe"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jenssegers/agent/zipball/daa11c43729510b3700bc34d414664966b03bffe",
"reference": "daa11c43729510b3700bc34d414664966b03bffe",
"shasum": ""
},
"require": {
"jaybizzle/crawler-detect": "^1.2",
"mobiledetect/mobiledetectlib": "^2.7.6",
"php": ">=5.6"
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpunit": "^5.0|^6.0|^7.0"
},
"suggest": {
"illuminate/support": "Required for laravel service providers"
},
"type": "library",
"extra": {
"laravel": {
"aliases": {
"Agent": "Jenssegers\\Agent\\Facades\\Agent"
},
"providers": [
"Jenssegers\\Agent\\AgentServiceProvider"
]
},
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
"Jenssegers\\Agent\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jens Segers",
"homepage": "https://jenssegers.com"
}
],
"description": "Desktop/mobile user agent parser with support for Laravel, based on Mobiledetect",
"homepage": "https://github.com/jenssegers/agent",
"keywords": [
"Agent",
"browser",
"desktop",
"laravel",
"mobile",
"platform",
"user agent",
"useragent"
],
"support": {
"issues": "https://github.com/jenssegers/agent/issues",
"source": "https://github.com/jenssegers/agent/tree/v2.6.4"
},
"funding": [
{
"url": "https://github.com/jenssegers",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/jenssegers/agent",
"type": "tidelift"
}
],
"time": "2020-06-13T08:05:20+00:00"
},
{
"name": "laravel-notification-channels/expo",
"version": "2.3.0",
@ -4249,6 +4114,75 @@
],
"time": "2026-08-18T11:39:06+00:00"
},
{
"name": "matomo/device-detector",
"version": "6.5.1",
"source": {
"type": "git",
"url": "https://github.com/matomo-org/device-detector.git",
"reference": "f30457500c6be4c80c8830466f8a746724779fd0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/matomo-org/device-detector/zipball/f30457500c6be4c80c8830466f8a746724779fd0",
"reference": "f30457500c6be4c80c8830466f8a746724779fd0",
"shasum": ""
},
"require": {
"mustangostang/spyc": "*",
"php": "^7.2|^8.0"
},
"replace": {
"piwik/device-detector": "self.version"
},
"require-dev": {
"matthiasmullie/scrapbook": "^1.4.7",
"mayflower/mo4-coding-standard": "^v9.0.0",
"phpstan/phpstan": "^1.10.44",
"phpunit/phpunit": "^8.5.2 || ^9 || ^10 || ^11 || ^12 || ^13",
"psr/cache": "^1.0.1 || ^2.0 || ^3.0",
"psr/simple-cache": "^1.0.1 || ^2.0 || ^3.0",
"slevomat/coding-standard": "<8.16.0",
"symfony/yaml": "^5.4 || ^6.4 || ^7.4 || ^8.0"
},
"suggest": {
"ext-yaml": "Necessary for using the Pecl YAML parser"
},
"type": "library",
"autoload": {
"psr-4": {
"DeviceDetector\\": ""
},
"exclude-from-classmap": [
"Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"LGPL-3.0-or-later"
],
"authors": [
{
"name": "The Matomo Team",
"email": "hello@matomo.org",
"homepage": "https://matomo.org/team/"
}
],
"description": "The Universal Device Detection library, that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, media players, mobile apps, feed readers, libraries, etc), operating systems, devices, brands and models.",
"homepage": "https://matomo.org",
"keywords": [
"devicedetection",
"parser",
"useragent"
],
"support": {
"forum": "https://forum.matomo.org/",
"issues": "https://github.com/matomo-org/device-detector/issues",
"source": "https://github.com/matomo-org/matomo",
"wiki": "https://developer.matomo.org/"
},
"time": "2026-05-27T09:53:26+00:00"
},
{
"name": "minishlink/web-push",
"version": "v10.1.0",
@ -4320,68 +4254,6 @@
},
"time": "2026-05-28T09:37:37+00:00"
},
{
"name": "mobiledetect/mobiledetectlib",
"version": "2.8.47",
"source": {
"type": "git",
"url": "https://github.com/serbanghita/Mobile-Detect.git",
"reference": "28e9045958dcaf771f9b56564549d5b174e38b0e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/serbanghita/Mobile-Detect/zipball/28e9045958dcaf771f9b56564549d5b174e38b0e",
"reference": "28e9045958dcaf771f9b56564549d5b174e38b0e",
"shasum": ""
},
"require": {
"php": ">=5.0.0"
},
"require-dev": {
"phpunit/phpunit": "~4.8.36"
},
"type": "library",
"autoload": {
"psr-0": {
"Detection": "namespaced/"
},
"classmap": [
"Mobile_Detect.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Serban Ghita",
"email": "serbanghita@gmail.com",
"homepage": "http://mobiledetect.net",
"role": "Developer"
}
],
"description": "Mobile_Detect is a lightweight PHP class for detecting mobile devices. It uses the User-Agent string combined with specific HTTP headers to detect the mobile environment.",
"homepage": "https://github.com/serbanghita/Mobile-Detect",
"keywords": [
"detect mobile devices",
"mobile",
"mobile detect",
"mobile detector",
"php mobile detect"
],
"support": {
"issues": "https://github.com/serbanghita/Mobile-Detect/issues",
"source": "https://github.com/serbanghita/Mobile-Detect/tree/2.8.47"
},
"funding": [
{
"url": "https://github.com/serbanghita",
"type": "github"
}
],
"time": "2026-04-14T12:32:34+00:00"
},
{
"name": "monolog/monolog",
"version": "3.10.0",
@ -4551,6 +4423,60 @@
},
"time": "2026-07-06T18:56:19+00:00"
},
{
"name": "mustangostang/spyc",
"version": "0.6.3",
"source": {
"type": "git",
"url": "https://github.com/mustangostang/spyc.git",
"reference": "4627c838b16550b666d15aeae1e5289dd5b77da0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/mustangostang/spyc/zipball/4627c838b16550b666d15aeae1e5289dd5b77da0",
"reference": "4627c838b16550b666d15aeae1e5289dd5b77da0",
"shasum": ""
},
"require": {
"php": ">=5.3.1"
},
"require-dev": {
"phpunit/phpunit": "4.3.*@dev"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.5.x-dev"
}
},
"autoload": {
"files": [
"Spyc.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "mustangostang",
"email": "vlad.andersen@gmail.com"
}
],
"description": "A simple YAML loader/dumper class for PHP",
"homepage": "https://github.com/mustangostang/spyc/",
"keywords": [
"spyc",
"yaml",
"yml"
],
"support": {
"issues": "https://github.com/mustangostang/spyc/issues",
"source": "https://github.com/mustangostang/spyc/tree/0.6.3"
},
"time": "2019-09-10T13:16:29+00:00"
},
{
"name": "nesbot/carbon",
"version": "3.13.2",

Loading…
Cancel
Save