{"id":22355538,"url":"https://github.com/zbo14/fastify-net-acl","last_synced_at":"2026-05-02T01:33:49.844Z","repository":{"id":57233333,"uuid":"414070994","full_name":"zbo14/fastify-net-acl","owner":"zbo14","description":"🚫 Fastify plugin that restricts access to IP addresses/subnets.","archived":false,"fork":false,"pushed_at":"2022-01-25T16:40:02.000Z","size":260,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-19T17:41:59.278Z","etag":null,"topics":["acl","allowlist","blocklist","fastify","ip","ip-address","ipv4","ipv6","networking"],"latest_commit_sha":null,"homepage":"","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/zbo14.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":"2021-10-06T04:42:32.000Z","updated_at":"2022-01-25T15:59:26.000Z","dependencies_parsed_at":"2022-08-31T20:51:22.667Z","dependency_job_id":null,"html_url":"https://github.com/zbo14/fastify-net-acl","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Ffastify-net-acl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Ffastify-net-acl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Ffastify-net-acl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zbo14%2Ffastify-net-acl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zbo14","download_url":"https://codeload.github.com/zbo14/fastify-net-acl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245659051,"owners_count":20651525,"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":["acl","allowlist","blocklist","fastify","ip","ip-address","ipv4","ipv6","networking"],"created_at":"2024-12-04T14:07:07.869Z","updated_at":"2026-05-02T01:33:49.801Z","avatar_url":"https://github.com/zbo14.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastify-net-acl\n\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)\n\nFastify plugin that restricts access according to IP address/subnet allow and block lists.\n\n## Install\n\n`npm i fastify-net-acl`\n\n## Usage\n\n### Blocking\n\n**Block IP address:**\n\n```js\nfastify.register(require('fastify-net-acl'), {\n  blockList: '1.2.3.4'\n})\n```\n\n**Block multiple IP addresses:**\n\n```js\nfastify.register(require('fastify-net-acl'), {\n  blockList: [\n    '1.2.3.4',\n    '2.3.4.5'\n  ]\n})\n```\n\n**Block subnet:**\n\n```js\nfastify.register(require('fastify-net-acl'), {\n  blockList: '1.2.3.4/24'\n})\n```\n\n**Block a bunch of stuff:**\n\n```js\nfastify.register(require('fastify-net-acl'), {\n  blockList: [\n    '::1',\n    '4.3.2.1',\n    '4.2.3.4',\n    '1.2.3.4/24',\n    '2.3.4.5/16'\n  ]\n})\n```\n\n### Allowing\n\n**Only allow 1 IP address:**\n\n```js\nfastify.register(require('fastify-net-acl'), {\n  allowList: '1.2.3.4'\n})\n```\n\n**Only allow 1 subnet:**\n\n```js\nfastify.register(require('fastify-net-acl'), {\n  allowList: '1.2.3.4/24'\n})\n```\n\n**Only allow specified IP addresses and subnets:**\n\n```js\nfastify.register(require('fastify-net-acl'), {\n  allowList: [\n    '::1',\n    '2.3.4.5',\n    '1.2.3.4/24'\n  ]\n})\n```\n\n### Route specific rules\n\n**Note:** you must `await` the plugin registration so the decorator function is accessible for the route definition.\n\n```js\nawait fastify.register(require('fastify-net-acl'), {\n  blockList: '1.2.3.4/24',\n  global: false\n})\n\nconst onRequest = fastify.createNetAclRequestHandler()\n\nfastify.get('/has-blocking', { onRequest }, (req, reply) =\u003e {})\nfastify.get('/no-blocking', (req, reply) =\u003e {})\n```\n\n**Use multiple allow/block lists:**\n\n```js\nawait fastify.register(require('fastify-net-acl'), {\n  allowList: {\n    foo: '1.2.3.4/24'\n  },\n\n  blockList: {\n    bar: '2.3.4.5/24'\n  },\n\n  global: false\n})\n\n{\n  const onRequest = fastify.createNetAclRequestHandler('allow:foo')\n  fastify.get('/foo', { onRequest }, (req, reply) =\u003e {})\n}\n\n{\n  const onRequest = fastify.createNetAclRequestHandler('block:bar')\n  fastify.get('/bar', { onRequest }, (req, reply) =\u003e {})\n}\n\nfastify.get('/no-blocking', (req, reply) =\u003e {})\n```\n\n## Reference\n\nThis plugin decorates the `fastify` instance with `allowList` and/or `blockList`, depending on which properties are specified in `options`. Both are instances of [`net.BlockList`](https://nodejs.org/docs/latest-v16.x/api/net.html#class-netblocklist) and determine which IP addresses/subnets are allowed or blocked, respectively.\n\n**Note:** `fastify-net-acl` requires Node \u003e= 15.0.0 since `net.Blocklist` was introduced in 15.0.0.\n\nThe `options` object has the following properties. Either `allowList` xor `blockList` must be specified if `global` is `true`. Both may be specified if `global` is `false` since you may want to use different allow/block lists on different routes.\n\n* `allowList` is a string, array of strings, or object with those values- of IPv4/IPv6 addresses and/or subnets in CIDR format indicating which IPs should be allowed\n* `blockList` is a string, array of strings, or object with those values- of IPv4/IPv6 addresses and/or subnets in CIDR format indicating which IPs should be blocked\n* `errorCode` is the HTTP status code when an IP is blocked/not allowed (default: `403`)\n* `errorMessage` is the status message when an IP is blocked/not allowed (default: generic status message for `errorCode`)\n* `global` is a boolean indicating whether the ACL applies globally, i.e. for all routes (default: `true`)\n\n## Test\n\n`npm test`\n\n## Lint\n\n`npm run lint` or `npm run lint:fix`\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbo14%2Ffastify-net-acl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzbo14%2Ffastify-net-acl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzbo14%2Ffastify-net-acl/lists"}