{"id":14989543,"url":"https://github.com/ruisiang/pow-shield","last_synced_at":"2025-05-16T04:06:08.303Z","repository":{"id":37072230,"uuid":"345595504","full_name":"RuiSiang/PoW-Shield","owner":"RuiSiang","description":"Project dedicated to fight Layer 7 DDoS with proof of work, with an additional WAF and controller. Completed with full set of features and containerized for rapid and lightweight deployment.","archived":false,"fork":false,"pushed_at":"2025-05-14T19:30:26.000Z","size":1889,"stargazers_count":361,"open_issues_count":31,"forks_count":67,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-05-16T04:06:04.374Z","etag":null,"topics":["cybersecurity","ddos","ddos-mitigation","ddos-protection","koa2","netsec","network-security","nodejs","proof-of-work","proxy-server","security","spam-filtering","spam-protection","typescript","waf"],"latest_commit_sha":null,"homepage":"https://shield.rs.me","language":"TypeScript","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/RuiSiang.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-03-08T09:12:20.000Z","updated_at":"2025-05-14T16:55:07.000Z","dependencies_parsed_at":"2023-02-16T14:16:14.320Z","dependency_job_id":"ad761c11-405e-462d-99f2-fe8cd35aec36","html_url":"https://github.com/RuiSiang/PoW-Shield","commit_stats":{"total_commits":619,"total_committers":9,"mean_commits":68.77777777777777,"dds":0.5476575121163166,"last_synced_commit":"42c00e1fca9ebf0b6541f784e8fd967850d1f12c"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RuiSiang%2FPoW-Shield","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RuiSiang%2FPoW-Shield/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RuiSiang%2FPoW-Shield/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RuiSiang%2FPoW-Shield/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RuiSiang","download_url":"https://codeload.github.com/RuiSiang/PoW-Shield/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254464895,"owners_count":22075570,"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":["cybersecurity","ddos","ddos-mitigation","ddos-protection","koa2","netsec","network-security","nodejs","proof-of-work","proxy-server","security","spam-filtering","spam-protection","typescript","waf"],"created_at":"2024-09-24T14:18:32.409Z","updated_at":"2025-05-16T04:06:08.264Z","avatar_url":"https://github.com/RuiSiang.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg height=auto width=100% src=\"https://raw.githubusercontent.com/RuiSiang/PoW-Shield/main/screenshot.jpg\" alt=\"PoW Shield\"\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/RuiSiang/PoW-Shield/actions/workflows/nodejs-ci.yml/badge.svg\"\u003e\n  \u003cimg src=\"https://github.com/RuiSiang/PoW-Shield/actions/workflows/njsscan-analysis.yml/badge.svg\"\u003e\n  \u003cimg src=\"https://github.com/RuiSiang/PoW-Shield/actions/workflows/codeql-analysis.yml/badge.svg\"\u003e\n  \u003ca href=\"https://hub.docker.com/r/ruisiang/pow-shield\"\u003e\n    \u003cimg src=\"https://img.shields.io/docker/image-size/ruisiang/pow-shield/latest?label=docker%20image%20size\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/github/repo-size/ruisiang/pow-shield?color=orange\"\u003e\n  \u003ca href=\"https://deepsource.io/gh/RuiSiang/PoW-Shield/?ref=repository-badge\"\u003e\n    \u003cimg src=\"https://deepsource.io/gh/RuiSiang/PoW-Shield.svg/?label=active+issues\u0026show_trend=true\u0026token=yoFuBlRVaXTzIVkgAB6aSUf3\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://deepsource.io/gh/RuiSiang/PoW-Shield/?ref=repository-badge\"\u003e\n    \u003cimg src=\"https://deepsource.io/gh/RuiSiang/PoW-Shield.svg/?label=resolved+issues\u0026show_trend=true\u0026token=yoFuBlRVaXTzIVkgAB6aSUf3\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n## Description\n\nPoW Shield provides DDoS protection on OSI application layer by acting as a proxy that utilizes proof of work between the backend service and the end user. This project aims to provide an alternative to general anti-DDoS methods such as Google's ReCaptcha that has always been a pain to solve. Accessing a web service protected by PoW Shield has never been easier, simply go to the url, and your browser will do the rest of the verification automatically for you.\n\nPoW Shield aims to provide the following services bundled in a single webapp / docker image:\n\n- proof of work authentication\n- ratelimiting and ip blacklisting\n- web application firewall\n\n(New) [Article on LinkedIn](https://www.linkedin.com/feed/update/urn:li:ugcPost:6994133790017163264?updateEntityUrn=urn%3Ali%3Afs_updateV2%3A%28urn%3Ali%3AugcPost%3A6994133790017163264%2CFEED_DETAIL%2CEMPTY%2CDEFAULT%2Cfalse%29)\n\n[Featured on Pentester Academy TV](https://youtu.be/zeNKUDR7_Jc 'The Tool Box | PoW Shield')\n\n[Story on Medium](https://ruisiang.medium.com/pow-shield-application-layer-proof-of-work-ddos-filter-4fed32465509 'PoW Shield: Application Layer Proof of Work DDoS Filter')\n\n## Features\n\n- Web Service Structure\n- Proxy Functionality\n- PoW Implementation\n- Dockerization\n- IP Blacklisting\n- Ratelimiting\n- Unit Testing\n- WAF Implementation\n- Multi-Instance Syncing (Redis)\n- SSL Support\n\nSupported via [PoW Phalanx](https://github.com/ruisiang/PoW-Phalanx) controller:\n- Multi-instance Management\n- Whitelist tokens\n- Blacklist IP syncing\n- Dynamic difficulty control\n- Dashboard\n\nAlternate implementation in Go [PoW-Shield-Go](https://github.com/RuiSiang/Pow-Shield-Go) (WIP) for stress testing purposes and future optimized production version.\n\n## How it Works\n\nSo basically, PoW Shield works as a proxy in front of the actual web app/service. It conducts verification via proof-of-work and only proxies authorized traffic through to the actual server. The proxy is easily installable, and is capable of protecting low security applications with a WAF.\n\nHere’s what happens behind the scenes when a user browses a PoW Shield-protected webservice:\n\n1. The server generates a random hex-encoded “prefix” and sends it along with the PoW Shield page to the client.\n2. Browser JavaScript on the client side then attempts to brute-force a “nonce” that when appended with the prefix, can produce a SHA256 hash with the number of leading zero-bits more than the “difficulty” D specified by the server. i.e. SHA256(prefix + nonce)=0…0xxxx (binary, with more than D leading 0s)\n3. Client-side JavaScript then sends the calculated nonce to the server for verification, if verification passes, the server generates a cookie for the client to pass authentication.\n4. The server starts proxying the now authenticated client traffic to the server with WAF filtering enabled.\n\n## Configuration\n\nYou can configure PoW Shield via the following methods.\n\n- nodejs: .env (example: .env.example)\n- docker-compose: docker-compose.yaml (example: docker-compose.example.yaml)\n- docker run: -e parameter\n\n### Environmental Variables\n\n| Variable                     | Type       | Default                 | Description                                                                                                                                                       |\n| ---------------------------- | ---------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| PORT                         | General    | 3000                    | port that PoW Shield listens to                                                                                                                                   |\n| SESSION_KEY                  | General    |                         | secret key for cookie signatures, use a unique one for security reasons, or anyone can forge your signed cookies                                                  |\n| BACKEND_URL                  | General    |                         | location to proxy authenticated traffic to, IP and URLs are both accepted(accepts protocol://url(:port) or protocol://ip(:port))                                  |\n| DATABASE_HOST                | Redis      | 127.0.0.1               | redis service host                                                                                                                                                |\n| DATABASE_PORT                | Redis      | 6379                    | redis service port                                                                                                                                                |\n| DATABASE_PASSWORD            | Redis      | null                    | redis service password                                                                                                                                            |\n| POW                          | PoW        | on                      | toggles PoW functionality on/off (if not temporary switched off, why use this project at all?)                                                                    |\n| NONCE_VALIDITY               | PoW        | 60000                   | specifies the maximum seconds a nonce has to be submitted to the server after generation(used to enforce difficulty change and filter out stale nonces)           |\n| DIFFICULTY                   | PoW        | 13                      | problem difficulty, number of leading 0-bits in produced hash (0:extremely easy ~ 256:impossible, 13(default) takes about 5 seconds for the browser to calculate) |\n| RATE_LIMIT                   | Rate Limit | on                      | toggles ratelimit functionality on/off                                                                                                                            |\n| RATE_LIMIT_SAMPLE_MINUTES    | Rate Limit | 60                      | specifies how many minutes until statistics reset for session/ip                                                                                                  |\n| RATE_LIMIT_SESSION_THRESHOLD | Rate Limit | 100                     | number of requests that a single session can make until triggering token revocation                                                                               |\n| RATE_LIMIT_BAN_IP            | Rate Limit | on                      | toggles ip banning functionality on/off                                                                                                                           |\n| RATE_LIMIT_IP_THRESHOLD      | Rate Limit | 500                     | number of requests that a single session can make until triggering IP ban                                                                                         |\n| RATE_LIMIT_BAN_MINUTES       | Rate Limit | 15                      | number of minutes that IP ban persists                                                                                                                            |\n| WAF                          | WAF        | on                      | toggles waf functionality on/off                                                                                                                                  |\n| WAF_URL_EXCLUDE_RULES        | WAF        |                         | exclude rules to check when scanning request url, use ',' to seperate rule numbers, use '-' to specify a range (eg: 1,2-4,5,7-10)                                 |\n| WAF_HEADER_EXCLUDE_RULES     | WAF        | 14,33,80,96,100         | exclude rules to check when scanning request header, use ',' to seperate rule numbers, use '-' to specify a range (eg: 1,2-4,5,7-10)                              |\n| WAF_BODY_EXCLUDE_RULES       | WAF        |                         | exclude rules to check when scanning request body, use ',' to seperate rule numbers, use '-' to specify a range (eg: 1,2-4,5,7-10)                                |\n| SSL                          | SSL        | off                     | toggles SSL functionality on/off                                                                                                                                  |\n| SSL_CERT_PATH                | SSL        | tests/ssl/mock-cert.pem | path to SSL certificate password                                                                                                                                  |\n| SSL_KEY_PATH                 | SSL        | tests/ssl/mock-key.pem  | path to SSL key                                                                                                                                                   |\n| SOCKET                       | Socket     | off                     | toggles socket functionality on/off                                                                                                                               |\n| SOCKET_URL                   | Socket     |                         | location of PoW Phalanx controller, IP and URLs are both accepted(accepts protocol://url:port or protocol://ip:port)                                              |\n| SOCKET_TOKEN                 | Socket     |                         | subscription token for PoW Phalanx controller                                                                                                                     |\n\n## Usage\n\n### Nodejs\n\n#### Prerequisites\n\n- Docker ^19.0.0\n- Nodejs ^14.0.0\n\n```bash\n# Clone repository\ngit clone https://github.com/RuiSiang/PoW-Shield.git\n\n# Install dependencies\nnpm install\n\n# Configure settings\ncp -n .env.example .env\n# Edit .env\nnano .env\n\n# Transpile\nnpm run build\n\n#############################################\n# Run with db (redis), recommended \u0026 faster #\n# install redis first                       #\n# sudo apt-get install redis-server         #\n#############################################\nnpm start\n#############################################\n\n#############################################\n#        Run without db (mock redis)        #\n#############################################\nnpm run start:standalone # linux\nnpm run start:standalone-win # windows\n#############################################\n\n# Test functionalities(optional)\nnpm test\n\n```\n\n### Docker ([repo](https://hub.docker.com/repository/docker/ruisiang/pow-shield))\n\n```bash\n####################################################\n# Docker run with db (redis), recommended \u0026 faster #\n####################################################\ndocker run -p 3000:3000 -e BACKEND_URL=\"http://example.com\" -d ruisiang/pow-shield\n####################################################\n\n####################################################\n#        Docker run without db (mock redis)        #\n####################################################\ndocker run -p 3000:3000 -e BACKEND_URL=\"http://example.com\" -e NODE_ENV=\"standalone\" -d ruisiang/pow-shield\n####################################################\n\n####################################################\n#                  Docker Compose                  #\n####################################################\n# Copy docker-compose.example.yaml\ncp -n docker-compose.example.yaml docker-compose.yaml\n# Edit docker-compose.yaml\nnano docker-compose.yaml\n\n# Start the container\ndocker-compose -f docker-compose.yaml up\n####################################################\n```\n\n## Stress Test\n\nNote: This only works on non-containerized version of PoW Shield, and that your system might experience unstability when running the test.\n\n```bash\n# Start the stress test\nnpm run stress\n\n# If you changed the PORT variable in .env, you should also change the target variable in the stress test script\nnano scripts/stress.sh\n```\n\n_The following tests are are conducted on a single thread of a i7-10870H CPU with a 60 second period for each concurrent parameter._\n\n### Mass GET\n\n| Concurrent Connections | Avg Latency | Error Rate | Requests/Second |\n| ---------------------: | ----------: | ---------: | --------------: |\n|                     64 |      15.3ms |     0.0000 |            4188 |\n|                    128 |      30.2ms |     0.0000 |            4229 |\n|                    256 |      60.4ms |     0.0000 |            4235 |\n|                    512 |     122.6ms |     0.0142 |            4166 |\n|                   1024 |     261.7ms |     0.1766 |            3894 |\n|                   2048 |    1966.5ms |     0.4979 |            1027 |\n|                   4096 |      4685ms |     0.7179 |             838 |\n\n### Nonce Flood\n\n| Concurrent Connections | Avg Latency | Error Rate | Requests/Second |\n| ---------------------: | ----------: | ---------: | --------------: |\n|                     64 |      15.6ms |        N/A |            4094 |\n|                    128 |      31.5ms |        N/A |            4058 |\n|                    256 |      61.5ms |        N/A |            4159 |\n|                    512 |     129.5ms |        N/A |            3945 |\n|                   1024 |     264.4ms |        N/A |            3858 |\n|                   2048 |     592.1ms |        N/A |            3407 |\n|                   4096 |    1212.6ms |        N/A |            3322 |\n\nFrom the above sample, we can see that the appropriate max load estimate for PoW Shield is around 512 concurrent connections. Error rates and latencies deteriorate beyond normal acceptance afterwards. Hence in a load-balanced environment on the machine (1 PoW Shield instance on each of it's 8 cores), it should be able to handle a maximum of approximately 4096 concurrent connections (clients) at a total request rate of 32k requests/second.\n\n## References\n\n- Proof-of-work by Fedor Indutny (PoW utility functions)\n- Shadowd by Zesecure (WAF rules)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruisiang%2Fpow-shield","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fruisiang%2Fpow-shield","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fruisiang%2Fpow-shield/lists"}