
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
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 72 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
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.