Security Considerations

This page outlines important security considerations for integrating the TwoCoin widget into your website. Implementing proper security measures is essential to protect your users and your business when dealing with cryptocurrency transactions.

Security Warning

Cryptocurrency transactions are irreversible. Implementing proper security measures is critical to prevent fraud, protect sensitive data, and ensure a secure user experience.

HTTPS Requirement

The TwoCoin widget must always be loaded over HTTPS to ensure secure communication:

✓ Correct Implementation

<iframe src="https://your-widget-domain.com/widget" width="100%" height="800px"></iframe>

✗ Incorrect Implementation

<iframe src="http://your-widget-domain.com/widget" width="100%" height="800px"></iframe>

Your entire website should be served over HTTPS to maintain end-to-end security. Modern browsers will block mixed content, which can cause issues with the iframe widget if your site uses HTTP.

Data Security

The iframe-based widget provides excellent security isolation. No API credentials are exposed in your client-side code since all communication happens within the secure iframe environment:

Security Benefits of Iframe Integration

  • No API credentials exposed in your website's code
  • Widget operates in an isolated security context
  • User data is processed securely within the widget's domain
  • Reduced attack surface compared to JavaScript integration

Webhook Security

Webhooks are used to notify your server about order status changes. To ensure these notifications are authentic:

// Node.js example for verifying webhook signatures
const crypto = require('crypto');

function verifyWebhookSignature(payload, signature, secret) {
  // Get the signature provided in the X-Signature header
  const providedSignature = signature;

  // Compute the HMAC signature of the payload using your webhook secret
  const computedSignature = crypto
    .createHmac('sha256', secret)
    .update(payload)
    .digest('hex');

  // Use timing-safe comparison to prevent timing attacks
  return crypto.timingSafeEqual(
    Buffer.from(providedSignature, 'hex'),
    Buffer.from(computedSignature, 'hex')
  );
}

// Express.js route example
app.post('/webhooks/twocoin', express.raw({type: 'application/json'}), (req, res) => {
  const signature = req.headers['x-signature'];
  const payload = req.body;

  // Verify the signature
  if (!verifyWebhookSignature(payload, signature, process.env.WEBHOOK_SECRET)) {
    return res.status(401).send('Invalid signature');
  }

  // Process the webhook payload
  const event = JSON.parse(payload);

  // Handle different event types
  switch(event.type) {
    case 'order.completed':
      // Process completed order
      break;
    case 'order.failed':
      // Handle failed order
      break;
    default:
      // Handle other event types
  }

  // Always respond with 200 OK to acknowledge receipt
  res.status(200).send('Webhook received');
});

Cross-Site Scripting (XSS) Protection

Protect your integration from cross-site scripting attacks:

  • Implement Content Security Policy (CSP) headers to restrict where scripts can be loaded from
  • Add the TwoCoin widget domain to your CSP script-src directive
  • Sanitize any user input before passing it to the widget configuration
// Example CSP header that allows TwoCoin widget iframe
Content-Security-Policy: default-src 'self'; frame-src 'self' https://your-widget-domain.com;

User Data Protection

Handle user data securely to comply with privacy regulations:

Data Collection

Only collect the minimum amount of user data necessary for the transaction. Be transparent about what data is collected and how it's used.

Data Storage

Store sensitive user data securely and in compliance with regulations like GDPR. Implement proper encryption for stored data.

Data Transmission

Always transmit user data over encrypted connections (HTTPS). Never pass sensitive data via URL parameters.

Privacy Policy

Update your privacy policy to include information about the TwoCoin widget and how user data is handled during transactions.

Wallet Address Validation

Implement client-side validation for cryptocurrency wallet addresses:

// Example: Client-side validation before submitting the wallet address
function validateWalletAddress(address, currency) {
  // Basic validation patterns
  const patterns = {
    'BTC': /^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,62}$/,
    'ETH': /^0x[a-fA-F0-9]{40}$/,
    'XRP': /^r[0-9a-zA-Z]{24,34}$/
  };

  // Check if we have a pattern for this currency
  if (!patterns[currency]) {
    return true; // Skip validation for unsupported currencies
  }

  // Test the address against the pattern
  return patterns[currency].test(address);
}

// Use during form submission
document.getElementById('exchange-form').addEventListener('submit', function(event) {
  const address = document.getElementById('wallet-address').value;
  const currency = document.getElementById('target-currency').value;

  if (!validateWalletAddress(address, currency)) {
    event.preventDefault();
    alert('Please enter a valid ' + currency + ' wallet address.');
  }
});

Note that the widget has built-in validation for most cryptocurrency addresses, but adding an extra layer of validation on your side can improve user experience by catching errors early.

Order Verification

Always verify order details on your server before processing:

  1. 1. Verify order details received from webhooks by making a separate API call to fetch the order
  2. 2. Implement idempotency in your webhook handling to prevent double-processing
  3. 3. Check that order parameters (amounts, currencies) match your expected values
  4. 4. Store order IDs you've already processed to prevent replay attacks

Security Headers

Implement these security headers on your website to enhance protection:

HeaderExample ValuePurpose
Strict-Transport-Securitymax-age=31536000; includeSubDomainsEnforces HTTPS connections
X-Frame-OptionsDENYPrevents clickjacking attacks
X-Content-Type-OptionsnosniffPrevents MIME type sniffing
Referrer-Policystrict-origin-when-cross-originControls referrer information
Permissions-Policycamera=(), microphone=(), geolocation=()Restricts browser features

Security Monitoring

Set up monitoring to detect and respond to security issues:

  • Monitor for unusual transaction patterns or high failure rates
  • Set up alerts for unauthorized API access attempts
  • Log and review webhook signature verification failures
  • Implement rate limiting on your server endpoints

Next Steps

Support

If you encounter any issues or have questions not addressed in this documentation, please contact our support team on Telegram at https://t.me/cs_2coin (@cs_2coin).