Overview
Security is paramount when implementing webview authentication. This guide covers critical security considerations for both postMessage and query parameter methods.IP Whitelisting
To get your server’s IP address:API Key Security
Secure API Key Usage
Backend Implementation Example
Origin Verification
If you load the iframe from sandbox, the origin you verify here — and the
targetOrigin you pass to postMessage — must be
https://sandbox.embed.doshi.app. A check hardcoded to the production host
will silently reject sandbox messages. Allow both hosts to support either
environment. See Environments.For postMessage
Specify Target Origins
Token Security
Token Lifecycle
The custom token received from the API:- Is single-use for initial authentication
- Has a short expiration time
- Cannot be reused after the user session is established
Session Tokens
Once authenticated:- ID Token TTL: 1 hour
- Refresh Token TTL: 12 hours
- The iframe manages token refresh automatically
- Sessions are isolated per iframe instance
Cross-Origin Communication
postMessage API Security
Message Validation
Message Validation
Always validate the structure and content of messages:
Error Handling
Error Handling
Implement comprehensive error handling:
HTTPS Enforcement
HTTPS Enforcement
Always use HTTPS for secure communication:
Query Parameter Security
Best Practices
- Clear Parameters After Use
- Use Short-Lived Tokens
- Monitor Token Usage
- Respect URL Length Limits
URLs should generally stay under 2000 characters for maximum browser compatibility
2FA Security
When implementing 2FA:Don’t Send Unnecessary Data
Security Checklist
Store API key securely in backend environment variables
Never expose API key in client-side code
Call Doshi API only from your backend server
Use HTTPS for all communication
Verify message origins in production
Never use ”*” wildcard for target origins in production
Validate all incoming messages and parameters
Use short-lived tokens
Clear sensitive data from URLs after reading
Implement comprehensive error handling
Log security events for monitoring
Test across different browsers and environments
Common Security Pitfalls
Environment-Specific Configuration
Monitoring and Logging
Next Steps
postMessage Implementation
Implement secure real-time authentication
Query Parameters
Use URL-based authentication safely
