feat: skip public API calls for non-routable IP addresses#320
Open
Dev9269 wants to merge 2 commits into
Open
Conversation
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
✅ Deploy Preview for web-check ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
lissy93
reviewed
Jul 24, 2026
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; | ||
| } | ||
| } |
Owner
There was a problem hiding this comment.
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 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 }); | ||
| }); | ||
| }); |
Owner
There was a problem hiding this comment.
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.
Contributor
Author
|
Thanks for the review @lissy93 — you were right on all points. I've rewritten the whole thing:
The branch has been updated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.
Closes #302