Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/dhv3 #138

Merged
merged 12 commits into from
Aug 7, 2023
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## UNRELEASED
* Add CIDR-based blocker (configurable per client) to prevent e-mail filters (e.g. Cisco Umbrella) from invalidating a login link

## 1.0.0
* Add env MYSQL_CA_CERT for MySQL SSL connection
* Upgrade to node 16
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,18 @@ By default the required fields have labels as defined in `config/user.js`. These

## MySQL with SSL
When you want to connect to a MySQL server using SSL, a Certificate Authority certificate is required. The contents of this CA certificate can be passed into the `MYSQL_CA_CERT` environment variable.

## Block CIDRs from invalidating the login e-mail link
In some cases, e-mail filters (such as Cisco Umbrella) will invalidate the login e-mail link, because all links are visited by the filter.
To combat this, the Cisco Umbrella CIDRs are blocked by default from visiting the `/auth/url/authenticate` route.

If you need to add other CIDRs to this block, this can be done on a per client basis through the `clients` table under the `config` column:

```
"blockCidrs": [
"1.2.3.4/16",
"4.4.4.4/16"
]
```

Note: When adding your own `blockCidrs` like this, the default Cisco umbrella CIDRs will be overwritten.
3 changes: 1 addition & 2 deletions app-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,14 @@ app.use(passport.initialize());
app.use(passport.session());
app.use(expressValidator());

/*
app.use((req, res, next) => {
console.log('=====> REQUEST: ', req.originalUrl);
console.log('=====> query: ', req.query);
console.log('=====> ip: ', req.headers['x-forwarded-for'] || req.socket.remoteAddress, req.ip);
console.log('=====> body: ', req.body);
console.log('=====> session: ', req.session);
next();
});
*/

// Passport configuration
require('./auth');
Expand Down
8 changes: 6 additions & 2 deletions controllers/auth/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ exports.logout = async (req, res) => {
const config = req.client.config;
const allowedDomains = req.client.allowedDomains ? req.client.allowedDomains : false;
let redirectURL = req.query.redirectUrl;
const redirectUrlHost = redirectURL ? new URL(redirectURL).hostname : false;
redirectURL = redirectUrlHost && allowedDomains && allowedDomains.indexOf(redirectUrlHost) !== -1 ? redirectURL : false;
try {
const redirectUrlHost = redirectURL ? new URL(redirectURL).hostname : false;
redirectURL = redirectUrlHost && allowedDomains && allowedDomains.indexOf(redirectUrlHost) !== -1 ? redirectURL : false;
} catch (e) {
//
}

if (!redirectURL) {
redirectURL = config && config.logoutUrl ? config.logoutUrl : req.client.siteUrl
Expand Down
29 changes: 29 additions & 0 deletions middleware/blocker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const Netmask = require('netmask').Netmask;

exports.preventCiscoRequest = (req, res, next) => {

// Fix for local IP
if (req.ip == '::1') {
return next();
}

// Get CIDRs from client config. If the `blockCidrs` key doesn't exist fall back to Cisco Umbrella CIDRs
// See https://support.umbrella.com/hc/en-us/articles/360059292052-Additional-Egress-IP-Address-Range
const blockCidrs = req && req.client && req.client.config && req.client.config.blockCidrs ? req.client.config.blockCidrs : ['146.112.0.0/16', '155.190.0.0/16', '151.186.0.0/16'];

// Check if IP is in cidr
const isIpInCidr = blockCidrs.some(cidr => {
const block = new Netmask(cidr);
return block.contains(req.ip);
});

if (!isIpInCidr) {
return next();
}

console.log('IP is in CIDRs to block', req.ip, blockCidrs, isIpInCidr);

req.flash('error', {msg: 'De url is geen geldige login url, wellicht is deze verlopen'});
return res.redirect(`/auth/url/login?clientId=${req.query.clientId}`);

}
Loading
Loading