add edgeone ip range fetch#5634
Open
tianq02 wants to merge 1 commit into
Open
Conversation
|
Docker Image for build 1 is available on DockerHub: Note Ensure you backup your NPM instance before testing this image! Especially if there are database changes. Warning Changes and additions to DNS Providers require verification by at least 2 members of the community! |
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.
Why
I am using EdgeOne as CDN service for my server, and NPM is not correctly handling its IP header out of the box, giving downstream hosts CDN node's IP as X-Real-IP, which is a security hazard.
Digging into the code, It seems like Cloudflare and CloudFront are already supported, so I built
ip_ranges_eo.jsmimicing existing design. We built its core api call imitating tencent cloud's nodejs demo code here(http request, nodejs), this doesn't bring any additional dependencies. I used gemini to refactor these demo code into a reuseable function.Previously,
IP_RANGES_FETCH_ENABLED='false'only skips initial fetch, timer is always running and npm is still periodically fetching IP ranges, which seems to be a logic bug. I refactoredindex.jsto fix these logic, now we have a second envIP_RANGES_TIMER_ENABLEDto control its behaviour. Unset defaults to 'auto', which means enable the timer only if the initial fetch succeeds. Beware this is likely a breaking change, now settingIP_RANGES_FETCH_ENABLED='false'also disables the timer.EdgeOne doesn't include X-Real-IP header by default, so I edited nginx.conf to use XFF header instead, this shouldn't break anything.
This module is by default disabled, since EdgeOne IP range fetch is paywalled and it requires a quite involving credential setup. So I made a detailed documentation for it, which is also included in this pr, you can read it here
Type of Change
AI Usage