
Research
Malicious fezbox npm Package Steals Browser Passwords from Cookies via Innovative QR Code Steganographic Technique
A malicious package uses a QR code as steganography in an innovative technique.
express-defender
Advanced tools
Express middleware to enforce domain and country-based access, blocking direct IP requests and unwanted bots.
Express middleware to enforce domain and country-based access, blocking direct IP requests and unwanted bots.
npm i express-defender
const express = require('express');
const expressDefender = require('express-defender');
const app = express();
app.use(expressDefender({
allowedDomains: ['example.com'],
allowedCountries: ['BR', 'US']
}));
app.get('/', (req, res) => {
res.json(req.expressDefender);
});
app.listen(3000, () => console.log('Server running on http://localhost:3000'));
Option | Type | Default | Description |
---|---|---|---|
allowedDomains | string[] | ['*'] | List of allowed domains. Accepts * to allow all. E.g., ['example.com'] also allows www.example.com and api.example.com . |
allowedCountries | string[] | ['*'] | List of allowed countries (ISO Alpha-2). Use * to allow all. |
allowedBots | RegExp[] | Googlebot, Bingbot, Slurp, DuckDuckBot | List of User-Agents of bots authorized to ignore country/domain restrictions. |
log | boolean | true | Enables or disables logging in the console. |
• Allow all domains and countries
app.use(expressDefender({
allowedDomains: ['*'],
allowedCountries: ['*']
}));
• Allow only the US and Canada
app.use(expressDefender({
allowedCountries: ['US', 'CA']
}));
• Allow only direct requests from mysite.com and Googlebot
app.use(expressDefender({
allowedDomains: ['mysite.com'],
allowedBots: [/Googlebot/]
}));
• Output of req.expressDefender
{
"ip": "192.0.2.25",
"country": "BR",
"region": "SP",
"city": "SP",
"method": "GET",
"url": "/home",
"fromDomain": true,
"isBot": false
}
• Logs when
Bot Acess
Localhost Acess
Sucessful Acess
Blocked Acess by Country
Blocked Acess by direct IP traffic
Blocked Acess by Country and direct IP traffic
respectively.
Contributions are welcome! Please feel free to open an issue or submit a pull request, for bug fixes or new features.
git checkout -b <new-feature-name>
git commit -am "Add new feature"
git push origin <new-feature-name>
FAQs
Express middleware to enforce domain and country-based access, blocking direct IP requests and unwanted bots.
The npm package express-defender receives a total of 4 weekly downloads. As such, express-defender popularity was classified as not popular.
We found that express-defender demonstrated a healthy version release cadence and project activity because the last version was released less than 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
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.
Application Security
/Research
/Security News
Socket detected multiple compromised CrowdStrike npm packages, continuing the "Shai-Hulud" supply chain attack that has now impacted nearly 500 packages.