Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature: Local IP information in local cf object

See original GitHub issue


Deployed Cloudflare workers offer the useful cf object, which provides Cloudflare-specific data from their edge network. Among these is the ASN, ASO, country, of the remote client IP. This data is especially useful as it cuts out an extra step in look up this data with an external service.

Since miniflare is not deployed on the Cloudflare edge, it does not provide this data. In fact, this data is explicitly overridden in the file miniflare/src/index.ts (lines 375-395).

This feature seeks to explore ways to replace some of the data in the cf object.

Targeted sources files and dependencies

  • miniflare/src/index.ts
    • contains the cf object and the overridden fields
    • this feature would alter the overridden fields to values from the locally ingested ip info
  • local ip info ingestion
    • somewhere we would be allowing the ingestion of a local ip info db, such as a .mmdb
    • this could potentially be done from the command line interface like many of the other miniflare configurations as an optional CLI flag/arg

Benefits of this feature

  • build consistent systems that rely on the Workers cf object for IP geo/whois data, even when running locally with miniflare

Risks of this feature

  • the cf object is data from the Cloudflare edge network. Supplementing the data in the cf object with data sourced from elsewhere is potentially confusing at best, misrepresentation at worst.

Fields in cf object marked for IP info

Below are a list of fields within the cf object that could make use of data from a local IP geo/whois database. I have also subjectively marked them as either geo or whois as that may determine the database to be used.

  • cf.asn: whois
  • cf.asOrganization: whois
  • geo
  • geo
  • cf.continent: geo
  • cf.latitude: geo
  • cf.longitude: geo
  • cf.postalCode: geo
  • cf.metroCode: geo
  • cf.region: geo
  • cf.regionCode: geo
  • cf.timezone: geo

Reference materials

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

mrbbotcommented, Oct 8, 2021

Ah ok, that makes sense. Running miniflare on your own network is definitely a use case I’d like to support, especially now that Miniflare 2 lets you run multiple miniflare instances using the same (Redis) database and still maintain proper Durable Object transaction semantics. How about a function option like cfProvider that accepts a Node request object and returns values for the cf object and CF-* headers? This would default to using the (cached) trustable HTTP endpoint, but could be customised to use a local IP database.

Electroidcommented, Oct 8, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

HTTP request headers · Cloudflare Fundamentals docs
Cloudflare passes all HTTP request headers to your origin web server and adds additional headers as specified below. ​​ CF-Connecting-IP. CF- ...
Read more >
How to get a client IP Address in Node.js (6 ways) - Abstract API
1. Retrieve User IP Address From the Request Object's Socket Property · 2. Retrieve Multiple IP Addresses With the X-Forwarded-For (XFF) Header.
Read more >
How to determine a user's IP address in node - Stack Overflow
remoteAddress the property will contain the private IP address of the load balancer rather than the public IP address of the client. By...
Read more >
Local IP — Neutron 21.1.0.dev258 documentation
Local IP is a virtual IP that can be shared across multiple ports/VMs (similar to anycast IP) and is guaranteed to only be...
Read more >
Conf - SpamAssassin configuration file
The following options can be used in both site-wide ( ) and ... host's IP address, and to record the result in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found