{"id":28398407,"url":"https://github.com/primus/forwarded-for","last_synced_at":"2025-07-08T07:09:46.190Z","repository":{"id":13621575,"uuid":"16314810","full_name":"primus/forwarded-for","owner":"primus","description":"Abstraction for retrieving ip address information from a Node.js connection. Searches for proxy headers before degrading req.address","archived":false,"fork":false,"pushed_at":"2023-01-02T20:09:33.000Z","size":46,"stargazers_count":20,"open_issues_count":1,"forks_count":8,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-01T13:16:01.780Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/primus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-01-28T14:56:49.000Z","updated_at":"2024-08-05T03:17:06.000Z","dependencies_parsed_at":"2023-01-13T17:33:38.770Z","dependency_job_id":null,"html_url":"https://github.com/primus/forwarded-for","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/primus/forwarded-for","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primus%2Fforwarded-for","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primus%2Fforwarded-for/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primus%2Fforwarded-for/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primus%2Fforwarded-for/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/primus","download_url":"https://codeload.github.com/primus/forwarded-for/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/primus%2Fforwarded-for/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262444717,"owners_count":23312212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-01T04:38:45.272Z","updated_at":"2025-06-28T14:31:13.135Z","avatar_url":"https://github.com/primus.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# forwarded-for\n\n[![Version npm](http://img.shields.io/npm/v/forwarded-for.svg?style=flat-square)](https://www.npmjs.com/package/forwarded-for)[![CI](https://img.shields.io/github/actions/workflow/status/primus/forwarded-for/ci.yml?branch=master\u0026label=CI\u0026style=flat-square)](https://github.com/primus/forwarded-for/actions?query=workflow%3ACI+branch%3Amaster)[![Coverage Status](http://img.shields.io/coveralls/primus/forwarded-for/master.svg?style=flat-square)](https://coveralls.io/r/primus/forwarded-for?branch=master)\n\nWhen you are hosting your applications behind a reverse load balancer the\nincoming requests will no longer have the IP address of your user but of the\nload balancer as it forwards the request to your node instance. Most load\nbalancers allow you to modify the headers of the request and add original\nrequest information in it.\n\nThis module makes it easier to find the correct IP address of your connection by\ndetecting these headers that load balancers set and it will gracefully fall down\nto the original `req.address` that contained the IP address of the request\ninside node.js. In addition to gracefully degrading to the original request we\nalso for other known locations of the address (which are usually set by\nframeworks such as SockJS and Socket.IO etc.)\n\n## Installation\n\nThe module is released in the npm registry:\n\n```\nnpm install --save forwarded-for\n```\n\n## Getting started\n\nLet's start out with including the module in to your application:\n\n```js\n'use strict';\n\nvar forwarded = require('forwarded-for');\n```\n\nThe `forwarded` variable will now contain the function which parses out the\nrequest information for you in to a really simple object. This object contains\nthe following properties:\n\n- `port` The remote port. It defaults to `0`.\n- `ip` The string representation of the remoteAddress. It defaults to '127.0.0.1'.\n\nWhen we fail to parse or detect an IP address we will use the default values to\nconstruct the object. To correctly parse the data the function requires the\nfollowing arguments:\n\n- `obj` The socket like object that probably contains the remoteAddress\n- `headers` A reference to the HTTP headers of the request\n- `whitelist`, _optional_ A white list of IP addresses of your load balancers so\n  people cannot make fake requests with `x-forwarded-for` headers.\n\nSo with all the information combined, it would look something like this:\n\n```js\n'use strict';\n\nvar forwarded = require('forwarded-for');\n\nrequire('http').createServer(function (req, res) {\n  var address = forwarded(req, req.headers);\n\n  res.end('Your ip address is '+ address.ip);\n}).listen(8080);\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprimus%2Fforwarded-for","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprimus%2Fforwarded-for","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprimus%2Fforwarded-for/lists"}