Skip to content

Commit 54ab7f0

Browse files
committed
Fixed blank CDN Determination instead of Unknown
1 parent 19ca225 commit 54ab7f0

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Changelog
22

3-
## [1.6.1] - *Unreleased*
3+
## [1.6.1] - 5<sup>th</sup> February 2021
44

55
### Changed
66

77
* Fixed a bug in `--debug` output which reported the number of unique domains as `undefined`.
88
* Fixed an incorrect JSON property name type in the internal default settings (i.e. the ones used if `default.json` isn't loaded correctly).
99
* Updated dependency `open` to version `7.4.0`.
10+
* Fixed a bug which would result in a blank CDN Determination status instead of `Unknown`.
1011

1112
---
1213

ccc-dns.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const CCC_CDN_DETERMINATION_STATUS = {
77
INDETERMINATE: 'Indeterminate',
88
CDN: 'CDN',
99
ERROR: 'Error',
10+
AWS: 'AWS',
1011
OTHER: 'Other Internet Service'
1112
};
1213
const CCC_DNS_DEFAULT_RESOLVER = '8.8.8.8';
@@ -208,23 +209,30 @@ module.exports = {
208209
}
209210
}
210211

212+
211213
// Check if the DNS chain inspection didn't identify it as a CDN
212214
if (cdnResponse.status != CCC_CDN_DETERMINATION_STATUS.CDN) {
215+
debug('%s\'s DNS recursion didn\'t match a known CDN provider\'s domain');
213216
// Get the IP address from the DNS answer
217+
debug('Extracting the IP address from the DNS answer');
214218
cdnResponse.ipAddress = module.exports.parseAnswer(answer.answer, {});
215219
// DNS didn't yield a conclusive answer. Check the IP Address against the AWS service list
216220
let awsServicesFile = __dirname + pathSeparator + 'service.providers/aws/ip-ranges.json';
217221
let rawData = fs.readFileSync(awsServicesFile); // Read the AWS services file
218222
let awsServices = JSON.parse(rawData); // Parse it into a JSON object
219-
let message = new String; // Temporarily store the message because the AWS JSON might contain two matching CIDR blocks, so we can't just concatenate
223+
let message = '';//new String; // Temporarily store the message because the AWS JSON might contain two matching CIDR blocks, so we can't just concatenate
224+
220225
// Loop through each service
226+
debug('Checking if the IP address [%s] matches a known AWS service');
221227
for (let i = 0; i < awsServices.prefixes.length; i++) {
222228
// Create a cidr object based on current service's IP prefix range
223229
const cidr = new IPCIDR(awsServices.prefixes[i].ip_prefix);
224230

225231
// Check if the IP address exists within the cidr block
226232
if (cidr.contains(cdnResponse.ipAddress)) {
233+
debug('%s is in the CIDR block %s, which is AWS service %s', cdnResponse.ipAddress, awsServices.prefixes[i].ip_prefix, awsServices.prefixes[i].service);
227234
message = awsServices.prefixes[i].service;
235+
cdnResponse.status = CCC_CDN_DETERMINATION_STATUS.AWS;
228236
//cdnResponse.message = awsServices.prefixes[i].service; // Put the service name into the return object's message
229237
cdnResponse.reason = `${cdnResponse.ipAddress} is in the CIDR block ${awsServices.prefixes[i].ip_prefix} which is used by AWS ${awsServices.prefixes[i].service}`;
230238

@@ -243,10 +251,15 @@ module.exports = {
243251
}
244252
}
245253
}
246-
if (cdnResponse.message === 'Unknown') {
247-
cdnResponse.message = message; // Replace the current message with a more precise AWS specific detection
248-
} else {
249-
cdnResponse.message += ', ' + message; // Append the AWS detection message to the DNS detection message
254+
255+
if (cdnResponse.status === CCC_CDN_DETERMINATION_STATUS.AWS) {
256+
if (cdnResponse.message === 'Unknown') {
257+
debug('Replacing the message [%s] with [%s]', cdnResponse.message, message);
258+
cdnResponse.message = message; // Replace the current message with a more precise AWS specific detection
259+
} else {
260+
debug('Replacing the message [%s] with [%s]', cdnResponse.message, cdnResponse.message += ', ' + message);
261+
cdnResponse.message += ', ' + message; // Append the AWS detection message to the DNS detection message
262+
}
250263
}
251264

252265
}

0 commit comments

Comments
 (0)