@anonympins/fingerprint 0.4.2 → 0.4.4
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/CHANGELOG.md +38 -0
- package/README.md +70 -60
- package/package.json +1 -1
- package/src/js/fingerprint.client.js +831 -635
- package/src/js/fingerprint.js +249 -31
- package/src/js/pow.solver.js +531 -497
- package/src/js/problem-manager.js +24 -0
- package/src/js/tests/fingerprint.client.init.test.js +140 -119
- package/src/js/tests/fingerprint.test.js +2451 -2319
- package/src/js/tests/pow.solver.test.js +233 -197
- package/src/js/tests/problem-manager.test.js +358 -322
- package/src/php/Challenge/ChallengeUtils.php +415 -361
- package/src/php/Config/SecurityProfiles.php +276 -271
- package/src/php/FingerprintClient.php +131 -131
- package/src/php/FingerprintEngine.php +36 -2
- package/src/php/Optimization/FunctionRegistry.php +63 -62
- package/src/php/Optimization/OptimizationOperators.php +401 -304
- package/src/php/ProblemManager.php +29 -0
- package/src/php/RequestContext.php +90 -90
- package/src/php/Store/IStore.php +41 -41
- package/src/php/Store/RedisStore.php +53 -53
- package/src/php/Tests/FingerprintEngineTest.php +330 -299
- package/src/php/Tests/ProblemManagerTest.php +376 -296
- package/src/php/Tests/RequestUtilsTest.php +386 -253
- package/src/php/Tests/problems.config.json +3 -3
- package/src/php/Utils/RequestUtils.php +201 -17
|
@@ -1,272 +1,277 @@
|
|
|
1
|
-
<?php
|
|
2
|
-
|
|
3
|
-
declare(strict_types=1);
|
|
4
|
-
|
|
5
|
-
namespace Anonympins\Fingerprint\Config;
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Définit les profils de sécurité prédéfinis pour la bibliothèque Fingerprint.
|
|
9
|
-
* Ces profils contiennent les poids des scores de suspicion et les seuils de déclenchement.
|
|
10
|
-
*/
|
|
11
|
-
class SecurityProfiles
|
|
12
|
-
{
|
|
13
|
-
/**
|
|
14
|
-
* @var array<string, array<string, mixed>>
|
|
15
|
-
*/
|
|
16
|
-
public const PROFILES = [
|
|
17
|
-
/**
|
|
18
|
-
* Balanced Profile (Default)
|
|
19
|
-
* A general-purpose configuration suitable for most websites, offering a good mix of security and user experience.
|
|
20
|
-
* It's sensitive enough to catch common bots without being overly aggressive towards legitimate users.
|
|
21
|
-
*/
|
|
22
|
-
'balanced' => [
|
|
23
|
-
'summary' => 'Balanced Profile (Default)',
|
|
24
|
-
'description' => 'A general-purpose configuration suitable for most websites, offering a good mix of security and user experience. It\'s sensitive enough to catch common bots without being overly aggressive towards legitimate users.',
|
|
25
|
-
'weights' => [
|
|
26
|
-
'historyScore' => 0.3,
|
|
27
|
-
'rotationScore' => 0.5,
|
|
28
|
-
'headerAnomalyScore' => 0.1,
|
|
29
|
-
'requestPatternScore' => 0.6,
|
|
30
|
-
'inconsistencyScore' => 0.8,
|
|
31
|
-
'behaviorScore' => 0.7,
|
|
32
|
-
'honeypotScore' => 1.0,
|
|
33
|
-
'crossLayerInconsistencyScore' => 0.4,
|
|
34
|
-
'timeInconsistencyScore' => 0.9,
|
|
35
|
-
'tlsSpoofingScore' => 0.8,
|
|
36
|
-
'botScore' => 1.0, // Poids pour le score de bot explicite
|
|
37
|
-
'cookieDroppingScore' => 0.9, // Pénalité élevée pour la suppression de cookies
|
|
38
|
-
'threatIntelScore' => 0.4, // Poids pour le renseignement sur les menaces (ex: IP de proxy connu)
|
|
39
|
-
'clientHintsInconsistencyScore' => 0.7, // Penalizes inconsistency between User-Agent and Client-Hints
|
|
40
|
-
'clickVarianceScore' => 0.6, // Poids pour la variance des clics
|
|
41
|
-
'subnetScore' => 0.5, // Pénalise les sous-réseaux IP avec une activité suspecte agrégée
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
'
|
|
45
|
-
|
|
46
|
-
'
|
|
47
|
-
'
|
|
48
|
-
'
|
|
49
|
-
'
|
|
50
|
-
'
|
|
51
|
-
'
|
|
52
|
-
'
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
'
|
|
68
|
-
'
|
|
69
|
-
|
|
70
|
-
'
|
|
71
|
-
'
|
|
72
|
-
'
|
|
73
|
-
'
|
|
74
|
-
'
|
|
75
|
-
'
|
|
76
|
-
'
|
|
77
|
-
'
|
|
78
|
-
'
|
|
79
|
-
'
|
|
80
|
-
'
|
|
81
|
-
'
|
|
82
|
-
'
|
|
83
|
-
'
|
|
84
|
-
'
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
'
|
|
91
|
-
'
|
|
92
|
-
'
|
|
93
|
-
'
|
|
94
|
-
'
|
|
95
|
-
'
|
|
96
|
-
'
|
|
97
|
-
'
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
*
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
'
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
'
|
|
115
|
-
'
|
|
116
|
-
'
|
|
117
|
-
'
|
|
118
|
-
'
|
|
119
|
-
'
|
|
120
|
-
'
|
|
121
|
-
'
|
|
122
|
-
'
|
|
123
|
-
'
|
|
124
|
-
'
|
|
125
|
-
'
|
|
126
|
-
'
|
|
127
|
-
'
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
'
|
|
135
|
-
'
|
|
136
|
-
'
|
|
137
|
-
'
|
|
138
|
-
'
|
|
139
|
-
'
|
|
140
|
-
'
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
*
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
'
|
|
161
|
-
'
|
|
162
|
-
'
|
|
163
|
-
'
|
|
164
|
-
'
|
|
165
|
-
'
|
|
166
|
-
'
|
|
167
|
-
'
|
|
168
|
-
'
|
|
169
|
-
'
|
|
170
|
-
'
|
|
171
|
-
'
|
|
172
|
-
'
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
'
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
'
|
|
181
|
-
'
|
|
182
|
-
'
|
|
183
|
-
'
|
|
184
|
-
'
|
|
185
|
-
'
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
'
|
|
205
|
-
'
|
|
206
|
-
'
|
|
207
|
-
|
|
208
|
-
'
|
|
209
|
-
'
|
|
210
|
-
'
|
|
211
|
-
|
|
212
|
-
'
|
|
213
|
-
'
|
|
214
|
-
'
|
|
215
|
-
'
|
|
216
|
-
'
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
'
|
|
221
|
-
'
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
'
|
|
226
|
-
'
|
|
227
|
-
'
|
|
228
|
-
'
|
|
229
|
-
'
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
declare(strict_types=1);
|
|
4
|
+
|
|
5
|
+
namespace Anonympins\Fingerprint\Config;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Définit les profils de sécurité prédéfinis pour la bibliothèque Fingerprint.
|
|
9
|
+
* Ces profils contiennent les poids des scores de suspicion et les seuils de déclenchement.
|
|
10
|
+
*/
|
|
11
|
+
class SecurityProfiles
|
|
12
|
+
{
|
|
13
|
+
/**
|
|
14
|
+
* @var array<string, array<string, mixed>>
|
|
15
|
+
*/
|
|
16
|
+
public const PROFILES = [
|
|
17
|
+
/**
|
|
18
|
+
* Balanced Profile (Default)
|
|
19
|
+
* A general-purpose configuration suitable for most websites, offering a good mix of security and user experience.
|
|
20
|
+
* It's sensitive enough to catch common bots without being overly aggressive towards legitimate users.
|
|
21
|
+
*/
|
|
22
|
+
'balanced' => [
|
|
23
|
+
'summary' => 'Balanced Profile (Default)',
|
|
24
|
+
'description' => 'A general-purpose configuration suitable for most websites, offering a good mix of security and user experience. It\'s sensitive enough to catch common bots without being overly aggressive towards legitimate users.',
|
|
25
|
+
'weights' => [
|
|
26
|
+
'historyScore' => 0.3,
|
|
27
|
+
'rotationScore' => 0.5,
|
|
28
|
+
'headerAnomalyScore' => 0.1,
|
|
29
|
+
'requestPatternScore' => 0.6,
|
|
30
|
+
'inconsistencyScore' => 0.8,
|
|
31
|
+
'behaviorScore' => 0.7,
|
|
32
|
+
'honeypotScore' => 1.0,
|
|
33
|
+
'crossLayerInconsistencyScore' => 0.4,
|
|
34
|
+
'timeInconsistencyScore' => 0.9,
|
|
35
|
+
'tlsSpoofingScore' => 0.8,
|
|
36
|
+
'botScore' => 1.0, // Poids pour le score de bot explicite
|
|
37
|
+
'cookieDroppingScore' => 0.9, // Pénalité élevée pour la suppression de cookies
|
|
38
|
+
'threatIntelScore' => 0.4, // Poids pour le renseignement sur les menaces (ex: IP de proxy connu)
|
|
39
|
+
'clientHintsInconsistencyScore' => 0.7, // Penalizes inconsistency between User-Agent and Client-Hints
|
|
40
|
+
'clickVarianceScore' => 0.6, // Poids pour la variance des clics
|
|
41
|
+
'subnetScore' => 0.5, // Pénalise les sous-réseaux IP avec une activité suspecte agrégée
|
|
42
|
+
'botnetClusterScore' => 0.6, // NOUVEAU: Poids pour le clustering botnet
|
|
43
|
+
],
|
|
44
|
+
'thresholds' => ['low' => 20, 'medium' => 45, 'high' => 75, 'block' => 95],
|
|
45
|
+
'patterns' => [
|
|
46
|
+
'velocityThreshold' => 800,
|
|
47
|
+
'burstThreshold' => 1500,
|
|
48
|
+
'scrapeThreshold' => 1000,
|
|
49
|
+
'historySize' => 10,
|
|
50
|
+
'minSamples' => 5,
|
|
51
|
+
'regularityThreshold' => 50,
|
|
52
|
+
'benfordThreshold' => 0.15,
|
|
53
|
+
'patternWeight' => 80,
|
|
54
|
+
'decayFactor' => 0.9,
|
|
55
|
+
'inactivityReset' => 5000,
|
|
56
|
+
],
|
|
57
|
+
'wasm' => true,
|
|
58
|
+
],
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Strict Profile
|
|
62
|
+
* An aggressive configuration for sensitive applications (e.g., financial services, admin panels).
|
|
63
|
+
* It uses lower suspicion thresholds and higher penalties for anomalies, prioritizing security over user convenience.
|
|
64
|
+
* All new devices are challenged by default.
|
|
65
|
+
*/
|
|
66
|
+
'strict' => [
|
|
67
|
+
'summary' => 'Strict Profile',
|
|
68
|
+
'description' => 'An aggressive configuration for sensitive applications (e.g., financial services, admin panels). It uses lower suspicion thresholds and higher penalties for anomalies, prioritizing security over user convenience. All new devices are challenged by default.',
|
|
69
|
+
'weights' => [
|
|
70
|
+
'historyScore' => 0.4,
|
|
71
|
+
'rotationScore' => 0.6,
|
|
72
|
+
'headerAnomalyScore' => 0.2,
|
|
73
|
+
'requestPatternScore' => 0.8,
|
|
74
|
+
'inconsistencyScore' => 1.0,
|
|
75
|
+
'behaviorScore' => 0.8,
|
|
76
|
+
'honeypotScore' => 1.0,
|
|
77
|
+
'crossLayerInconsistencyScore' => 0.6,
|
|
78
|
+
'timeInconsistencyScore' => 1.0,
|
|
79
|
+
'tlsSpoofingScore' => 1.0,
|
|
80
|
+
'botScore' => 1.0,
|
|
81
|
+
'cookieDroppingScore' => 1.0, // Pénalité maximale
|
|
82
|
+
'threatIntelScore' => 0.7, // Poids élevé pour les menaces connues (Tor, etc.)
|
|
83
|
+
'clientHintsInconsistencyScore' => 0.9, // Very high penalty in strict mode
|
|
84
|
+
'clickVarianceScore' => 0.7, // High weight for click variance
|
|
85
|
+
'subnetScore' => 0.7, // Poids plus élevé en mode strict
|
|
86
|
+
'botnetClusterScore' => 0.8, // NOUVEAU: Poids pour le clustering botnet
|
|
87
|
+
],
|
|
88
|
+
'thresholds' => ['low' => 10, 'medium' => 35, 'high' => 65, 'block' => 90],
|
|
89
|
+
'patterns' => [
|
|
90
|
+
'velocityThreshold' => 1000,
|
|
91
|
+
'burstThreshold' => 1800,
|
|
92
|
+
'scrapeThreshold' => 1200,
|
|
93
|
+
'historySize' => 15,
|
|
94
|
+
'minSamples' => 4,
|
|
95
|
+
'regularityThreshold' => 40,
|
|
96
|
+
'benfordThreshold' => 0.12,
|
|
97
|
+
'patternWeight' => 90,
|
|
98
|
+
'decayFactor' => 0.85,
|
|
99
|
+
'inactivityReset' => 4000,
|
|
100
|
+
],
|
|
101
|
+
'challengeNewDevices' => true, // Challenge all new devices
|
|
102
|
+
'wasm' => true,
|
|
103
|
+
],
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* API Profile
|
|
107
|
+
* Optimized for protecting API endpoints. This profile is highly sensitive to request patterns (velocity, bursts)
|
|
108
|
+
* and less reliant on browser-specific behavioral metrics. It's designed to quickly identify and throttle scrapers and automated clients.
|
|
109
|
+
*/
|
|
110
|
+
'api' => [
|
|
111
|
+
'summary' => 'API Profile',
|
|
112
|
+
'description' => 'Optimized for protecting API endpoints. This profile is highly sensitive to request patterns (velocity, bursts) and less reliant on browser-specific behavioral metrics. It\'s designed to quickly identify and throttle scrapers and automated clients.',
|
|
113
|
+
'weights' => [
|
|
114
|
+
'historyScore' => 0.5,
|
|
115
|
+
'rotationScore' => 0.5,
|
|
116
|
+
'headerAnomalyScore' => 0.3,
|
|
117
|
+
'requestPatternScore' => 1.0, // Very high weight for API patterns
|
|
118
|
+
'inconsistencyScore' => 0.7,
|
|
119
|
+
'behaviorScore' => 0.2, // Lower weight, as browser behavior is not applicable
|
|
120
|
+
'honeypotScore' => 1.0,
|
|
121
|
+
'crossLayerInconsistencyScore' => 0.5,
|
|
122
|
+
'timeInconsistencyScore' => 0.8,
|
|
123
|
+
'tlsSpoofingScore' => 0.7,
|
|
124
|
+
'botScore' => 0.5,
|
|
125
|
+
'cookieDroppingScore' => 0.8, // Important pour les clients API qui doivent maintenir un état
|
|
126
|
+
'threatIntelScore' => 0.5, // APIs are often targeted by malicious IPs
|
|
127
|
+
'clientHintsInconsistencyScore' => 0.6, // Relevant signal for APIs
|
|
128
|
+
'clickVarianceScore' => 0.3, // Low weight as not applicable to APIs
|
|
129
|
+
'subnetScore' => 0.8, // Très important pour les API pour détecter les botnets
|
|
130
|
+
'botnetClusterScore' => 0.7, // NOUVEAU: Poids pour le clustering botnet
|
|
131
|
+
],
|
|
132
|
+
'thresholds' => ['low' => 25, 'medium' => 50, 'high' => 80, 'block' => 95],
|
|
133
|
+
'patterns' => [
|
|
134
|
+
'velocityThreshold' => 200, // APIs are expected to be fast
|
|
135
|
+
'burstThreshold' => 500,
|
|
136
|
+
'scrapeThreshold' => 400,
|
|
137
|
+
'historySize' => 20,
|
|
138
|
+
'minSamples' => 8,
|
|
139
|
+
'regularityThreshold' => 20,
|
|
140
|
+
'benfordThreshold' => 0.18,
|
|
141
|
+
'patternWeight' => 85,
|
|
142
|
+
'decayFactor' => 0.9,
|
|
143
|
+
'inactivityReset' => 10000,
|
|
144
|
+
],
|
|
145
|
+
// This would be a callable in PHP, but for now, we represent its intent.
|
|
146
|
+
'isApiRequest' => 'req.path.startsWith("/api/") || req.headers.accept?.includes("application/json")',
|
|
147
|
+
'wasm' => true,
|
|
148
|
+
],
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Blog Profile
|
|
152
|
+
* Tuned for blogs and content-heavy websites. This profile focuses on detecting content scraping and comment spam
|
|
153
|
+
* by placing a high weight on request patterns and honeypot traps, while being more lenient on behavioral metrics
|
|
154
|
+
* typical of readers.
|
|
155
|
+
*/
|
|
156
|
+
'blog' => [
|
|
157
|
+
'summary' => 'Blog Profile',
|
|
158
|
+
'description' => 'Tuned for blogs and content-heavy websites. This profile focuses on detecting content scraping and comment spam by placing a high weight on request patterns and honeypot traps, while being more lenient on behavioral metrics typical of readers.',
|
|
159
|
+
'weights' => [
|
|
160
|
+
'historyScore' => 0.2,
|
|
161
|
+
'rotationScore' => 0.3,
|
|
162
|
+
'headerAnomalyScore' => 0.1,
|
|
163
|
+
'requestPatternScore' => 0.8, // High weight to detect content scraping
|
|
164
|
+
'inconsistencyScore' => 0.7,
|
|
165
|
+
'behaviorScore' => 0.5, // Less emphasis on complex interactions
|
|
166
|
+
'honeypotScore' => 1.0, // Crucial for comment spam
|
|
167
|
+
'crossLayerInconsistencyScore' => 0.4,
|
|
168
|
+
'timeInconsistencyScore' => 0.8,
|
|
169
|
+
'tlsSpoofingScore' => 0.6,
|
|
170
|
+
'botScore' => 0.8,
|
|
171
|
+
'cookieDroppingScore' => 0.7, // Moins critique, mais toujours un signal
|
|
172
|
+
'threatIntelScore' => 0.3, // Lower priority for a blog
|
|
173
|
+
'clientHintsInconsistencyScore' => 0.5,
|
|
174
|
+
'clickVarianceScore' => 0.5, // Moderate weight for click variance
|
|
175
|
+
'subnetScore' => 0.4, // Utile contre le spam de commentaires coordonné
|
|
176
|
+
'botnetClusterScore' => 0.5, // NOUVEAU: Poids pour le clustering botnet
|
|
177
|
+
],
|
|
178
|
+
'thresholds' => ['low' => 25, 'medium' => 55, 'high' => 80, 'block' => 95],
|
|
179
|
+
'patterns' => [
|
|
180
|
+
'velocityThreshold' => 1000, // Readers can be fast
|
|
181
|
+
'burstThreshold' => 2000,
|
|
182
|
+
'scrapeThreshold' => 800, // Very sensitive to scraping patterns
|
|
183
|
+
'historySize' => 12,
|
|
184
|
+
'minSamples' => 5,
|
|
185
|
+
'regularityThreshold' => 60,
|
|
186
|
+
'benfordThreshold' => 0.16,
|
|
187
|
+
'patternWeight' => 85,
|
|
188
|
+
'decayFactor' => 0.92,
|
|
189
|
+
'inactivityReset' => 10000,
|
|
190
|
+
],
|
|
191
|
+
'wasm' => true,
|
|
192
|
+
],
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* E-commerce Profile
|
|
196
|
+
* A strict profile tailored for e-commerce sites. It's designed to combat inventory scalping,
|
|
197
|
+
* price scraping, and account takeover attempts by using high weights for request patterns and fingerprint inconsistency.
|
|
198
|
+
* It also challenges all new devices to increase the cost for bots.
|
|
199
|
+
*/
|
|
200
|
+
'ecommerce' => [
|
|
201
|
+
'summary' => 'E-commerce Profile',
|
|
202
|
+
'description' => 'A strict profile tailored for e-commerce sites. It\'s designed to combat inventory scalping, price scraping, and account takeover attempts by using high weights for request patterns and fingerprint inconsistency. It also challenges all new devices to increase the cost for bots.',
|
|
203
|
+
'weights' => [
|
|
204
|
+
'historyScore' => 0.4,
|
|
205
|
+
'rotationScore' => 0.6,
|
|
206
|
+
'headerAnomalyScore' => 0.2,
|
|
207
|
+
'inconsistencyScore' => 1.0, // Crucial for preventing account takeover
|
|
208
|
+
'behaviorScore' => 0.8, // Important for checkout/login forms
|
|
209
|
+
'honeypotScore' => 1.0,
|
|
210
|
+
'crossLayerInconsistencyScore' => 0.7,
|
|
211
|
+
// NOUVEAU: Ajout des scores manquants pour une configuration complète
|
|
212
|
+
'requestPatternScore' => 0.9, // Poids unifié pour les patterns, remplace les scores scindés
|
|
213
|
+
'timeInconsistencyScore' => 0.9,
|
|
214
|
+
'tlsSpoofingScore' => 0.9,
|
|
215
|
+
'botScore' => 1.0,
|
|
216
|
+
'cookieDroppingScore' => 1.0, // Crucial pour la détection de bots e-commerce
|
|
217
|
+
'threatIntelScore' => 0.8, // Very important for e-commerce (scalping proxies)
|
|
218
|
+
'clientHintsInconsistencyScore' => 0.9, // Very important for e-commerce
|
|
219
|
+
'clickVarianceScore' => 0.8, // Very high weight for click variance
|
|
220
|
+
'subnetScore' => 0.9, // Crucial contre les attaques de scalping distribuées
|
|
221
|
+
'botnetClusterScore' => 0.9, // NOUVEAU: Poids pour le clustering botnet
|
|
222
|
+
],
|
|
223
|
+
'thresholds' => ['low' => 15, 'medium' => 40, 'high' => 70, 'block' => 90],
|
|
224
|
+
'patterns' => [
|
|
225
|
+
'velocityThreshold' => 500, // Bots are very fast
|
|
226
|
+
'burstThreshold' => 1000, // Detects rapid retries on the same product/action
|
|
227
|
+
'scrapeThreshold' => 600,
|
|
228
|
+
'historySize' => 15,
|
|
229
|
+
'minSamples' => 6,
|
|
230
|
+
'regularityThreshold' => 30,
|
|
231
|
+
'benfordThreshold' => 0.14,
|
|
232
|
+
'patternWeight' => 95,
|
|
233
|
+
'decayFactor' => 0.88,
|
|
234
|
+
'inactivityReset' => 3000,
|
|
235
|
+
],
|
|
236
|
+
'challengeNewDevices' => true, // New devices are suspicious in e-commerce
|
|
237
|
+
// This would be a callable in PHP, but for now, we represent its intent.
|
|
238
|
+
'isApiRequest' => 'req.path.startsWith("/api/cart") || req.path.startsWith("/api/stock") || req.path.startsWith("/api/checkout")',
|
|
239
|
+
'wasm' => true,
|
|
240
|
+
],
|
|
241
|
+
];
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Crée une configuration de sécurité basée sur un profil nommé, avec des surcharges optionnelles.
|
|
245
|
+
*
|
|
246
|
+
* @param string $profileName Le nom du profil à utiliser ('balanced', 'strict', 'api', etc.).
|
|
247
|
+
* @param array<string, mixed> $overrides Un tableau pour fusionner profondément avec le profil, permettant la personnalisation.
|
|
248
|
+
* @return array<string, mixed> L'objet de configuration de sécurité final.
|
|
249
|
+
*/
|
|
250
|
+
public static function createSecurityProfile(string $profileName = 'balanced', array $overrides = []): array
|
|
251
|
+
{
|
|
252
|
+
$baseProfile = self::PROFILES[$profileName] ?? self::PROFILES['balanced'];
|
|
253
|
+
return self::deepMerge($baseProfile, $overrides);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Fusionne profondément deux tableaux. Les propriétés du tableau `$source` écrasent celles du tableau `$target`.
|
|
258
|
+
*
|
|
259
|
+
* @param array<string, mixed> $target Le tableau cible.
|
|
260
|
+
* @param array<string, mixed> $source Le tableau source.
|
|
261
|
+
* @return array<string, mixed> Le tableau fusionné.
|
|
262
|
+
*/
|
|
263
|
+
public static function deepMerge(array $target, array $source): array
|
|
264
|
+
{
|
|
265
|
+
$output = $target;
|
|
266
|
+
|
|
267
|
+
foreach ($source as $key => $value) {
|
|
268
|
+
if (is_array($value) && isset($output[$key]) && is_array($output[$key])) {
|
|
269
|
+
$output[$key] = self::deepMerge($output[$key], $value);
|
|
270
|
+
} else {
|
|
271
|
+
$output[$key] = $value;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return $output;
|
|
276
|
+
}
|
|
272
277
|
}
|