@anonympins/fingerprint 0.1.2 → 0.1.3

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 CHANGED
@@ -97,6 +97,7 @@ const securityConfig = {
97
97
  ticketMaxAge: 3600000, // 1 hour. Duration for which a solved challenge ticket is valid.
98
98
  challengeTtl: 300000, // 5 minutes. Time during which a challenge nonce is valid.
99
99
  deviceIdCookieMaxAge: undefined, // By default, it's a session cookie. Set a value in ms for a persistent cookie.
100
+ challengePagePath: './path/to/your/custom-challenge-page.html', // (Optional) Path to a custom HTML template for the challenge page.
100
101
  verbose: true, // set to true to log for fingerprint detection output
101
102
  patterns: { // (Optional) Initial values for request pattern detection, optimized by auto-tuner if enabled.
102
103
  velocityThreshold: 800, // ms between requests to be considered "fast"
@@ -199,7 +200,50 @@ app.use((req, res, next) => {
199
200
 
200
201
  app.listen(3000, () => console.log('Server started on port 3000'));
201
202
  ```
203
+ ### Customizing the Challenge Page
202
204
 
205
+ You can provide your own HTML template for the Proof-of-Work challenge page to maintain a consistent user experience with your brand.
206
+
207
+ 1. **Configuration**: In your `securityConfig`, specify the path to your template file using the `challengePagePath` option.
208
+
209
+ ```javascript
210
+ const securityConfig = {
211
+ // ... other options
212
+ challengePagePath: './path/to/your/custom-challenge-page.html',
213
+ };
214
+ ```
215
+
216
+ 2. **Template Placeholders**: Your HTML file **must** contain the following placeholders. The system will replace them with the dynamic JavaScript code required to run the challenge.
217
+
218
+ * `<!-- FINGERPRINT_SOLVER_SCRIPT -->`: This will be replaced by the script that contains the logic for solving the CPU and memory challenges.
219
+ * `<!-- FINGERPRINT_CHALLENGE_SCRIPT -->`: This will be replaced by the script that initiates the challenge with the specific parameters for the current request (nonce, difficulty, etc.).
220
+ * `<!-- FINGERPRINT_TRAPS -->`: This will be replaced by hidden "honeypot" links designed to trap simple bots. This placeholder is crucial for an effective defense.
221
+
222
+ #### Example Custom HTML Template
223
+
224
+ Here is a basic example of what your `custom-challenge-page.html` could look like:
225
+
226
+ ```html
227
+ <!DOCTYPE html>
228
+ <html lang="en">
229
+ <head>
230
+ <meta charset="UTF-8">
231
+ <title>Security Verification</title>
232
+ <style>
233
+ body { font-family: sans-serif; text-align: center; padding-top: 50px; }
234
+ h1 { color: #333; }
235
+ </style>
236
+ </head>
237
+ <body>
238
+ <h1>Please wait while we verify your connection...</h1>
239
+ <div id="loader" style="margin:20px;">⚙️ Initializing verification...</div>
240
+
241
+ <script><!-- FINGERPRINT_SOLVER_SCRIPT --></script>
242
+ <script><!-- FINGERPRINT_CHALLENGE_SCRIPT --></script>
243
+ <!-- FINGERPRINT_TRAPS -->
244
+ </body>
245
+ </html>
246
+ ```
203
247
  ## Public API
204
248
 
205
249
  In addition to the main middleware, several functions are exported to allow for more advanced integrations.
@@ -238,9 +238,9 @@ const ClientLibrary = {
238
238
 
239
239
  _isFetchPatched: false,
240
240
  _interceptorChain: [],
241
- // On "lie" (bind) la fonction fetch à son contexte d'origine (window) pour éviter les erreurs "Illegal invocation".
242
- // C'est la correction clé pour le problème que vous rencontrez.
243
- _originalFetch: (typeof window !== 'undefined') ? window.fetch.bind(window) : () => Promise.reject(new Error('fetch is not available')),
241
+ // On stocke la fonction fetch originale et on la lie à son contexte (window)
242
+ // pour éviter les erreurs "Illegal invocation" si une autre lib la modifie.
243
+ _originalFetch: (typeof window !== 'undefined') ? window.fetch.bind(window) : null,
244
244
 
245
245
  /**
246
246
  * Adds an interceptor function to the `fetch` chain.
@@ -256,7 +256,7 @@ const ClientLibrary = {
256
256
  },
257
257
 
258
258
  patchGlobalFetch() {
259
- if (this._isFetchPatched || typeof window === 'undefined') return;
259
+ if (this._isFetchPatched || !this._originalFetch) return;
260
260
 
261
261
  this._isFetchPatched = true;
262
262
  window.fetch = (resource, options) => {