
Research
/Security News
Malicious npm Packages Target WhatsApp Developers with Remote Kill Switch
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
A service to parse user-agent strings in C#. UserAgentService is extremely fast because it uses in-memory caching. UserAgentService only looks at the first 512 characters of the useragent string, it ignores the rest of the string. Most user-agent strings are within this limit but this limitation is introduced to protect itself from malicious, extremely long, hand crafted, user-agent strings.
Microsoft.Extensions.Caching.Memory
Microsoft.Extensions.Options
Install from Nuget
Install-Package Ng.UserAgentService
Console application
using Ng.Services;
...
//You do not have to specify any settings if you want to use the defaults
var settings = new UserAgentSettings
{
CacheSizeLimit = 20000, //Default: 10000
CacheSlidingExpiration = TimeSpan.FromDays(1), //Default: TimeSpan.FromDays(3)
UaStringSizeLimit = 256, //Default: 512
};
var userAgentService = new UserAgentService(settings);
var ua = userAgentService.Parse("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0");
var isBrowser = ua.IsBrowser; // true
var isRobot = ua.IsRobot; // false
var isMobile = ua.IsMobile; // false
var platform = ua.Platform; // Windows 7
var bowser = ua.Browser; // Firefox
var version = ua.BrowserVersion; // 47.0
var mobile = ua.Mobile; // empty string
var robot = ua.Robot; // empty string
ASP.NET Core
Register service with dependency injection in Startup.cs
using Ng.Services;
...
public void ConfigureServices(IServiceCollection services)
{
services.AddUserAgentService(); //Is equivalent to services.AddSingleton<IUserAgentService, UserAgentService>();
or
services.AddUserAgentService(options => {
options.CacheSizeLimit = 20000; //Default: 10000
options.CacheSlidingExpiration = TimeSpan.FromDays(1); //Default: TimeSpan.FromDays(3)
options.UaStringSizeLimit = 256; //Default: 512
});
or
services.AddSingleton<IUserAgentService, UserAgentService>(); //Is equivalent to services.AddUserAgentService();
}
Inject IUserAgentService into a Controller or wherever you like
using Ng.Services;
...
public class MyController
{
public MyController(IUserAgentService userAgentService) // <-- Inject IUserAgentService here
{
string userAgentString = Request.Headers["User-Agent"].ToString();
UserAgent ua = userAgentService.Parse(userAgentString);
}
}
This project is licensed under the MIT License.
Contributions are welcome.
FAQs
A service to parse user-agent strings in C#.
We found that ng.useragentservice demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.
Research
/Security News
Socket uncovered 11 malicious Go packages using obfuscated loaders to fetch and execute second-stage payloads via C2 domains.
Security News
TC39 advances 11 JavaScript proposals, with two moving to Stage 4, bringing better math, binary APIs, and more features one step closer to the ECMAScript spec.