← Back to Content

Cross-Domain localStorage: How Browser Fingerprinting Enables Seamless Data Sharing

Discover how browser fingerprinting can create a cross-domain localStorage alternative, enabling secure data sharing between different websites without cookies or CORS restrictions.

Ilkka
cross-domain localStoragebrowser fingerprintingdata sharingweb storagecross-originfingerprint storagethumbmarkjs
Cross-Domain localStorage: How Browser Fingerprinting Enables Seamless Data Sharing

The web's same-origin policy is a fundamental security feature that prevents websites from accessing each other's data. While this protection is essential, it also creates challenges for legitimate use cases where you need to share data across different domains. Traditional solutions like cookies have limitations, and CORS (Cross-Origin Resource Sharing) requires server-side coordination. But what if there was a way to create a cross-domain storage solution using browser fingerprinting?

The Cross-Domain Storage Problem

Traditional Limitations

When building web applications that span multiple domains, developers face several challenges:

Real-World Scenarios

These limitations affect common use cases:

The Browser Fingerprinting Solution

The Core Concept

Browser fingerprinting creates a unique identifier for each visitor based on their browser and device characteristics. Since this fingerprint is consistent across domains (for the same user), it can serve as a "key" for cross-domain data storage.

Here's how it works:

  1. Generate a fingerprint on Domain A

  2. Store data in a backend database using the fingerprint as the key

  3. Generate the same fingerprint on Domain B

  4. Retrieve the data using the matching fingerprint

Why This Works

// On domain-a.com
const fingerprint = await generateFingerprint(); // "abc123def456"
const userData = { theme: 'dark', language: 'en' };

// Store in backend
await storeData(fingerprint, userData);

// On domain-b.com (same user, same browser)
const fingerprint = await generateFingerprint(); // "abc123def456" (same!)
const userData = await retrieveData(fingerprint); // { theme: 'dark', language: 'en' }

Implementing Cross-Domain Fingerprint Storage

Backend Storage Service

Create a simple API that acts like a fingerprint-based localStorage:

// API endpoints
POST /api/fingerprint-storage
{
  "fingerprint": "abc123def456",
  "key": "user-preferences",
  "value": { "theme": "dark", "language": "en" }
}

GET /api/fingerprint-storage?fingerprint=abc123def456&key=user-preferences
// Returns: { "theme": "dark", "language": "en" }

Client-Side Implementation

Using ThumbmarkJS for consistent fingerprinting:

import { Thumbmark } from '@thumbmark/thumbmarkjs';

class CrossDomainStorage {
  constructor(apiEndpoint, apiKey) {
    this.thumbmark = new Thumbmark({ apiKey });
    this.apiEndpoint = apiEndpoint;
  }

  async setItem(key, value) {
    const fingerprint = await this.thumbmark.get();
    
    const response = await fetch(`${this.apiEndpoint}/api/fingerprint-storage`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        fingerprint: fingerprint.id,
        key,
        value
      })
    });
    
    return response.ok;
  }

  async getItem(key) {
    const fingerprint = await this.thumbmark.get();
    
    const response = await fetch(
      `${this.apiEndpoint}/api/fingerprint-storage?fingerprint=${fingerprint.id}&key=${key}`
    );
    
    if (response.ok) {
      return await response.json();
    }
    return null;
  }
}

// Usage
const crossDomainStorage = new CrossDomainStorage('https://api.example.com', 'your-api-key');

// Store data
await crossDomainStorage.setItem('user-preferences', { theme: 'dark' });

// Retrieve on another domain
const preferences = await crossDomainStorage.getItem('user-preferences');

Advantages of Fingerprint-Based Storage

1. No Domain Restrictions

Unlike localStorage, fingerprint storage works across any domains that implement the same system.

2. No CORS Headers Required

The backend API can serve any domain without complex CORS configuration.

3. Larger Storage Capacity

Unlike cookies, you're not limited to 4KB per domain.

4. Automatic Cleanup

Implement TTL (Time To Live) for automatic data expiration.

5. Privacy-Conscious

No tracking cookies or persistent identifiers required.

Security and Privacy Considerations

Fingerprint Collisions

While rare, fingerprint collisions can occur. Therefore, this approach shouldn't be used for critical data.

Real-World Use Cases

1. Multi-Domain E-commerce

// Store cart items across different store domains
await crossDomainStorage.setItem('cart', {
  items: [{ id: 'product-123', quantity: 2 }],
  total: 99.99
});

2. User Preferences

// Share theme, language, and settings across subdomains
await crossDomainStorage.setItem('preferences', {
  theme: 'dark',
  language: 'en',
  notifications: true
});

3. Acquisition

// Share login status across related services
await crossDomainStorage.setItem('attribution', {
  source: 'google',
  medium: 'organic'
});

Limitations and Considerations

1. Fingerprint Stability

Browser updates or configuration changes can alter fingerprints. Consider version-locking ThumbmarkJS.

2. Privacy Regulations

Ensure compliance with GDPR, CCPA, and other privacy laws:

Conclusion

Browser fingerprinting-based cross-domain storage offers a powerful alternative to traditional methods. While not perfect, it provides a practical solution for legitimate use cases where data sharing across domains is necessary.

Key benefits:

As browser fingerprinting technology continues to improve, this approach will become even more reliable and practical. Tools like ThumbmarkJS make it easy to implement consistent, accurate fingerprinting across different domains.

Get Started

Ready to implement cross-domain storage in your application? Get started with ThumbmarkJS and discover how easy it is to create seamless data sharing across domains.

For more information about browser fingerprinting and cross-domain solutions, visit our documentation or contact our team for personalized guidance.

Want to see this in ThumbmarkJS?

If this would be a useful feature for you, and you'd like to see it implemented in ThumbmarkJS, let us know on GitHub.


Note: This approach should be used responsibly and in compliance with applicable privacy laws and regulations. Always consider the privacy implications and provide appropriate user controls.