@marvalt/madapter 2.1.0 → 2.1.1
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/dist/index.cjs +60 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +47 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +61 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/react/components/TurnstileWidget.d.ts +47 -0
- package/dist/react/components/TurnstileWidget.d.ts.map +1 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/mautic-proxy.d.ts.map +1 -1
- package/dist/server/turnstile.d.ts +24 -0
- package/dist/server/turnstile.d.ts.map +1 -0
- package/dist/server.cjs +137 -0
- package/dist/server.cjs.map +1 -1
- package/dist/server.esm.js +137 -1
- package/dist/server.esm.js.map +1 -1
- package/package.json +1 -1
- package/scripts/postinstall.cjs +13 -0
- package/templates/MAUTIC_SECURITY.md +308 -0
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
# Mautic Integration Security Hardening Guide
|
|
2
|
+
|
|
3
|
+
**Auto-generated by @marvalt/madapter**
|
|
4
|
+
|
|
5
|
+
This guide helps you secure your Mautic integration using Cloudflare's security features and best practices.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🔒 Security Checklist
|
|
10
|
+
|
|
11
|
+
### ✅ Phase 1: Essential (Before Production)
|
|
12
|
+
|
|
13
|
+
Complete these steps before deploying to production:
|
|
14
|
+
|
|
15
|
+
- [ ] **1. Enable Turnstile (Bot Protection)**
|
|
16
|
+
- Sign up: https://dash.cloudflare.com/?to=/:account/turnstile
|
|
17
|
+
- Get your site key and secret key
|
|
18
|
+
- Add to `.env`:
|
|
19
|
+
```bash
|
|
20
|
+
VITE_TURNSTILE_SITE_KEY=your_site_key_here
|
|
21
|
+
```
|
|
22
|
+
- Add to `.env.local`:
|
|
23
|
+
```bash
|
|
24
|
+
VITE_TURNSTILE_SECRET_KEY=your_secret_key_here
|
|
25
|
+
```
|
|
26
|
+
- Turnstile will automatically protect all Mautic form submissions
|
|
27
|
+
|
|
28
|
+
- [ ] **2. Configure Allowed Origins**
|
|
29
|
+
- Add to `.env`:
|
|
30
|
+
```bash
|
|
31
|
+
VITE_ALLOWED_ORIGINS=https://your-app.pages.dev,https://your-custom-domain.com
|
|
32
|
+
```
|
|
33
|
+
- This prevents unauthorized websites from using your API endpoint
|
|
34
|
+
- Use comma-separated list for multiple domains
|
|
35
|
+
|
|
36
|
+
- [ ] **3. Enable Cloudflare Bot Fight Mode**
|
|
37
|
+
- Go to: Cloudflare Dashboard → Your Site → Security → Bots
|
|
38
|
+
- Toggle "Bot Fight Mode" to ON (Free tier)
|
|
39
|
+
- Automatically blocks known bad bots
|
|
40
|
+
|
|
41
|
+
- [ ] **4. Configure Mautic Trusted Domains**
|
|
42
|
+
- Go to: Mautic → Settings → Configuration → System Settings
|
|
43
|
+
- Find "Trusted Domains" section
|
|
44
|
+
- Add your domains (one per line):
|
|
45
|
+
```
|
|
46
|
+
your-app.pages.dev
|
|
47
|
+
your-custom-domain.com
|
|
48
|
+
localhost:8080
|
|
49
|
+
```
|
|
50
|
+
- Save configuration
|
|
51
|
+
|
|
52
|
+
- [ ] **5. Set Up Cloudflare Access for Mautic**
|
|
53
|
+
- Protect your Mautic instance behind Cloudflare Access
|
|
54
|
+
- Dashboard: https://dash.cloudflare.com/?to=/:account/access
|
|
55
|
+
- Create a Service Token for your application
|
|
56
|
+
- Add credentials to `.env.local`:
|
|
57
|
+
```bash
|
|
58
|
+
VITE_CF_ACCESS_CLIENT_ID=your_client_id
|
|
59
|
+
VITE_CF_ACCESS_CLIENT_SECRET=your_client_secret
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
### 🔥 Phase 2: Enhanced (After Launch)
|
|
65
|
+
|
|
66
|
+
Implement these after your initial deployment:
|
|
67
|
+
|
|
68
|
+
- [ ] **6. Add WAF Rate Limiting Rules**
|
|
69
|
+
- Go to: Cloudflare Dashboard → Security → WAF → Rate limiting rules
|
|
70
|
+
- Create new rule:
|
|
71
|
+
- **Rule name**: "Mautic Form Submission Limit"
|
|
72
|
+
- **If incoming requests match**:
|
|
73
|
+
- URI Path equals `/api/mautic-submit`
|
|
74
|
+
- Method equals `POST`
|
|
75
|
+
- **Then**: Rate limit
|
|
76
|
+
- **Requests**: 10 requests per 1 minute
|
|
77
|
+
- **Action**: Block
|
|
78
|
+
- Save and deploy
|
|
79
|
+
|
|
80
|
+
- [ ] **7. Enable Super Bot Fight Mode** (Requires Pro plan - $20/mo)
|
|
81
|
+
- Go to: Security → Bots
|
|
82
|
+
- Upgrade to Pro plan
|
|
83
|
+
- Enable "Super Bot Fight Mode"
|
|
84
|
+
- Advanced bot detection with machine learning
|
|
85
|
+
|
|
86
|
+
- [ ] **8. Set Up Monitoring and Alerts**
|
|
87
|
+
- Go to: Analytics → Security
|
|
88
|
+
- Monitor blocked requests and bot traffic
|
|
89
|
+
- Set up email notifications:
|
|
90
|
+
- Notifications → Add
|
|
91
|
+
- Select "Security Events"
|
|
92
|
+
- Configure threshold (e.g., >100 blocked requests/hour)
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
### 💎 Phase 3: Advanced (Production Scale)
|
|
97
|
+
|
|
98
|
+
For high-traffic or high-value applications:
|
|
99
|
+
|
|
100
|
+
- [ ] **9. Custom WAF Rules**
|
|
101
|
+
- **Block specific countries** (if needed):
|
|
102
|
+
```
|
|
103
|
+
(ip.geoip.country in {"CN" "RU"}) and
|
|
104
|
+
(http.request.uri.path contains "/api/mautic-submit")
|
|
105
|
+
→ Block
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- **Challenge suspicious user agents**:
|
|
109
|
+
```
|
|
110
|
+
(http.user_agent contains "curl" or
|
|
111
|
+
http.user_agent contains "python" or
|
|
112
|
+
http.user_agent contains "bot") and
|
|
113
|
+
(http.request.uri.path eq "/api/mautic-submit")
|
|
114
|
+
→ Managed Challenge
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
- [ ] **10. Implement Per-Form Rate Limiting**
|
|
118
|
+
- Use Cloudflare Workers KV for custom rate limiting
|
|
119
|
+
- Track submissions per IP per form ID
|
|
120
|
+
- Prevent targeted abuse of specific forms
|
|
121
|
+
|
|
122
|
+
- [ ] **11. Enable Cloudflare Logs** (Business plan+)
|
|
123
|
+
- Full request logging for forensics
|
|
124
|
+
- Integrate with SIEM tools
|
|
125
|
+
- Long-term security analytics
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 📋 Environment Variables Reference
|
|
130
|
+
|
|
131
|
+
### Required Variables
|
|
132
|
+
|
|
133
|
+
**In `.env` (non-sensitive):**
|
|
134
|
+
```bash
|
|
135
|
+
# Mautic instance URL
|
|
136
|
+
VITE_MAUTIC_URL=https://your-mautic-instance.com
|
|
137
|
+
|
|
138
|
+
# Allowed origins (comma-separated)
|
|
139
|
+
VITE_ALLOWED_ORIGINS=https://your-app.pages.dev,https://your-domain.com
|
|
140
|
+
|
|
141
|
+
# Turnstile site key (public)
|
|
142
|
+
VITE_TURNSTILE_SITE_KEY=0x4AAA...
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
**In `.env.local` (secrets - never commit!):**
|
|
146
|
+
```bash
|
|
147
|
+
# Mautic OAuth2 credentials
|
|
148
|
+
VITE_MAUTIC_API_PUBLIC_KEY=your_oauth_client_id
|
|
149
|
+
VITE_MAUTIC_API_SECRET_KEY=your_oauth_client_secret
|
|
150
|
+
|
|
151
|
+
# Turnstile secret key
|
|
152
|
+
VITE_TURNSTILE_SECRET_KEY=0x4BBB...
|
|
153
|
+
|
|
154
|
+
# Cloudflare Access (optional)
|
|
155
|
+
VITE_CF_ACCESS_CLIENT_ID=your_access_client_id
|
|
156
|
+
VITE_CF_ACCESS_CLIENT_SECRET=your_access_client_secret
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## 🔧 Testing Your Security
|
|
162
|
+
|
|
163
|
+
### 1. Test Turnstile Protection
|
|
164
|
+
```bash
|
|
165
|
+
# Should work (with valid Turnstile token)
|
|
166
|
+
curl -X POST https://your-app.pages.dev/api/mautic-submit?endpoint=/form/submit \
|
|
167
|
+
-H "Origin: https://your-app.pages.dev" \
|
|
168
|
+
-H "cf-turnstile-response: valid_token_here"
|
|
169
|
+
|
|
170
|
+
# Should fail (missing Turnstile token)
|
|
171
|
+
curl -X POST https://your-app.pages.dev/api/mautic-submit?endpoint=/form/submit \
|
|
172
|
+
-H "Origin: https://your-app.pages.dev"
|
|
173
|
+
# Expected: 403 Forbidden
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 2. Test Origin Validation
|
|
177
|
+
```bash
|
|
178
|
+
# Should fail (unauthorized origin)
|
|
179
|
+
curl -X POST https://your-app.pages.dev/api/mautic-submit?endpoint=/form/submit \
|
|
180
|
+
-H "Origin: https://malicious-site.com"
|
|
181
|
+
# Expected: 403 Forbidden
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 3. Test Endpoint Whitelisting
|
|
185
|
+
```bash
|
|
186
|
+
# Should fail (unauthorized endpoint)
|
|
187
|
+
curl https://your-app.pages.dev/api/mautic-submit?endpoint=/api/contacts \
|
|
188
|
+
-H "Origin: https://your-app.pages.dev"
|
|
189
|
+
# Expected: 403 Forbidden
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### 4. Test Rate Limiting
|
|
193
|
+
Submit a form 15 times rapidly - should be blocked after 10 submissions.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## 📊 Security Monitoring
|
|
198
|
+
|
|
199
|
+
### Regular Checks
|
|
200
|
+
|
|
201
|
+
**Daily:**
|
|
202
|
+
- Check Cloudflare Analytics → Security Events
|
|
203
|
+
- Review blocked requests and patterns
|
|
204
|
+
|
|
205
|
+
**Weekly:**
|
|
206
|
+
- Review Mautic form submissions for spam
|
|
207
|
+
- Check for unusual traffic patterns
|
|
208
|
+
- Verify Turnstile is working (check solve rate)
|
|
209
|
+
|
|
210
|
+
**Monthly:**
|
|
211
|
+
- Review and update allowed origins
|
|
212
|
+
- Audit Cloudflare Access logs
|
|
213
|
+
- Update WAF rules based on threats
|
|
214
|
+
|
|
215
|
+
### Key Metrics
|
|
216
|
+
|
|
217
|
+
- **Bot Score**: Should be mostly 1-30 (humans)
|
|
218
|
+
- **Blocked Requests**: <5% of total traffic
|
|
219
|
+
- **Turnstile Solve Rate**: >95%
|
|
220
|
+
- **False Positives**: <1%
|
|
221
|
+
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## 🆘 Troubleshooting
|
|
225
|
+
|
|
226
|
+
### "Verification failed" Error
|
|
227
|
+
|
|
228
|
+
**Symptoms:** Form submission fails with "Bot verification failed"
|
|
229
|
+
|
|
230
|
+
**Solutions:**
|
|
231
|
+
1. Check Turnstile secret key in `.env.local`
|
|
232
|
+
2. Verify site key matches in Cloudflare dashboard
|
|
233
|
+
3. Check browser console for Turnstile errors
|
|
234
|
+
4. Ensure Turnstile script loads (check network tab)
|
|
235
|
+
|
|
236
|
+
### "Forbidden origin" Error
|
|
237
|
+
|
|
238
|
+
**Symptoms:** Form submission fails with "Forbidden origin"
|
|
239
|
+
|
|
240
|
+
**Solutions:**
|
|
241
|
+
1. Add your domain to `VITE_ALLOWED_ORIGINS` in `.env`
|
|
242
|
+
2. Check for typos (`https://` vs `http://`)
|
|
243
|
+
3. Verify domain matches exactly (including subdomain)
|
|
244
|
+
4. Restart dev server after changing `.env`
|
|
245
|
+
|
|
246
|
+
### "Forbidden endpoint" Error
|
|
247
|
+
|
|
248
|
+
**Symptoms:** API calls fail with "Forbidden endpoint"
|
|
249
|
+
|
|
250
|
+
**Solutions:**
|
|
251
|
+
1. Only `/form/submit` endpoints are allowed
|
|
252
|
+
2. Check endpoint format in request
|
|
253
|
+
3. Verify you're not trying to access other Mautic APIs
|
|
254
|
+
|
|
255
|
+
### Forms Not Submitting
|
|
256
|
+
|
|
257
|
+
**Symptoms:** Form submission hangs or fails silently
|
|
258
|
+
|
|
259
|
+
**Solutions:**
|
|
260
|
+
1. Check browser console for errors
|
|
261
|
+
2. Verify Mautic OAuth credentials in `.env.local`
|
|
262
|
+
3. Check Cloudflare Access service token
|
|
263
|
+
4. Verify Mautic instance is accessible
|
|
264
|
+
5. Check Cloudflare Pages Function logs
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## 📚 Additional Resources
|
|
269
|
+
|
|
270
|
+
- **Cloudflare Turnstile**: https://developers.cloudflare.com/turnstile/
|
|
271
|
+
- **Cloudflare Access**: https://developers.cloudflare.com/cloudflare-one/identity/service-tokens/
|
|
272
|
+
- **Cloudflare WAF**: https://developers.cloudflare.com/waf/
|
|
273
|
+
- **Mautic API**: https://developer.mautic.org/
|
|
274
|
+
- **@marvalt/madapter**: https://github.com/MarVAlt/madapter
|
|
275
|
+
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## 🎯 Security Level Assessment
|
|
279
|
+
|
|
280
|
+
After completing each phase:
|
|
281
|
+
|
|
282
|
+
| Phase | Protection Level | Suitable For |
|
|
283
|
+
|-------|-----------------|--------------|
|
|
284
|
+
| **Phase 1** | 85-90% | MVP, Small apps |
|
|
285
|
+
| **Phase 2** | 95-98% | Production apps |
|
|
286
|
+
| **Phase 3** | 99%+ | Enterprise, High-value |
|
|
287
|
+
|
|
288
|
+
---
|
|
289
|
+
|
|
290
|
+
## ✅ Quick Start Checklist
|
|
291
|
+
|
|
292
|
+
For immediate deployment, complete these minimum steps:
|
|
293
|
+
|
|
294
|
+
1. ✅ Add `VITE_ALLOWED_ORIGINS` to `.env`
|
|
295
|
+
2. ✅ Enable Cloudflare Bot Fight Mode
|
|
296
|
+
3. ✅ Configure Mautic Trusted Domains
|
|
297
|
+
4. ✅ Set up Turnstile (get keys, add to env)
|
|
298
|
+
5. ✅ Test form submission
|
|
299
|
+
|
|
300
|
+
**Time required:** ~15 minutes
|
|
301
|
+
**Security level achieved:** Good (85-90%)
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
**Need help?** Check the troubleshooting section or open an issue on GitHub.
|
|
306
|
+
|
|
307
|
+
**Last updated:** Auto-generated on package installation
|
|
308
|
+
|