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

Only allow internal addresses to update FS and RTP caches #44

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions lib/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
const CIDRMatcher = require('cidr-matcher');
const debug = require('debug')('jambonz:sbc-options-handler');
const fsServers = new Map();
const fsServiceUrls = new Map();
const rtpServers = new Map();

const internalNetwork = new CIDRMatcher(
[(process.env.JAMBONES_NETWORK_CIDR ?? ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16'])].flat()
);

module.exports = ({srf, logger}) => {
const {stats, addToSet, removeFromSet, isMemberOfSet, retrieveSet} = srf.locals;

Expand Down Expand Up @@ -104,21 +109,24 @@ module.exports = ({srf, logger}) => {
};

return async(req, res) => {
const {srf, source_address, locals: {logger}} = req;

/* OPTIONS ping from internal FS or RTP server? */
const internal = req.has('X-FS-Status') || req.has('X-RTP-Status');
if (!internal) {
if (!internalNetwork.contains(source_address)) {
if (req.has('X-FS-Status') || req.has('X-RTP-Status')) {
logger.info('Received external OPTIONS with internal header(s)');
}
debug('got external OPTIONS ping');
res.send(200);
return req.srf.endSession(req);
return srf.endSession(req);
}

try {
let map, status, countOfMembers;
const h = ['X-FS-Status', 'X-RTP-Status'].find((h) => req.has(h));
if (h) {
const isRtpServer = req.has('X-RTP-Status');
const key = isRtpServer ? req.source_address : `${req.source_address}:${req.source_port}`;
const key = isRtpServer ? source_address : `${source_address}:${req.source_port}`;
const prefix = isRtpServer ? 'X-RTP' : 'X-FS';
map = isRtpServer ? rtpServers : fsServers;
const setName = isRtpServer ? setNameRtp : setNameFs;
Expand All @@ -141,6 +149,6 @@ module.exports = ({srf, logger}) => {
debug(err);
logger.error({err}, 'Error handling OPTIONS');
}
return req.srf.endSession(req);
return srf.endSession(req);
};
};
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
"homepage": "https://github.com/jambonz/sbc-sip-sidecar#readme",
"dependencies": {
"@jambonz/db-helpers": "^0.9.1",
"@jambonz/digest-utils": "^0.0.3",
"@jambonz/mw-registrar": "^0.2.4",
"@jambonz/realtimedb-helpers": "^0.8.7",
"@jambonz/stats-collector": "^0.1.9",
"@jambonz/time-series": "^0.2.5",
"@jambonz/digest-utils": "^0.0.3",
"cidr-matcher": "^2.1.1",
"debug": "^4.3.4",
"drachtio-mw-registration-parser": "^0.1.0",
"drachtio-mw-response-time": "^1.0.2",
Expand Down