api-turnstile 0.1.5 → 0.1.7
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 +119 -45
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
<div align="center">
|
|
4
4
|
<img src="https://sentinel.risksignal.name.ng/sentinel-logo.png" alt="Sentinel Logo" width="120" />
|
|
5
|
-
<h3>
|
|
5
|
+
<h3>Turnstile for API</h3>
|
|
6
6
|
<p>Cloudflare Turnstile protects browsers. <b>Sentinel protects APIs.</b></p>
|
|
7
7
|
<p>
|
|
8
8
|
<a href="https://www.npmjs.com/package/api-turnstile"><img src="https://img.shields.io/npm/v/api-turnstile?color=orange&style=flat-square" alt="NPM Version" /></a>
|
|
@@ -13,32 +13,48 @@
|
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
16
|
-
> **
|
|
16
|
+
> **The first line of defense for modern APIs.**
|
|
17
17
|
> **Block bots, scripts, credential stuffing, and automation attacks — without rate limits or CAPTCHAs.**
|
|
18
|
-
> **API Turnstile is a
|
|
18
|
+
> **API Turnstile is a high-velocity decision engine built specifically to protect API endpoints at the network edge.**
|
|
19
19
|
|
|
20
20
|
## What Is API Turnstile?
|
|
21
21
|
|
|
22
|
-
API Turnstile is
|
|
23
|
-
It blocks automated attacks such as credential stuffing, fake account creation, payment fraud, and API scraping — without CAPTCHAs or browser JavaScript.
|
|
22
|
+
API Turnstile (Sentinel) is a deterministic trust layer for APIs. Unlike traditional WAFs that rely on static IP blocklists or user-hostile CAPTCHAs, Sentinel uses **Infrastructure Forensics** and **Behavioral Work Tokens (BWT)** to differentiate between legitimate users and automated scripts in real-time.
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
It allows you to maintain a frictionless user experience while effectively blocking 99.9% of automated threats, including sophisticated headless browsers and residential proxy rotation.
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
- **🛡️ Adaptive Defenses**: Automatically escalates cryptographic challenges (BWT) for suspicious IPs.
|
|
29
|
-
- **🔌 Multi-Framework**: First-class support for Node.js (Express/Fastify) and Edge Runtimes (Next.js/Bun).
|
|
30
|
-
- **🕹️ CLI Intelligence**: Stream live traffic decisions directly to your terminal with `sentinel tail`.
|
|
31
|
-
- **🎯 Outcome-Based**: Focuses on business results (e.g., bot reduction, capital saved) rather than just "block counts".
|
|
26
|
+
## Architecture
|
|
32
27
|
|
|
33
|
-
|
|
28
|
+
Sentinel operates on a three-tier defense matrix:
|
|
29
|
+
|
|
30
|
+
1. **Fast-Path Matrix (< 20ms)**: Instant vetting against a global ASN/IP reputation matrix (OVH, Hetzner, DigitalOcean, etc.).
|
|
31
|
+
2. **Behavioral Work Tokens (BWT)**: A cryptographic challenge-response system that escalatesPoW difficulty for suspicious IPs.
|
|
32
|
+
3. **Infrastructure Forensics**: Deep analysis of request signatures to detect Puppeteer, Playwright, curl, and VPN/Proxy masking.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Key Features
|
|
37
|
+
|
|
38
|
+
- **Extreme Performance**: Sub-50ms decision latency globally.
|
|
39
|
+
- **Zero Friction**: No CAPTCHAs, no puzzles, no interrupted user flows.
|
|
40
|
+
- **Adaptive Defenses**: Automatically scales security based on the `risk-score` of an incoming request.
|
|
41
|
+
- **Framework Agnostic**: Native middleware for Express, Fastify, Next.js, Hono, and Bun.
|
|
42
|
+
- **CLI Forensics**: Stream live traffic decisions and audit IPs directly from your terminal.
|
|
43
|
+
- **Outcome-Focused**: Designed for Registration Fraud, Account Takeover (ATO), and Scraping Prevention.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
34
48
|
|
|
35
49
|
```bash
|
|
36
50
|
npm install api-turnstile
|
|
37
51
|
```
|
|
38
52
|
|
|
39
|
-
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Basic Integration
|
|
40
56
|
|
|
41
|
-
### Express
|
|
57
|
+
### Express.js
|
|
42
58
|
```javascript
|
|
43
59
|
import { sentinel } from 'api-turnstile';
|
|
44
60
|
import express from 'express';
|
|
@@ -46,16 +62,16 @@ import express from 'express';
|
|
|
46
62
|
const app = express();
|
|
47
63
|
|
|
48
64
|
app.use(sentinel({
|
|
49
|
-
apiKey: '
|
|
50
|
-
protect: ['/api/
|
|
51
|
-
profile: 'api'
|
|
65
|
+
apiKey: 'YOUR_SENTINEL_KEY',
|
|
66
|
+
protect: ['/api/auth/*', '/v1/payments'],
|
|
67
|
+
profile: 'api' // Default profile
|
|
52
68
|
}));
|
|
53
69
|
```
|
|
54
70
|
|
|
55
|
-
### Next.js Edge Middleware
|
|
56
|
-
```
|
|
71
|
+
### Next.js (Edge Middleware)
|
|
72
|
+
```typescript
|
|
57
73
|
// middleware.ts
|
|
58
|
-
import { sentinelEdge } from 'api-turnstile
|
|
74
|
+
import { sentinelEdge } from 'api-turnstile';
|
|
59
75
|
|
|
60
76
|
export default sentinelEdge({
|
|
61
77
|
apiKey: process.env.SENTINEL_KEY,
|
|
@@ -64,56 +80,114 @@ export default sentinelEdge({
|
|
|
64
80
|
'/api/public/*': 'monitor'
|
|
65
81
|
}
|
|
66
82
|
});
|
|
83
|
+
|
|
84
|
+
export const config = {
|
|
85
|
+
matcher: '/api/:path*',
|
|
86
|
+
};
|
|
67
87
|
```
|
|
68
88
|
|
|
69
|
-
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Advanced Configuration
|
|
92
|
+
|
|
93
|
+
The `sentinel` middleware accepts a `SentinelConfig` object for granular control.
|
|
70
94
|
|
|
71
95
|
| Option | Type | Default | Description |
|
|
72
96
|
| :--- | :--- | :--- | :--- |
|
|
73
97
|
| `apiKey` | `string` | **Required** | Your Sentinel API key. |
|
|
74
|
-
| `protect` | `string[] \| Object` | `[]` |
|
|
75
|
-
| `profile` | `string` | `'api'` |
|
|
76
|
-
| `fail` | `'open' \| 'closed'` | `'closed'` |
|
|
98
|
+
| `protect` | `string[] \| Object` | `[]` | List of paths to protect or a map of path patterns to `ProtectionMode`. |
|
|
99
|
+
| `profile` | `string` | `'api'` | Sensitivity profile: `api`, `signup`, `payments`, `crypto`. |
|
|
100
|
+
| `fail` | `'open' \| 'closed'` | `'closed'` | Fail strategy if API is unreachable. `closed` blocks access. |
|
|
101
|
+
| `onBlock` | `Function` | `403 JSON` | Custom block handler: `(req, res, decision) => void`. |
|
|
77
102
|
| `bwt.enabled` | `boolean` | `true` | Enable Behavioral Work Tokens (Adaptive PoW). |
|
|
78
|
-
| `onBlock` | `
|
|
103
|
+
| `webhooks.onBlock`| `string` | `undefined` | URL to POST to when an attack is blocked. |
|
|
79
104
|
|
|
80
|
-
### Protection Modes
|
|
81
|
-
|
|
82
|
-
- **`
|
|
83
|
-
- **`
|
|
105
|
+
### Path Protection Modes
|
|
106
|
+
Control how strictly each path is enforced:
|
|
107
|
+
- **`monitor`**: Passive logging. Never blocks.
|
|
108
|
+
- **`balanced`**: Defensive mode. Blocks high-confidence automated threats.
|
|
109
|
+
- **`strict`**: Zero-tolerance. Blocks any suspicious signal including VPNs and Datacenters.
|
|
84
110
|
|
|
85
|
-
|
|
111
|
+
```javascript
|
|
112
|
+
protect: {
|
|
113
|
+
'/api/public': 'monitor',
|
|
114
|
+
'/api/user/*': 'balanced',
|
|
115
|
+
'/api/sensitive': 'strict'
|
|
116
|
+
}
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
86
120
|
|
|
87
|
-
|
|
121
|
+
## Security Profiles
|
|
122
|
+
|
|
123
|
+
Sentinel profiles tune the engine's heuristics based on the endpoint's value:
|
|
124
|
+
|
|
125
|
+
| Profile | Focus | Use Case |
|
|
126
|
+
| :--- | :--- | :--- |
|
|
127
|
+
| **`api`** | Velocity | Standard API endpoints, data feeds. |
|
|
128
|
+
| **`signup`** | Identity | Registration, Login, Forget Password. |
|
|
129
|
+
| **`payments`** | Integrity | Checkout, Subscription, Payment Method Update. |
|
|
130
|
+
| **`crypto`** | Pure Trust | Wallets, Faucets, On-Chain interactions. |
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Response Formats
|
|
135
|
+
|
|
136
|
+
### Successful Decision (Allowed)
|
|
137
|
+
Requests that pass Sentinel checks proceed seamlessly to your next middleware.
|
|
138
|
+
|
|
139
|
+
### Blocked Decision (Default 403)
|
|
140
|
+
If a request is blocked, Sentinel returns a detailed forensic response:
|
|
141
|
+
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"error": "Access denied",
|
|
145
|
+
"reason": "Headless browser signature detected (Puppeteer/Chrome)",
|
|
146
|
+
"remediation": {
|
|
147
|
+
"widget_required": false,
|
|
148
|
+
"trust_token_eligible": true
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Sentinel CLI
|
|
156
|
+
|
|
157
|
+
The package includes a powerful command-line interface for real-time traffic analysis.
|
|
88
158
|
|
|
89
159
|
```bash
|
|
90
|
-
# Install globally
|
|
160
|
+
# Install CLI globally
|
|
91
161
|
npm install -g api-turnstile
|
|
92
162
|
|
|
93
|
-
# Stream live
|
|
163
|
+
# Stream live traffic forensic decisions
|
|
94
164
|
sentinel tail --key YOUR_API_KEY
|
|
95
165
|
|
|
96
|
-
# Perform an immediate
|
|
166
|
+
# Perform an immediate audit on an IP address
|
|
97
167
|
sentinel check 1.2.3.4
|
|
98
168
|
|
|
99
|
-
# View security
|
|
169
|
+
# View security ROI and outcome metrics
|
|
100
170
|
sentinel stats
|
|
101
171
|
```
|
|
102
172
|
|
|
103
|
-
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Behavioral Work Tokens (BWT)
|
|
104
176
|
|
|
105
|
-
BWT is
|
|
177
|
+
BWT is our proprietary adaptive PoW system. When Sentinel identifies an "Unstable" IP, it scales a cryptographic challenge that must be solved by the client.
|
|
106
178
|
|
|
107
|
-
1. Legitimate
|
|
108
|
-
2. Bot
|
|
109
|
-
|
|
179
|
+
1. **Legitimate Users**: The `api-turnstile` client (or frontend widget) solves the challenge in ~10-40ms in the background.
|
|
180
|
+
2. **Bot Scripts**: Python, Go, and simple NodeJS scripts fail the challenge as they lack the cryptographic engine required to generate a valid `BWT-Nonce`.
|
|
181
|
+
|
|
182
|
+
---
|
|
110
183
|
|
|
111
|
-
##
|
|
184
|
+
## Deployment & Compatibility
|
|
112
185
|
|
|
113
|
-
- **
|
|
114
|
-
- **
|
|
115
|
-
- **
|
|
186
|
+
- **Node.js**: 18.x and above.
|
|
187
|
+
- **Bun**: 1.0.0 and above.
|
|
188
|
+
- **Cloud Runtime**: Vercel Edge, Cloudflare Workers, AWS Lambda.
|
|
189
|
+
- **Database**: Zero external DB dependencies (Decision Engine is managed).
|
|
116
190
|
|
|
117
|
-
##
|
|
191
|
+
## License
|
|
118
192
|
|
|
119
193
|
MIT © [Sentinel Security](https://sentinel.risksignal.name.ng)
|
package/package.json
CHANGED