{"id":13743349,"url":"https://github.com/UlisesGascon/tor-detect-middleware","last_synced_at":"2025-05-09T01:30:37.299Z","repository":{"id":40771271,"uuid":"206923937","full_name":"UlisesGascon/tor-detect-middleware","owner":"UlisesGascon","description":"Tor detect middleware for express","archived":false,"fork":false,"pushed_at":"2023-12-06T14:31:17.000Z","size":2263,"stargazers_count":14,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-30T18:01:49.155Z","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":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/UlisesGascon.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-09-07T06:05:44.000Z","updated_at":"2024-11-30T08:39:00.000Z","dependencies_parsed_at":"2024-01-13T10:12:51.784Z","dependency_job_id":"9410904e-ddb9-4ff6-9190-71a69358117b","html_url":"https://github.com/UlisesGascon/tor-detect-middleware","commit_stats":{"total_commits":49,"total_committers":5,"mean_commits":9.8,"dds":"0.44897959183673475","last_synced_commit":"649f15c65d731dc0fe79fca0b7f723d2d31bd5af"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UlisesGascon%2Ftor-detect-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UlisesGascon%2Ftor-detect-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UlisesGascon%2Ftor-detect-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UlisesGascon%2Ftor-detect-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UlisesGascon","download_url":"https://codeload.github.com/UlisesGascon/tor-detect-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252777355,"owners_count":21802589,"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":"2024-08-03T05:00:45.064Z","updated_at":"2025-05-09T01:30:36.594Z","avatar_url":"https://github.com/UlisesGascon.png","language":"JavaScript","funding_links":[],"categories":["Security Hardening"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003ch1 align=\"center\"\u003e\n  tor-detect-middleware\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  Tor detect middleware for Express\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.org/package/tor-detect-middleware\"\u003e\u003cimg src=\"https://badgen.net/npm/v/tor-detect-middleware\" alt=\"npm version\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.org/package/tor-detect-middleware\"\u003e\u003cimg src=\"https://badgen.net/npm/license/tor-detect-middleware\" alt=\"license\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.org/package/tor-detect-middleware\"\u003e\u003cimg src=\"https://badgen.net/npm/dt/tor-detect-middleware\" alt=\"downloads\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://snyk.io/test/github/ulisesgascon/tor-detect-middleware\"\u003e\u003cimg src=\"https://snyk.io/test/github/ulisesgascon/tor-detect-middleware/badge.svg\" alt=\"Known Vulnerabilities\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003c/p\u003e\n\n# About\n\nTor detect middleware for Express.\n\n❤️ Awesome Features:\n\n- Easy to redirect Tor or Surface users. 🔥\n- Easy to recognize TorUsers at inside the `req` object, `req.isTorUser` 🍺\n- No infra required, the database is json based using `lowdb` 🎉\n- The `strictMode` won't allow any request to access until the relays IPs are collected 📦\n- The `purge` allow you to dump the database at startup ☣️\n- `debug` is supported 💪\n- Refresh time is customizable 🧐\n- Easy to use and great test coverage ✅\n\n```js\nconst express = require('express');\nconst torUserHandler = require('tor-detect-middleware')\nconst app = express();\n\napp.use(torUserHandler())\n\napp.get('/', (req, res) =\u003e {\n  const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;\n  res.send(`Are you (${ip}) a TOR user? ${req.isTorUser}`);\n});\n\napp.listen(3000, () =\u003e {\n  console.log('We are in port 3000!');\n});\n```\n\n## Usage\n\n### Install\n\n```bash\nnpm install tor-detect-middleware\n```\n\n### simple example\n\n```js\nconst express = require('express');\nconst torUserHandler = require('tor-detect-middleware')\nconst app = express();\n\napp.use(torUserHandler())\n\napp.get('/', (req, res) =\u003e {\n  const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;\n  res.send(`Are you (${ip}) a TOR user? ${req.isTorUser}`);\n});\n\napp.listen(3000, () =\u003e {\n  console.log('We are in port 3000!');\n});\n```\n\n### Redirect Users\n\nIn this example we redirect the surface users to `https://www.nytimes.com` and Tor users to `https://www.nytimes3xbfgragh.onion/`. You can use both ways to redirect.\n\n```js\nconst express = require('express');\nconst torUserHandler = require('tor-detect-middleware')\nconst app = express();\n\napp.use(torUserHandler({\n    surface: \"https://www.nytimes.com\",\n    tor: \"https://www.nytimes3xbfgragh.onion/\"\n}))\n\napp.listen(3000, () =\u003e {\n  console.log('We are in port 3000!');\n});\n```\n\n### Ban users from surface or TOR\n\n```js\nconst express = require('express');\nconst torUserHandler = require('tor-detect-middleware')\nconst app = express();\n\napp.use(torUserHandler())\n\napp.get('/surface-only', (req, res) =\u003e {\n  if(req.isTorUser) return res.status(401).send(\"You can't access from TOR here\")\n  res.send('Welcome surface user!');\n});\n\napp.get('/tor-only', (req, res) =\u003e {\n  if(!req.isTorUser) return res.status(401).send(\"You can't access from the surface here\")\n  res.send('Welcome to the dark side. We have cookies!');\n});\n\napp.listen(3000, () =\u003e {\n  console.log('We are in port 3000!');\n});\n```\n\n### Custom Cron Jobs\n\nBy default we refresh the IP list every hour, but you can modify the ms as you wish.\n\n```js\nconst express = require('express');\nconst torUserHandler = require('tor-detect-middleware')\nconst app = express();\n\napp.use(torUserHandler({refreshMs: 600000}))\n\n//...\n```\n\n### Strict Mode\n\nSpecial behaviour in Strict mode:\n\n- The server will stop at startup if `https://onionoo.torproject.org/details` url is down\n- The server will wait until there is a list ready to dispatch requests. (Few seconds)\n\n_Note: if there is a list stored you wont surfer any problem, as we start the service from the previous list._\n\n```js\nconst express = require('express');\nconst torUserHandler = require('tor-detect-middleware')\nconst app = express();\n\napp.use(torUserHandler({\n    strictMode: true\n}))\n\n//...\n```\n\n### Purge list at start\n\nYou can purge the list by default at the startup of the service.\n\n```js\nconst express = require('express');\nconst torUserHandler = require('tor-detect-middleware')\nconst app = express();\n\napp.use(torUserHandler({\n    purge: true\n}))\n\n//...\n```\n\n## Built With\n\nDevelopment only:\n\n- [Standard](https://www.npmjs.com/package/standard) - Linting propuses\n- [Husky](https://www.npmjs.com/package/husky) - Git Hooks\n- [Nodemon](https://www.npmjs.com/package/nodemon) - Reload the process\n\nProduction only:\n\n- [debug](https://www.npmjs.com/package/debug) - Debug the app\n- [got](https://www.npmjs.com/package/got) - Download TOR infra data\n- [ip-regex](https://www.npmjs.com/package/ip-regex) - Validate relays IPs\n- [lowdb](https://www.npmjs.com/package/lowdb) - Store and query IPs\n\n## Contributing\n\nPlease read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/ulisesGascon/tor-detect-middelware/tags).\n\n## Authors\n\n- **Ulises Gascón** - *Initial work- - [@ulisesGascon](https://github.com/ulisesGascon)\n\nSee also the list of [contributors](https://github.com/ulisesGascon/tor-detect-middelware/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the GNU AGPL3.0 License - see the [LICENSE.md](LICENSE.md) file for details\n\n## Acknowledgments\n\n- This project is under development, but you can help us to improve it! We :heart: FOSS!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUlisesGascon%2Ftor-detect-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FUlisesGascon%2Ftor-detect-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUlisesGascon%2Ftor-detect-middleware/lists"}