Skip to content

Commit

Permalink
more logging & debuggin
Browse files Browse the repository at this point in the history
  • Loading branch information
kafkasl committed Apr 26, 2022
1 parent 6bb4005 commit 8c54cf9
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/utils/authMiddlewares.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,27 @@ const checkAuthExpiredMiddleware = (req, res, next) => {
return true;
}

console.log('isReqFromLocalhost throwing error');
throw new Error('ip address is not localhost');
};

const isReqFromCluster = async () => {
console.log('isReqFromCluster');
const domains = await dns.reverse(req.ip);
let domains;
try {
domains = await dns.reverse(req.ip);
} catch (e) {
console.log('isReqFromCluster error: ', e);
}

console.log('isReqFromCluster domains ', domains);
if (!domains.some((domain) => INTERNAL_DOMAINS_REGEX.test(domain))) {
if (domains.some((domain) => INTERNAL_DOMAINS_REGEX.test(domain))) {
console.log('isReqFromCluster throwing error');
throw new Error('ip address does not come from internal sources');
return true;
}

return true;
console.log('isReqFromCluster throwing error');
throw new Error('ip address does not come from internal sources');
};

console.log('lcs [URL,METHOD]: ', req.method.toLowerCase(), req.url);
Expand All @@ -125,16 +132,20 @@ const checkAuthExpiredMiddleware = (req, res, next) => {
// JWT `exp` returns seconds since UNIX epoch, conver to milliseconds for this
const timeLeft = (req.user.exp * 1000) - Date.now();

// ignore if JWT is still valid
if (timeLeft > 0) {
return next();
}
// temporarily ignore valid token to debug patch cellsets
if (!(req.url.includes('cellSets') && req.method.toLowerCase() === 'patch')) {
// ignore if JWT is still valid
if (timeLeft > 0) {
return next();
}

console.log('lcs time left in token ', timeLeft);
// send error if JWT is older than the limit
if (timeLeft < -(7 * 1000 * 60 * 60)) {
console.log('lcs rejecting very expired token');
return next(new UnauthenticatedError('token has expired'));

console.log('lcs time left in token ', timeLeft);
// send error if JWT is older than the limit
if (timeLeft < -(7 * 1000 * 60 * 60)) {
console.log('lcs rejecting very expired token');
return next(new UnauthenticatedError('token has expired'));
}
}

// check if we should ignore expired jwt token for this path and request type
Expand All @@ -156,7 +167,8 @@ const checkAuthExpiredMiddleware = (req, res, next) => {
.then(() => {
next();
})
.catch(() => {
.catch((e) => {
console.log('lcs error in promise any: ', e);
next(new UnauthenticatedError('token has expired'));
});

Expand Down

0 comments on commit 8c54cf9

Please sign in to comment.