Skip to content

Commit 7022f72

Browse files
authored
Pow phalanx connection (#341)
* edit redis prefix and change db service name * add control socket support * fix incorrect socket response * add whitelist functionality and add two stats * update readme * add blacklist sync * add update_model placeholder * update dependencies * fix deepsource issues
1 parent 5ba7da8 commit 7022f72

18 files changed

+825
-1268
lines changed

.env.example

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PORT=3000
22
SESSION_KEY="abcdefghijklmnop"
33
POW=on
44
NONCE_VALIDITY=60000
5-
INITIAL_DIFFICULTY=13
5+
DIFFICULTY=13
66
BACKEND_URL="http://example.com"
77

88
DATABASE_HOST=127.0.0.1
@@ -23,4 +23,8 @@ WAF_BODY_EXCLUDE_RULES=
2323

2424
SSL=off
2525
SSL_CERT_PATH=
26-
SSL_KEY_PATH=
26+
SSL_KEY_PATH=
27+
28+
SOCKET=off
29+
SOCKET_URL=http://hostname:port
30+
SOCKET_TOKEN=pow-phalanx-subscription-token

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ PoW Shield aims to provide the following services bundled in a single webapp / d
4848
- Multi-Instance Syncing (Redis)
4949
- SSL Support
5050

51+
Supported via [PoW Phalanx](https://github.com/ruisiang/PoW-Phalanx) controller:
52+
- Multi-instance Management
53+
- Whitelist tokens
54+
- Blacklist IP syncing
55+
- Dynamic difficulty control
56+
- Dashboard
57+
5158
## How it Works
5259

5360
So 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.
@@ -79,7 +86,7 @@ You can configure PoW Shield via the following methods.
7986
| DATABASE_PASSWORD | Redis | null | redis service password |
8087
| POW | PoW | on | toggles PoW functionality on/off (if not temporary switched off, why use this project at all?) |
8188
| 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) |
82-
| INITIAL_DIFFICULTY | PoW | 13 | initial 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) |
89+
| 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) |
8390
| RATE_LIMIT | Rate Limit | on | toggles ratelimit functionality on/off |
8491
| RATE_LIMIT_SAMPLE_MINUTES | Rate Limit | 60 | specifies how many minutes until statistics reset for session/ip |
8592
| RATE_LIMIT_SESSION_THRESHOLD | Rate Limit | 100 | number of requests that a single session can make until triggering token revocation |
@@ -93,6 +100,9 @@ You can configure PoW Shield via the following methods.
93100
| SSL | SSL | off | toggles SSL functionality on/off |
94101
| SSL_CERT_PATH | SSL | tests/ssl/mock-cert.pem | path to SSL certificate password |
95102
| SSL_KEY_PATH | SSL | tests/ssl/mock-key.pem | path to SSL key |
103+
| SOCKET | Socket | off | toggles socket functionality on/off |
104+
| SOCKET_URL | Socket | | location of PoW Phalanx controller, IP and URLs are both accepted(accepts protocol://url:port or protocol://ip:port) |
105+
| SOCKET_TOKEN | Socket | | subscription token for PoW Phalanx controller |
96106

97107
## Usage
98108

app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import config from './service/util/config-parser'
1111
import powRouter from './routes/pow-router'
1212
import testRouter from './routes/test-router'
1313
import { controller } from './service/controller-service'
14+
import Client from './service/util/socket'
1415

1516
app.keys = [config.session_key]
1617
app.use(
@@ -57,6 +58,9 @@ app.use(
5758
)
5859

5960
// service and routes
61+
if (config.socket) {
62+
Client.getInstance()
63+
}
6064
if (process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'standalone') {
6165
app.use(testRouter.routes())
6266
}

docker-compose.example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ services:
99
- 'SESSION_KEY=abcdefghijklmnop'
1010
- 'POW=on'
1111
- 'NONCE_VALIDITY=60000'
12-
- 'INITIAL_DIFFICULTY=13'
12+
- 'DIFFICULTY=13'
1313
- 'BACKEND_URL=http://webapp:80'
1414
- 'DATABASE_HOST=redis'
1515
- 'DATABASE_PORT=6379'

0 commit comments

Comments
 (0)