@webdecoy/node 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -2
- package/dist/index.d.mts +789 -1
- package/dist/index.d.ts +789 -1
- package/dist/index.js +2071 -2
- package/dist/index.mjs +2049 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Core Web Decoy SDK for Node.js applications - Advanced bot detection with TLS fingerprinting.
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/@webdecoy/node)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
7
|
|
|
8
8
|
## Installation
|
|
@@ -127,6 +127,90 @@ import type {
|
|
|
127
127
|
} from '@webdecoy/node';
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
+
## Self-Hosted Captcha & Detection Engine
|
|
131
|
+
|
|
132
|
+
In addition to the API-backed `protect()` flow above, the SDK ships a fully
|
|
133
|
+
**in-process** bot-detection engine and captcha — no remote call required. It
|
|
134
|
+
scores ~40 behavioral, environmental, and fingerprint signals collected by the
|
|
135
|
+
[`@webdecoy/client`](https://www.npmjs.com/package/@webdecoy/client) browser
|
|
136
|
+
widget, verifies a SHA-256 proof-of-work, and issues a signed session token.
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
Browser (@webdecoy/client) Your server (@webdecoy/node)
|
|
140
|
+
collect signals + solve PoW ──▶ Captcha.verify()
|
|
141
|
+
├─ verify proof-of-work
|
|
142
|
+
├─ score signals (in-process engine)
|
|
143
|
+
└─ issue session token on success
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Mounting the endpoints
|
|
147
|
+
|
|
148
|
+
Use your framework adapter (or `createCaptchaEndpoints` directly). The handler
|
|
149
|
+
serves `GET /__webdecoy/challenge`, `POST /__webdecoy/verify`, `POST
|
|
150
|
+
/__webdecoy/score`, and `POST /__webdecoy/token/verify`.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
import express from 'express';
|
|
154
|
+
import { webdecoyCaptcha } from '@webdecoy/express';
|
|
155
|
+
|
|
156
|
+
const app = express();
|
|
157
|
+
app.use(express.json());
|
|
158
|
+
|
|
159
|
+
app.use(
|
|
160
|
+
webdecoyCaptcha({
|
|
161
|
+
secret: process.env.WEBDECOY_SECRET, // required in production
|
|
162
|
+
}),
|
|
163
|
+
);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
Then verify the token your form receives on a protected route:
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import { Captcha } from '@webdecoy/node';
|
|
170
|
+
|
|
171
|
+
const captcha = new Captcha({ secret: process.env.WEBDECOY_SECRET });
|
|
172
|
+
|
|
173
|
+
app.post('/login', (req, res) => {
|
|
174
|
+
const result = captcha.verifyToken(req.body.webdecoy_token, req.ip);
|
|
175
|
+
if (!result.valid) return res.status(403).json({ error: 'captcha failed' });
|
|
176
|
+
// ...proceed
|
|
177
|
+
});
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Using the engine directly
|
|
181
|
+
|
|
182
|
+
For full control, score raw signals yourself:
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { DetectionEngine } from '@webdecoy/node';
|
|
186
|
+
|
|
187
|
+
const engine = new DetectionEngine({ requirePoW: false });
|
|
188
|
+
const verdict = engine.score(signals, {
|
|
189
|
+
ip,
|
|
190
|
+
siteKey: 'site',
|
|
191
|
+
userAgent,
|
|
192
|
+
headers,
|
|
193
|
+
});
|
|
194
|
+
// verdict: { success, score, recommendation: 'allow'|'challenge'|'block', categoryScores, detections }
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
> **Note on the scoring model:** the verdict is a confidence-weighted blend
|
|
198
|
+
> across categories, so no single signal can cross the block threshold alone —
|
|
199
|
+
> a missing proof-of-work on an otherwise-clean request yields `challenge`, not
|
|
200
|
+
> `block`. Tune category weights via the `weights` option.
|
|
201
|
+
|
|
202
|
+
### Security & deployment notes
|
|
203
|
+
|
|
204
|
+
- **`secret`** signs challenges and tokens. It is **required in production**
|
|
205
|
+
(`NODE_ENV=production`); a missing or default secret throws. Generate one with
|
|
206
|
+
`openssl rand -hex 32`.
|
|
207
|
+
- Challenge/token/fingerprint stores are **in-memory** by default. For
|
|
208
|
+
serverless or multi-instance deployments, supply a shared store via the
|
|
209
|
+
`challengeStore` / `tokenStore` options (the `ChallengeStore` / `TokenStore`
|
|
210
|
+
interfaces are the seam for Redis).
|
|
211
|
+
- IP reputation (VPN/proxy/Tor, abuse score, geo) is still served by
|
|
212
|
+
`api.webdecoy.com` via the SDK's IP-enrichment client.
|
|
213
|
+
|
|
130
214
|
## Framework Integrations
|
|
131
215
|
|
|
132
216
|
For Express.js, use the dedicated middleware package:
|
|
@@ -147,7 +231,7 @@ API keys start with `sk_live_` for production or `sk_test_` for testing.
|
|
|
147
231
|
|
|
148
232
|
## Documentation
|
|
149
233
|
|
|
150
|
-
For full documentation, visit the [GitHub repository](https://github.com/
|
|
234
|
+
For full documentation, visit the [GitHub repository](https://github.com/WebDecoy/node-sdk).
|
|
151
235
|
|
|
152
236
|
## License
|
|
153
237
|
|