Skip to content

feat: skip public API calls for non-routable IP addresses#320

Open
Dev9269 wants to merge 2 commits into
lissy93:masterfrom
Dev9269:feat/skip-non-routable-ips
Open

feat: skip public API calls for non-routable IP addresses#320
Dev9269 wants to merge 2 commits into
lissy93:masterfrom
Dev9269:feat/skip-non-routable-ips

Conversation

@Dev9269

@Dev9269 Dev9269 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Adds a utility to detect non-routable (private/local) IP addresses and skips external API calls for them. Currently implemented for the Wayback Machine / archives check.

  • Added �pi/_common/is-non-routable.js - utility to detect private IPv4 ranges (10.x, 172.16-31.x, 192.168.x, 127.x, 169.254.x, 0.x) and IPv6 (loopback, unique-local, link-local)
  • Modified �pi/archives.js - skip Wayback Machine lookup for non-routable targets

Closes #302

Adds a non-routable IP check to the archives handler to avoid
wasting bandwidth on external API calls for private/local IPs.

Closes lissy93#302
@netlify

netlify Bot commented Jul 16, 2026

Copy link
Copy Markdown

Deploy Preview for web-check ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 8bfea37
🔍 Latest deploy log https://app.netlify.com/projects/web-check/deploys/6a639b8cf9e2240008dca3e2
😎 Deploy Preview https://deploy-preview-320--web-check.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@lissy93 lissy93 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Dev9269

But right now there's some logic bugs here, and the code is much longer and more complicated than it needs to be.

Comment thread api/_common/is-non-routable.js Outdated
Comment on lines +15 to +26
if (range.mask !== null) {
if (ip.startsWith(range.prefix)) {
const octets = ip.split('.').map(Number);
if (octets.length === 4) {
const ipNum = (octets[0] << 24) | (octets[1] << 16) | (octets[2] << 8) | octets[3];
const masked = ipNum >>> (32 - range.maskBits);
const rangeStart = (parseInt(range.prefix.split('.')[0]) << 24) |
(parseInt(range.prefix.split('.')[1]) << 16);
const rangeMasked = rangeStart >>> (32 - range.maskBits);
if (masked === rangeMasked) return true;
}
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code seems overly long and quite confusing. It's hard to follow, possibly AI/slop.

It also seems to not be working, as:

  • It misses real private IPs, like 172.16-172.31 range
  • And it wrongly blocks normal public addresses, like 172.0 - 172.15

Comment thread api/_common/is-non-routable.js Outdated
Comment on lines +43 to +49
const lookupAsync = (hostname) =>
new Promise((resolve, reject) => {
dns.lookup(hostname, (err, ip, family) => {
if (err) reject(err);
else resolve({ ip, family });
});
});

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to create your own helper here, we don't like callbacks, and the rest of the code already uses built-in promise api

…range

Replaces the complex bit-math with simple numeric range checks that
correctly handle 172.16-172.31 without blocking 172.0-172.15.
Replaces callback-based dns.lookup with dns.promises.
@Dev9269

Dev9269 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review @lissy93 — you were right on all points. I've rewritten the whole thing:

  • 172.x range fixed: now uses simple numeric comparison (parts[1] >= 16 && parts[1] <= 31) — no bit shifting, no false positives
  • **Removed \lookupAsync**: using native \dns.promises.lookup\ instead of callbacks
  • Dropped from 65 lines to 44 lines, much simpler to follow

The branch has been updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Don't bother using public APIs on non-routable IP addresses

2 participants