@anonympins/fingerprint 0.6.7 → 0.7.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.
Files changed (63) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +3 -7
  3. package/composer.json +8 -1
  4. package/package.json +1 -1
  5. package/public/fingerprint-wordpress.zip +0 -0
  6. package/public/fp.wasm +0 -0
  7. package/src/js/build-client.js +9 -11
  8. package/src/js/dynamic-wasm.js +7 -7
  9. package/src/js/fingerprint.builder.js +37 -38
  10. package/src/js/fingerprint.client.js +236 -152
  11. package/src/js/fingerprint.client.obfuscated.js +1 -1
  12. package/src/js/fingerprint.js +517 -101
  13. package/src/js/fingerprint.utils.js +213 -213
  14. package/src/js/library.js +355 -384
  15. package/src/js/mongodb-store.js +1 -1
  16. package/src/js/optimization.worker.js +27 -27
  17. package/src/js/pow.solver.inline.js +206 -62
  18. package/src/js/pow.solver.js +235 -101
  19. package/src/js/pow.worker.js +48 -26
  20. package/src/js/redis-store.js +1 -1
  21. package/src/js/tests/fingerprint.client.init.test.js +146 -143
  22. package/src/js/tests/fingerprint.test.js +101 -40
  23. package/src/js/tests/ip-reputation.test.js +1 -0
  24. package/src/js/upow-model-task.js +14 -15
  25. package/src/php/AutoTuner.php +34 -34
  26. package/src/php/Challenge/ChallengeUtils.php +204 -32
  27. package/src/php/Config/SecurityProfiles.php +21 -0
  28. package/src/php/DirectFingerprint.php +190 -145
  29. package/src/php/FingerprintBuilder.php +29 -30
  30. package/src/php/FingerprintClient.php +24 -25
  31. package/src/php/FingerprintEngine.php +1836 -1880
  32. package/src/php/Ja3AnomalyDetector.php +258 -227
  33. package/src/php/Optimization/FunctionRegistry.php +7 -7
  34. package/src/php/Optimization/Optimization.php +24 -24
  35. package/src/php/Optimization/OptimizationOperators.php +28 -27
  36. package/src/php/Optimization/ProblemInitializers.php +52 -52
  37. package/src/php/ProblemManager.php +31 -34
  38. package/src/php/RequestContext.php +8 -1
  39. package/src/php/Store/IStore.php +7 -8
  40. package/src/php/Store/InMemoryStore.php +66 -66
  41. package/src/php/Store/MongoDbStore.php +5 -5
  42. package/src/php/Store/RedisStore.php +5 -5
  43. package/src/php/Store/StoreManager.php +35 -35
  44. package/src/php/Tests/ChallengeUtilsTest.php +453 -453
  45. package/src/php/Tests/DnsCircuitBreakerTest.php +105 -105
  46. package/src/php/Tests/FingerprintEngineTest.php +662 -693
  47. package/src/php/Tests/IpReputationTest.php +10 -0
  48. package/src/php/Tests/MaliciousPatternsTest.php +103 -103
  49. package/src/php/Tests/MetricsTest.php +97 -97
  50. package/src/php/Tests/ProblemManagerTest.php +376 -376
  51. package/src/php/Tests/QuicFingerprintTest.php +53 -53
  52. package/src/php/Tests/RequestUtilsTest.php +471 -471
  53. package/src/php/Tests/TLSClientHelloParserTest.php +177 -177
  54. package/src/php/Tests/config/ed25519_key.json +3 -3
  55. package/src/php/Utils/Env.php +49 -49
  56. package/src/php/Utils/MaliciousPatterns.php +74 -74
  57. package/src/php/Utils/MetricsManager.php +209 -209
  58. package/src/php/Utils/RequestUtils.php +236 -19
  59. package/src/php/Utils/TLSClientHelloParser.php +369 -212
  60. package/src/php/WordPress/WpDbStore.php +155 -0
  61. package/src/php/WordPress/fingerprint-wordpress.php +217 -0
  62. package/src/php/WordPress/package.php +123 -0
  63. package/src/php/bin/auto-tune.php +118 -118
@@ -6,34 +6,33 @@ namespace Anonympins\Fingerprint;
6
6
  use Anonympins\Fingerprint\Config\SecurityProfiles;
7
7
 
8
8
  /**
9
- * FingerprintClient - Wrapper PHP pour la bibliothèque de fingerprinting côté client.
9
+ * FingerprintClient - PHP wrapper for the client-side fingerprinting library.
10
10
  *
11
- * Cette classe facilite l'intégration de la bibliothèque JavaScript `fingerprint.client.js`
12
- * dans une application PHP. Elle gère l'injection sécurisée du script et la création
13
- * de "honeypots" (pièges à bots) dans les formulaires.
11
+ * Handles script injection and generation of polymorphic honeypot fields
12
+ * inside HTML forms.
14
13
  */
15
14
  class FingerprintClient
16
15
  {
17
16
  /**
18
- * @var string Le chemin vers le fichier de la bibliothèque client JavaScript.
17
+ * @var string Path to client script asset.
19
18
  */
20
19
  private string $clientScriptPath;
21
20
 
22
21
  /**
23
- * @var array La configuration à passer à la fonction `initializeClient` de la bibliothèque JS.
22
+ * @var array Configuration payload passed to `initializeClient`.
24
23
  */
25
24
  private array $clientConfig;
26
25
 
27
26
  /**
28
- * @var string|null Un nonce cryptographique pour la Content Security Policy (CSP).
27
+ * @var string|null Cryptographic nonce for Content Security Policy (CSP).
29
28
  */
30
29
  private ?string $nonce;
31
30
 
32
31
  /**
33
- * Constructeur de la classe.
32
+ * Constructor.
34
33
  *
35
- * @param string $clientScriptPath Le chemin d'accès web au fichier `fingerprint.client.js`.
36
- * @param array $clientConfig La configuration pour la bibliothèque client (souris, frappes, honeypots, etc.).
34
+ * @param string $clientScriptPath Web-accessible path to `fingerprint.client.js`.
35
+ * @param array $clientConfig Client initialization options.
37
36
  */
38
37
  public function __construct(string $clientScriptPath, array $clientConfig = [])
39
38
  {
@@ -48,15 +47,15 @@ class FingerprintClient
48
47
  'handleChallenges' => true,
49
48
  'probationaryTtl' => 30000, // 30 seconds
50
49
  ],
51
- 'wasm' => true, // Activer la tentative de chargement du module WASM
52
- 'wasmPath' => '/fp.js' // Chemin vers le script de chargement WASM
50
+ 'wasm' => true, // Attempt to load WASM module
51
+ 'wasmPath' => '/fp.js' // Path to WASM loader script
53
52
  ];
54
53
 
55
- // Utiliser une fusion profonde pour permettre de surcharger des sous-clés
54
+ // Deep merge configuration overrides
56
55
  $this->clientConfig = SecurityProfiles::deepMerge($defaultConfig, $clientConfig);
57
56
 
58
57
  try {
59
- // Génère un nonce pour CSP si possible, pour une sécurité renforcée.
58
+ // Generate CSP nonce when possible
60
59
  $this->nonce = bin2hex(random_bytes(16));
61
60
  } catch (\Exception $e) {
62
61
  $this->nonce = null;
@@ -64,20 +63,20 @@ class FingerprintClient
64
63
  }
65
64
 
66
65
  /**
67
- * Génère un champ de formulaire "honeypot" caché.
68
- * Les bots le rempliront, mais il sera invisible pour les humains.
66
+ * Generates a hidden honeypot form field.
67
+ * Traps automated bots while remaining invisible to human users.
69
68
  *
70
- * @param string $fieldName Le nom du champ (doit correspondre à la configuration client).
71
- * @return string Le code HTML du champ honeypot.
69
+ * @param string $fieldName Field name (must match client honeypot registration).
70
+ * @return string Generated HTML markup.
72
71
  */
73
72
  public function generateHoneypotField(string $fieldName): string
74
73
  {
75
- // Ajoute le champ à la configuration pour que le script client le surveille.
74
+ // Register field in client configuration for monitoring
76
75
  if (!in_array($fieldName, $this->clientConfig['honeypots'])) {
77
76
  $this->clientConfig['honeypots'][] = $fieldName;
78
77
  }
79
78
 
80
- // Styles CSS polymorphiques pour cacher le champ de manière robuste.
79
+ // Polymorphic CSS styling to robustly obscure honeypots
81
80
  $styleOptions = [
82
81
  'position:absolute; left:-9999px; top:-9999px; transform:scale(0); opacity:0; pointer-events:none;',
83
82
  'position:fixed; left:-8888px; top:-8888px; width:0; height:0; overflow:hidden; opacity:0; pointer-events:none;',
@@ -104,16 +103,16 @@ class FingerprintClient
104
103
  }
105
104
 
106
105
  /**
107
- * Génère le bloc de script complet à inclure dans une page HTML.
106
+ * Generates HTML script tags to embed the client library on a page.
108
107
  *
109
- * @return string Le code HTML des balises <script>.
108
+ * @return string HTML <script> markup.
110
109
  */
111
110
  public function getScriptTag(): string
112
111
  {
113
112
  $configJson = json_encode($this->clientConfig);
114
113
  $nonceAttr = $this->nonce ? ' nonce="' . $this->nonce . '"' : '';
115
114
 
116
- // Le script d'initialisation qui sera inclus dans la page.
115
+ // Inline initialization script embedded in HTML
117
116
  $initScript = <<<JS
118
117
  document.addEventListener('DOMContentLoaded', function() {
119
118
  const config = {$configJson};
@@ -133,13 +132,13 @@ document.addEventListener('DOMContentLoaded', function() {
133
132
  });
134
133
  JS;
135
134
 
136
- // On combine le chargement de la bibliothèque et le script d'initialisation.
135
+ // Combine library loader script and inline initialization
137
136
  return '<script src="' . htmlspecialchars($this->clientScriptPath) . '"' . $nonceAttr . '></script>'
138
137
  . '<script' . $nonceAttr . '>' . $initScript . '</script>';
139
138
  }
140
139
 
141
140
  /**
142
- * Retourne le nonce généré pour pouvoir l'utiliser dans les en-têtes CSP.
141
+ * Returns the generated CSP nonce.
143
142
  * @return string|null
144
143
  */
145
144
  public function getNonce(): ?string