Skip to main content

Security Best Practices

API Key Management

Critical: Never expose your API key in client-side code. Always call the Doshi API from your backend.

Environment Variables

Store your API key securely:

Always Use HTTPS

Implement Proper Origin Checks

Never Use Wildcards in Production

Validate All Data

Performance Best Practices

Minimize API Calls

Cache the custom token temporarily if you need to render multiple iframes for the same user session

Optimize Message Size

Implement Proper Cleanup

Lazy Load the Iframe

Preconnect to Doshi Domain

Mobile App Integration

When embedding Doshi Frontend in a mobile app (iOS/Android WebView), there are special considerations:

Disable Zoom

Zooming should be disabled on mobile to prevent layout issues and ensure consistent user experience.
For Web (HTML Meta Tag):
For React:
For iOS (Swift/UIWebView):
For Android (WebView):

Handle Keyboard in Mobile Apps

When the keyboard opens in mobile apps, it can squeeze the iframe height and make content not visible. Handle this in your app environment.
The Doshi Frontend is designed to work within mobile WebViews, but your app needs to handle keyboard behavior correctly. iOS (Swift) - Adjust WebView when Keyboard Opens:
Android (Kotlin) - Adjust WebView when Keyboard Opens:
React Native (if applicable):
In Manifest (Android):

Best Practices for Mobile

Always disable zoom for consistent experience
Handle keyboard visibility in your app wrapper
Use adjustResize on Android to resize layout when keyboard appears
Use constraint-based layout on iOS to adjust for keyboard
Test on various screen sizes and keyboard types
Ensure input fields remain visible when keyboard is open
Doshi Frontend cannot handle external link clicks that open in new windows/popups due to security restrictions.

Why Popups Are Blocked

For security reasons, Doshi Frontend does not support opening links in popups or new windows from within the iframe. This prevents:
  • Phishing attacks
  • Unauthorized redirects
  • Cross-site scripting vulnerabilities
When users click on external links within Doshi Frontend, the iframe will send a postMessage to your parent application. You must handle these messages and open links in your environment. Listen for Link Click Messages:
iOS (Swift) - Handle Link Callbacks:
Android (Kotlin) - Handle Link Callbacks:
React - Handle Link Callbacks:

Message Format

When a user clicks an external link, Doshi Frontend sends:

Security Considerations

Always verify event.origin before processing messages
Validate URLs before opening (check for malicious protocols)
Use noopener,noreferrer when opening links in new tabs
Consider showing user confirmation for external links
Log external link clicks for security auditing

URL Validation Example

Error Handling Best Practices

Comprehensive Error Handling

User Feedback

Timeout Handling

Method Selection Guide

When to Use postMessage

Handling sensitive authentication data
Need for real-time, bidirectional communication
Production environments
Multiple authentication steps
Maximum security requirements
Complex 2FA flows

When to Use Query Parameters

Simple, one-time authentication
Rapid prototyping and development
Need for easier debugging
Simpler implementation requirements
Quick demos or proof of concepts

Code Organization

Separation of Concerns

Configuration Management

Styling Best Practices

Responsive Container

Loading States

Full-Screen Support

Testing Best Practices

Environment-Specific Testing

Mock API Responses

Integration Testing

Monitoring and Logging

Track Key Events

Error Monitoring

Performance Monitoring

Production Checklist

API key stored securely in environment variables
API calls made from backend only
HTTPS used for all URLs
Origin verification enabled for postMessage
No ”*” wildcards in production
Comprehensive error handling implemented
User feedback for all states (loading, error, success)
Timeout handling for slow connections
Proper cleanup of event listeners
Error logging and monitoring configured
Performance tracking in place
Tested across multiple browsers
Tested on mobile devices
Responsive design implemented
Accessibility considerations addressed

Next Steps

Troubleshooting

Common issues and solutions

Security Guide

Review security considerations