@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.
@@ -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
- 'thresholds' => ['low' => 20, 'medium' => 45, 'high' => 75, 'block' => 95],
44
- 'patterns' => [
45
- 'velocityThreshold' => 800,
46
- 'burstThreshold' => 1500,
47
- 'scrapeThreshold' => 1000,
48
- 'historySize' => 10,
49
- 'minSamples' => 5,
50
- 'regularityThreshold' => 50,
51
- 'benfordThreshold' => 0.15,
52
- 'patternWeight' => 80,
53
- 'decayFactor' => 0.9,
54
- 'inactivityReset' => 5000,
55
- ],
56
- 'wasm' => true,
57
- ],
58
-
59
- /**
60
- * Strict Profile
61
- * An aggressive configuration for sensitive applications (e.g., financial services, admin panels).
62
- * It uses lower suspicion thresholds and higher penalties for anomalies, prioritizing security over user convenience.
63
- * All new devices are challenged by default.
64
- */
65
- 'strict' => [
66
- 'summary' => 'Strict Profile',
67
- '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.',
68
- 'weights' => [
69
- 'historyScore' => 0.4,
70
- 'rotationScore' => 0.6,
71
- 'headerAnomalyScore' => 0.2,
72
- 'requestPatternScore' => 0.8,
73
- 'inconsistencyScore' => 1.0,
74
- 'behaviorScore' => 0.8,
75
- 'honeypotScore' => 1.0,
76
- 'crossLayerInconsistencyScore' => 0.6,
77
- 'timeInconsistencyScore' => 1.0,
78
- 'tlsSpoofingScore' => 1.0,
79
- 'botScore' => 1.0,
80
- 'cookieDroppingScore' => 1.0, // Pénalité maximale
81
- 'threatIntelScore' => 0.7, // Poids élevé pour les menaces connues (Tor, etc.)
82
- 'clientHintsInconsistencyScore' => 0.9, // Very high penalty in strict mode
83
- 'clickVarianceScore' => 0.7, // High weight for click variance
84
- 'subnetScore' => 0.7, // Poids plus élevé en mode strict
85
- ],
86
- 'thresholds' => ['low' => 10, 'medium' => 35, 'high' => 65, 'block' => 90],
87
- 'patterns' => [
88
- 'velocityThreshold' => 1000,
89
- 'burstThreshold' => 1800,
90
- 'scrapeThreshold' => 1200,
91
- 'historySize' => 15,
92
- 'minSamples' => 4,
93
- 'regularityThreshold' => 40,
94
- 'benfordThreshold' => 0.12,
95
- 'patternWeight' => 90,
96
- 'decayFactor' => 0.85,
97
- 'inactivityReset' => 4000,
98
- ],
99
- 'challengeNewDevices' => true, // Challenge all new devices
100
- 'wasm' => true,
101
- ],
102
-
103
- /**
104
- * API Profile
105
- * Optimized for protecting API endpoints. This profile is highly sensitive to request patterns (velocity, bursts)
106
- * and less reliant on browser-specific behavioral metrics. It's designed to quickly identify and throttle scrapers and automated clients.
107
- */
108
- 'api' => [
109
- 'summary' => 'API Profile',
110
- '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.',
111
- 'weights' => [
112
- 'historyScore' => 0.5,
113
- 'rotationScore' => 0.5,
114
- 'headerAnomalyScore' => 0.3,
115
- 'requestPatternScore' => 1.0, // Very high weight for API patterns
116
- 'inconsistencyScore' => 0.7,
117
- 'behaviorScore' => 0.2, // Lower weight, as browser behavior is not applicable
118
- 'honeypotScore' => 1.0,
119
- 'crossLayerInconsistencyScore' => 0.5,
120
- 'timeInconsistencyScore' => 0.8,
121
- 'tlsSpoofingScore' => 0.7,
122
- 'botScore' => 0.5,
123
- 'cookieDroppingScore' => 0.8, // Important pour les clients API qui doivent maintenir un état
124
- 'threatIntelScore' => 0.5, // APIs are often targeted by malicious IPs
125
- 'clientHintsInconsistencyScore' => 0.6, // Relevant signal for APIs
126
- 'clickVarianceScore' => 0.3, // Low weight as not applicable to APIs
127
- 'subnetScore' => 0.8, // Très important pour les API pour détecter les botnets
128
- ],
129
- 'thresholds' => ['low' => 25, 'medium' => 50, 'high' => 80, 'block' => 95],
130
- 'patterns' => [
131
- 'velocityThreshold' => 200, // APIs are expected to be fast
132
- 'burstThreshold' => 500,
133
- 'scrapeThreshold' => 400,
134
- 'historySize' => 20,
135
- 'minSamples' => 8,
136
- 'regularityThreshold' => 20,
137
- 'benfordThreshold' => 0.18,
138
- 'patternWeight' => 85,
139
- 'decayFactor' => 0.9,
140
- 'inactivityReset' => 10000,
141
- ],
142
- // This would be a callable in PHP, but for now, we represent its intent.
143
- 'isApiRequest' => 'req.path.startsWith("/api/") || req.headers.accept?.includes("application/json")',
144
- 'wasm' => true,
145
- ],
146
-
147
- /**
148
- * Blog Profile
149
- * Tuned for blogs and content-heavy websites. This profile focuses on detecting content scraping and comment spam
150
- * by placing a high weight on request patterns and honeypot traps, while being more lenient on behavioral metrics
151
- * typical of readers.
152
- */
153
- 'blog' => [
154
- 'summary' => 'Blog Profile',
155
- '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.',
156
- 'weights' => [
157
- 'historyScore' => 0.2,
158
- 'rotationScore' => 0.3,
159
- 'headerAnomalyScore' => 0.1,
160
- 'requestPatternScore' => 0.8, // High weight to detect content scraping
161
- 'inconsistencyScore' => 0.7,
162
- 'behaviorScore' => 0.5, // Less emphasis on complex interactions
163
- 'honeypotScore' => 1.0, // Crucial for comment spam
164
- 'crossLayerInconsistencyScore' => 0.4,
165
- 'timeInconsistencyScore' => 0.8,
166
- 'tlsSpoofingScore' => 0.6,
167
- 'botScore' => 0.8,
168
- 'cookieDroppingScore' => 0.7, // Moins critique, mais toujours un signal
169
- 'threatIntelScore' => 0.3, // Lower priority for a blog
170
- 'clientHintsInconsistencyScore' => 0.5,
171
- 'clickVarianceScore' => 0.5, // Moderate weight for click variance
172
- 'subnetScore' => 0.4, // Utile contre le spam de commentaires coordonné
173
- ],
174
- 'thresholds' => ['low' => 25, 'medium' => 55, 'high' => 80, 'block' => 95],
175
- 'patterns' => [
176
- 'velocityThreshold' => 1000, // Readers can be fast
177
- 'burstThreshold' => 2000,
178
- 'scrapeThreshold' => 800, // Very sensitive to scraping patterns
179
- 'historySize' => 12,
180
- 'minSamples' => 5,
181
- 'regularityThreshold' => 60,
182
- 'benfordThreshold' => 0.16,
183
- 'patternWeight' => 85,
184
- 'decayFactor' => 0.92,
185
- 'inactivityReset' => 10000,
186
- ],
187
- 'wasm' => true,
188
- ],
189
-
190
- /**
191
- * E-commerce Profile
192
- * A strict profile tailored for e-commerce sites. It's designed to combat inventory scalping,
193
- * price scraping, and account takeover attempts by using high weights for request patterns and fingerprint inconsistency.
194
- * It also challenges all new devices to increase the cost for bots.
195
- */
196
- 'ecommerce' => [
197
- 'summary' => 'E-commerce Profile',
198
- '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.',
199
- 'weights' => [
200
- 'historyScore' => 0.4,
201
- 'rotationScore' => 0.6,
202
- 'headerAnomalyScore' => 0.2,
203
- 'inconsistencyScore' => 1.0, // Crucial for preventing account takeover
204
- 'behaviorScore' => 0.8, // Important for checkout/login forms
205
- 'honeypotScore' => 1.0,
206
- 'crossLayerInconsistencyScore' => 0.7,
207
- // NOUVEAU: Ajout des scores manquants pour une configuration complète
208
- 'requestPatternScore' => 0.9, // Poids unifié pour les patterns, remplace les scores scindés
209
- 'timeInconsistencyScore' => 0.9,
210
- 'tlsSpoofingScore' => 0.9,
211
- 'botScore' => 1.0,
212
- 'cookieDroppingScore' => 1.0, // Crucial pour la détection de bots e-commerce
213
- 'threatIntelScore' => 0.8, // Very important for e-commerce (scalping proxies)
214
- 'clientHintsInconsistencyScore' => 0.9, // Very important for e-commerce
215
- 'clickVarianceScore' => 0.8, // Very high weight for click variance
216
- 'subnetScore' => 0.9, // Crucial contre les attaques de scalping distribuées
217
- ],
218
- 'thresholds' => ['low' => 15, 'medium' => 40, 'high' => 70, 'block' => 90],
219
- 'patterns' => [
220
- 'velocityThreshold' => 500, // Bots are very fast
221
- 'burstThreshold' => 1000, // Detects rapid retries on the same product/action
222
- 'scrapeThreshold' => 600,
223
- 'historySize' => 15,
224
- 'minSamples' => 6,
225
- 'regularityThreshold' => 30,
226
- 'benfordThreshold' => 0.14,
227
- 'patternWeight' => 95,
228
- 'decayFactor' => 0.88,
229
- 'inactivityReset' => 3000,
230
- ],
231
- 'challengeNewDevices' => true, // New devices are suspicious in e-commerce
232
- // This would be a callable in PHP, but for now, we represent its intent.
233
- 'isApiRequest' => 'req.path.startsWith("/api/cart") || req.path.startsWith("/api/stock") || req.path.startsWith("/api/checkout")',
234
- 'wasm' => true,
235
- ],
236
- ];
237
-
238
- /**
239
- * Crée une configuration de sécurité basée sur un profil nommé, avec des surcharges optionnelles.
240
- *
241
- * @param string $profileName Le nom du profil à utiliser ('balanced', 'strict', 'api', etc.).
242
- * @param array<string, mixed> $overrides Un tableau pour fusionner profondément avec le profil, permettant la personnalisation.
243
- * @return array<string, mixed> L'objet de configuration de sécurité final.
244
- */
245
- public static function createSecurityProfile(string $profileName = 'balanced', array $overrides = []): array
246
- {
247
- $baseProfile = self::PROFILES[$profileName] ?? self::PROFILES['balanced'];
248
- return self::deepMerge($baseProfile, $overrides);
249
- }
250
-
251
- /**
252
- * Fusionne profondément deux tableaux. Les propriétés du tableau `$source` écrasent celles du tableau `$target`.
253
- *
254
- * @param array<string, mixed> $target Le tableau cible.
255
- * @param array<string, mixed> $source Le tableau source.
256
- * @return array<string, mixed> Le tableau fusionné.
257
- */
258
- public static function deepMerge(array $target, array $source): array
259
- {
260
- $output = $target;
261
-
262
- foreach ($source as $key => $value) {
263
- if (is_array($value) && isset($output[$key]) && is_array($output[$key])) {
264
- $output[$key] = self::deepMerge($output[$key], $value);
265
- } else {
266
- $output[$key] = $value;
267
- }
268
- }
269
-
270
- return $output;
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
  }