Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
The 'isbot' npm package is a lightweight utility for detecting bots, crawlers, and spiders based on the user agent string. It helps developers identify non-human traffic to their websites or applications.
Basic Bot Detection
This feature allows you to check if a given user agent string belongs to a bot. The function returns true if the user agent is identified as a bot, otherwise false.
const isBot = require('isbot');
const userAgent = 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)';
console.log(isBot(userAgent)); // true
Custom Bot Patterns
You can extend the default bot detection patterns with custom patterns. This is useful if you have specific bots that are not covered by the default list.
const isBot = require('isbot');
isBot.extend(['my-custom-bot']);
const userAgent = 'my-custom-bot';
console.log(isBot(userAgent)); // true
Bot Detection in HTTP Requests
This feature demonstrates how to use 'isbot' to detect bots in incoming HTTP requests. Depending on whether the user agent is a bot, the server responds with a different message.
const isBot = require('isbot');
const http = require('http');
http.createServer((req, res) => {
if (isBot(req.headers['user-agent'])) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, bot!');
} else {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello, human!');
}
}).listen(3000);
The 'useragent' package provides detailed parsing of user agent strings, including bot detection. It offers more comprehensive information about the user agent, such as browser, version, and OS, but may be more complex to use compared to 'isbot'.
The 'express-useragent' package is an Express middleware for parsing user agent strings. It includes bot detection and provides additional details about the user agent. It is specifically designed for use with Express.js applications.
The 'ua-parser-js' package is a JavaScript library for parsing user agent strings. It includes bot detection and provides detailed information about the browser, engine, OS, and device. It is a more general-purpose library compared to 'isbot'.
Detect bots/crawlers/spiders using the user agent string.
const isbot = require('isbot');
// Nodejs HTTP
isbot(request.getHeader('User-Agent'))
// ExpressJS
isbot(req.get['user-agent'])
// User Agent string
isbot('Googlebot/2.1 (+http://www.google.com/bot.html)') // true
isbot('Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36') // false
Add rules to user agent match RegExp
isbot('Mozilla/5.0') // false
isbot.extend([
'istat',
'httpclient',
'^mozilla/\\d\\.\\d$'
])
isbot('Mozilla/5.0') // true
Remove rules to user agent match RegExp (see existing rules in list.json
file)
isbot('Google Page Speed Insights') // true
isbot.exclude([
'Google Page Speed Insights',
'Chrome-Lighthouse'
])
isbot('Google Page Speed Insights') // false
Return the respective match for bot user agent rule
isbot.find('Googlebot/2.1 (+http://www.google.com/bot.html)') // 'bot'
This package aims to identify "Good bots". Those who voluntarily identify themselves by setting a unique, preferably descriptive, user agent, usually by setting a dedicated request header.
It does not try to recognise malicious bots or programs disguising themselves as real users.
Recognising good bots such as web crawlers is useful for multiple purposes. Although it is not recommended to serve different content to web crawlers like Googlebot, you can still elect to
It is not recommended to whitelist requests for any reason based on user agent header only. Instead other methods of identification can be added such as reverse dns lookup.
Add patterns for:
Add some legit browser user-agent strings Fix periodic tests environment Add a tester page to check user agents easily
FAQs
🤖/👨🦰 Recognise bots/crawlers/spiders using the user agent string.
The npm package isbot receives a total of 230,893 weekly downloads. As such, isbot popularity was classified as popular.
We found that isbot demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.